Skip to content

Detect public API changes #1

Detect public API changes

Detect public API changes #1

name: Verify public interface
on:
pull_request:
types: [opened, labeled, unlabeled, synchronize]
paths:
- '**/*.swift'
- '!StripeFinancialConnections/**'
- '!StripeIdentity/**'
- '!StripeConnections/**'
jobs:
public-api-check:
runs-on: macos-14
permissions:
pull-requests: write
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Detect API changes
id: api-differences
run: |
modules=("StripeUICore" "StripeCameraCore" "StripeApplePay" "StripePayments" "StripePaymentsUI" "StripePaymentSheet" "StripeCardScan")
# Set destination
destination="platform=iOS Simulator,name=iPhone 12 mini,OS=16.2"
for module in "${modules[@]}"
do
echo "Checking module: $module ..."
# Checkout old version, build and generate API JSON
echo "Building and generating old version..."
git checkout ${{ github.base_ref }}
xcodebuild clean build -scheme $module -destination "$destination" -sdk iphonesimulator
xcrun swift-api-digester -dump-sdk -module $module -o old-$module.json -sdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk -I .build/debug
# Checkout new version, build and generate API JSON
echo "Building and generating new version..."
git checkout ${{ github.head_ref }}
xcodebuild clean build -scheme $module -destination "$destination" -sdk iphonesimulator
xcrun swift-api-digester -dump-sdk -module $module -o new-$module.json -sdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk -I .build/debug
# Compare APIs
echo "Comparing APIs..."
xcrun swift-api-digester -diagnose-sdk --input-paths old-$module.json --input-paths new-$module.json > output-$module.txt
echo "Done with $module."
done
echo "API_DIFF=$(cat output-*.txt)" >> $GITHUB_ENV
- name: Check for new APIs
id: check-api
run: |
if [[ -n "${{ env.API_DIFF }}" ]]; then
echo "::set-output name=new_apis_detected::yes"
else
echo "::set-output name=new_apis_detected::"
fi
- uses: peter-evans/find-comment@v1
id: find_comment
with:
issue-number: ${{ github.event.pull_request.number }}
body-includes: New public APIs
- uses: peter-evans/create-or-update-comment@v1
id: create-update-comment
if: steps.check-api.outputs.new_apis_detected == 'yes'
with:
body: |
⚠️ New public APIs detected:
```
${{ env.API_DIFF }}
```
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_detected == 'yes' && !contains(github.event.pull_request.labels.*.name, 'adds public API')"
run: exit 1