Skip to content

Commit

Permalink
Merge branch 'master' into jlh/test-restore
Browse files Browse the repository at this point in the history
  • Loading branch information
jlh-stripe authored Sep 30, 2024
2 parents 6889704 + 33f4ae7 commit a2139cb
Show file tree
Hide file tree
Showing 57 changed files with 2,328 additions and 183 deletions.
110 changes: 110 additions & 0 deletions .github/workflows/find-dead-code.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
name: Dead code detection
on:
pull_request:
types: [opened, labeled, unlabeled, synchronize]
paths:
- '**/*.swift'

jobs:
dead-code-check:
runs-on: macos-13
permissions:
pull-requests: write

steps:
- name: Checkout code
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Install Periphery
run: brew install peripheryapp/periphery/periphery

- name: Build project and run Periphery scan
id: periphery-scan
run: |
periphery scan --config .periphery.yml --clean-build 2>&1 | sed -E 's#.*/##; s/:[0-9]+:[0-9]+:/: /' | grep 'is unused' > periphery_report_feature_formatted_sorted.txt
ruby ci_scripts/dead_code/process_periphery_output.rb periphery_report_feature_formatted_sorted.txt unused_code_feature.json
- name: Copy .periphery.yml to temporary location
run: |
# Copy necessary files to /tmp/ before checking out master
cp .periphery.yml /tmp/
cp ci_scripts/dead_code/process_periphery_output.rb /tmp/
- name: Compare Periphery output with master baseline
run: |
git fetch origin master:master
git checkout master
cp /tmp/.periphery.yml .periphery.yml
mkdir -p ci_scripts/dead_code/
cp /tmp/process_periphery_output.rb ci_scripts/dead_code/
periphery scan --config .periphery.yml --clean-build 2>&1 | sed -E 's#.*/##; s/:[0-9]+:[0-9]+:/: /' | grep 'is unused' > periphery_report_master_formatted_sorted.txt
ruby ci_scripts/dead_code/process_periphery_output.rb periphery_report_master_formatted_sorted.txt unused_code_master.json
- name: Compare Unused Code JSON Files
id: compare-dead-code
run: |
# Compare the keys in the JSON files to find new dead code
ruby -r json -e '
master_file = "unused_code_master.json"
feature_file = "unused_code_feature.json"
output_file = "new_dead_code.json"
master_unused_code = JSON.parse(File.read(master_file))
feature_unused_code = JSON.parse(File.read(feature_file))
new_dead_code = feature_unused_code.reject { |k, _| master_unused_code.key?(k) }
if new_dead_code.size > 200
puts "More than 200 keys present, skipping. This usually happens if a build fails"
elsif new_dead_code.empty?
puts "No new dead code detected."
else
File.write(output_file, JSON.pretty_generate(new_dead_code) + "\n")
end
'
# Check if new_dead_code.json exists and is not empty
if [ -s new_dead_code.json ]; then
echo "New dead code detected."
echo "diff<<EOF" >> $GITHUB_ENV
cat new_dead_code.json >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
else
echo "No new dead code detected."
fi
- uses: peter-evans/find-comment@v3
id: find_comment
with:
issue-number: ${{ github.event.pull_request.number }}
body-includes: '🚨 New dead code detected'

- uses: peter-evans/create-or-update-comment@v3
id: create_update_comment
if: env.diff != ''
with:
issue-number: ${{ github.event.pull_request.number }}
body: |
🚨 New dead code detected in this PR:
```diff
${{ env.diff }}
```
Please remove the dead code before merging.
If this is intentional, you can bypass this check by adding the label `skip dead code check` to this PR.
ℹ️ If this comment appears to be left in error, make sure your branch is up-to-date with `master`.
edit-mode: replace
comment-id: ${{ steps.find_comment.outputs.comment-id }}
token: ${{ secrets.GITHUB_TOKEN }}

- name: Fail if not acknowledged
if: env.diff != '' && !contains(github.event.pull_request.labels.*.name, 'skip dead code check')
run: exit 1
106 changes: 106 additions & 0 deletions .periphery.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# Detects dead code
# Usage periphery scan --config .periphery.yml 2>&1 | sed 's#.*/##' | grep 'is unused' | sort > periphery_report_feature_formatted_sorted.txt
# Install/info https://github.com/peripheryapp/periphery
# Why are so many targets/schemes commented out? This script takes a long time to run in CI, so we skip some schemes to speed it up. Note: AllStripeFrameworks covers a lot of the commented out schemes, e.g. AllStripeFrameworks contains StripeApplePay.

workspace: Stripe.xcworkspace

schemes:
- AllStripeFrameworks
# - IntegrationTester
# - Stripe3DS2
# - Stripe3DS2DemoUI
# - StripeApplePay
# - StripeCameraCore
# - StripeCardScan
- StripeConnect
# - StripeCore
# - StripeFinancialConnections
# - StripeIdentity
# - StripePaymentSheet
# - StripePayments
# - StripePaymentsUI
# - StripeUICore
# - StripeiOS
# - PaymentSheet Example
# - AppClipExample
# - CardImageVerification Example
# - FinancialConnections Example
# - IdentityVerification Example
# - StripeConnect Example
# - Non-Card Payment Examples
# - UI Examples

targets:
# - AppClipExample
# - AppClipExampleClip
# - AppClipExampleClipTests
# - AppClipExampleClipUITests
# - AppClipExampleTests iOS
# - CardImageVerification Example
# - CardImageVerification ExampleUITests
# - Common
# - FinancialConnections Example
# - FinancialConnectionsUITests
# - IdentityVerification Example
# - IntegrationTester
# - IntegrationTesterUITests
# - Non-Card Payment Examples
# - PaymentSheet Example
# - PaymentSheetLocalizationScreenshotGenerator
# - PaymentSheetUITest
- Stripe3DS2
- Stripe3DS2Tests
- StripeApplePay
- StripeApplePayTests
- StripeCameraCore
- StripeCameraCoreTestUtils
- StripeCameraCoreTests
- StripeCardScan
- StripeCardScanTests
- StripeConnect
# - StripeConnect Example
# - StripeConnect ExampleUITests
- StripeConnectTests
- StripeCore
- StripeCoreTestUtils
- StripeCoreTests
- StripeFinancialConnections
- StripeFinancialConnectionsTests
- StripeIdentity
- StripeIdentityTests
- StripePaymentSheet
- StripePaymentSheetTestHostApp
- StripePaymentSheetTests
- StripePayments
- StripePaymentsObjcTestUtils
- StripePaymentsTestHostApp
- StripePaymentsTestUtils
- StripePaymentsTests
- StripePaymentsUI
- StripePaymentsUITests
- StripeUICore
- StripeUICoreTests
- StripeiOS
- StripeiOSAppHostedTests
- StripeiOSTestHostApp
- StripeiOSTests
# - UI Examples

retain_public: true
retain_objc_accessible: true
retain_objc_annotated: true
retain_objc_protocols: true

retain_ibaction: true
retain_iboutlet: true
retain_ibinspectable: true

analyze_tests: true

verbose: true

build_arguments:
- -destination
- 'generic/platform=iOS Simulator'

Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
A262D76C3319002A2F6EE395 /* CustomerSheetTestPlaygroundSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C2A8BAE3842A0E892D06BB9 /* CustomerSheetTestPlaygroundSettings.swift */; };
AEC3BC636297A0D3E2DDF522 /* MockFiles in Resources */ = {isa = PBXBuildFile; fileRef = 9496755DA1916325D38ECB2F /* MockFiles */; };
B36A24145C97D73C981DDBAC /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F4B26C754925F8D2A5183B2E /* Main.storyboard */; };
B615E86F2CA4B267007D684C /* ExampleEmbeddedElementCheckoutViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B615E86E2CA4B266007D684C /* ExampleEmbeddedElementCheckoutViewController.swift */; };
B641A4192C2BA25D00AE654A /* PaymentSheetVerticalUITest.swift in Sources */ = {isa = PBXBuildFile; fileRef = B641A4182C2BA25D00AE654A /* PaymentSheetVerticalUITest.swift */; };
B6CA975C2C486DE700DAE441 /* PaymentSheetLPMUITest.swift in Sources */ = {isa = PBXBuildFile; fileRef = B6CA975B2C486DE700DAE441 /* PaymentSheetLPMUITest.swift */; };
B6D6AAA666859847BB59749C /* PaymentSheet+AddressTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A61C5739DBE6405A4D9FD5F2 /* PaymentSheet+AddressTests.swift */; };
Expand Down Expand Up @@ -244,6 +245,7 @@
ADBEC0CE822B92C078E5D758 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
B33D2066D7BA7984CABC23A5 /* zh-HK */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-HK"; path = "zh-HK.lproj/LaunchScreen.strings"; sourceTree = "<group>"; };
B54E58F2CA450CF49ECD5637 /* CustomerSheetTestPlaygroundController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomerSheetTestPlaygroundController.swift; sourceTree = "<group>"; };
B615E86E2CA4B266007D684C /* ExampleEmbeddedElementCheckoutViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ExampleEmbeddedElementCheckoutViewController.swift; sourceTree = "<group>"; };
B641A4182C2BA25D00AE654A /* PaymentSheetVerticalUITest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PaymentSheetVerticalUITest.swift; sourceTree = "<group>"; };
B69C155A2B9FDCBD009CE667 /* PaymentSheet Example.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; name = "PaymentSheet Example.entitlements"; path = "PaymentSheet Example/PaymentSheet Example.entitlements"; sourceTree = "<group>"; };
B6CA975B2C486DE700DAE441 /* PaymentSheetLPMUITest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PaymentSheetLPMUITest.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -448,6 +450,7 @@
B7AFD32B5EAD3BEEEC3D4260 /* ExampleSwiftUIPaymentSheet.swift */,
D20765908089ACB79B556592 /* ExampleSwiftUIViews.swift */,
61FB6BC62C88C8BF00F8E074 /* EmbeddedPlaygroundViewController.swift */,
B615E86E2CA4B266007D684C /* ExampleEmbeddedElementCheckoutViewController.swift */,
ADBEC0CE822B92C078E5D758 /* Info.plist */,
27BA81F620FAB6E5505E0B32 /* PaymentSheetTestPlayground.swift */,
1261A6BDCDB7E81D08F137F0 /* PaymentSheetTestPlaygroundSettings.swift */,
Expand Down Expand Up @@ -672,6 +675,7 @@
buildActionMask = 2147483647;
files = (
EB1DCD930408180734A8D7CA /* AppDelegate.swift in Sources */,
B615E86F2CA4B267007D684C /* ExampleEmbeddedElementCheckoutViewController.swift in Sources */,
4694B03B08B7DA9706A2ED9D /* AppearancePlaygroundView.swift in Sources */,
DDF30DE9D7AA4BCC47CC12FB /* CustomerSheetTestPlayground.swift in Sources */,
8D9AAFD1D1D49112A7777414 /* CustomerSheetTestPlaygroundController.swift in Sources */,
Expand Down
Loading

0 comments on commit a2139cb

Please sign in to comment.