Skip to content

Add GitHub workflow to detect new public APIs #39

Add GitHub workflow to detect new public APIs

Add GitHub workflow to detect new public APIs #39

name: Check for new public APIs
on:
pull_request:
types: [opened, labeled, unlabeled, synchronize]
paths:
- '**/*.swift'
- '!StripeFinancialConnections/**'
- '!StripeIdentity/**'
- '!StripeConnections/**'
jobs:
public-api-check:
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.0
- name: Check for new public APIs
id: check-api
run: |
# Run the Ruby script and make a list of new public APIs
echo "Checking for new Public APIs..."
OUTPUT=$(ruby ci_scripts/check_for_new_public_apis.rb ${{ github.workspace }})
echo "${OUTPUT}"
echo "API_CHECK_OUTPUT<<EOF" >> $GITHUB_ENV
echo "${OUTPUT}" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
# Pass whether new public APIs have been found to the next steps
if [[ -z "$OUTPUT" ]]; then
echo "::set-output name=new_apis::"
else
echo "::set-output name=new_apis:: yes"
fi
- uses: peter-evans/find-comment@v3.0.0
id: find_comment
with:
issue-number: ${{ github.event.pull_request.number }}
body-includes: New public APIs
- uses: peter-evans/create-or-update-comment@v4
id: create-update-comment
if: steps.check-api.outputs.new_apis
with:
body: |
⚠️ New public APIs detected:
```
${{ env.API_CHECK_OUTPUT }}
```
Consider the following:
- Do these APIs need to be `public` or can they be protected with `@_spi(STP)`?
- If these APIs need to be `public`, assess whether they require an API review.
If you confirm these APIs need to be public and have undergone necessary review, add the label `adds public API` to this PR to acknowledge and bypass this check.
edit-mode: replace
comment-id: ${{ steps.find_comment.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
token: ${{ secrets.GITHUB_TOKEN }}
- name: Fail if not acknowledged
if: "steps.check-api.outputs.new_apis && !contains(github.event.pull_request.labels.*.name, 'adds public API')"
run: exit 1