Skip to content

Detect public API changes #6

Detect public API changes

Detect public API changes #6

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: Build frameworks
id: build-frameworks
run: |
modules=("StripeUICore" "StripeCameraCore" "StripeApplePay" "StripePayments" "StripePaymentsUI" "StripePaymentSheet" "StripeCardScan")
mkdir -p ${{ github.workspace }}/build
echo "BUILD_DIR=${{ github.workspace }}/build" >> $GITHUB_ENV
# Checkout old version, build and generate API JSON
echo "Building and generating old version..."
git checkout ${{ github.base_ref }}
xcodebuild clean archive \
-quiet \
-workspace "Stripe.xcworkspace" \
-scheme "AllStripeFrameworks" \
-destination 'generic/platform=iOS Simulator' \
-configuration "Release" \
-archivePath "#{build_dir}/StripeFrameworks-sim-master.xcarchive" \
-sdk iphonesimulator \
SUPPORTS_MACCATALYST=NO \
BUILD_LIBRARIES_FOR_DISTRIBUTION=YES \
SWIFT_ACTIVE_COMPILATION_CONDITIONS=STRIPE_BUILD_PACKAGE \
SKIP_INSTALL=NO
xcrun swift-api-digester \
-dump-sdk \
-module StripePaymentSheet \
-o old-StripePaymentSheet.json \
-I "#{build_dir}/StripeFrameworks-sim-master.xcarchive/Products/Library/Frameworks"
# Checkout new version, build and generate API JSON
echo "Building and generating new version..."
git checkout ${{ github.head_ref }}
xcodebuild clean archive \
-quiet \
-workspace "Stripe.xcworkspace" \
-scheme "AllStripeFrameworks" \
-destination 'generic/platform=iOS Simulator' \
-configuration "Release" \
-archivePath "#{build_dir}/StripeFrameworks-sim-new.xcarchive" \
-sdk iphonesimulator \
SUPPORTS_MACCATALYST=NO \
BUILD_LIBRARIES_FOR_DISTRIBUTION=YES \
SWIFT_ACTIVE_COMPILATION_CONDITIONS=STRIPE_BUILD_PACKAGE \
SKIP_INSTALL=NO
xcrun swift-api-digester -dump-sdk -module StripePaymentSheet -o new-StripePaymentSheet.json -sdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk -I .build/debug
- 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