Skip to content

Commit

Permalink
ci: remove duplicate code for generating SDK size
Browse files Browse the repository at this point in the history
Part of: https://linear.app/customerio/issue/MBL-155/track-the-binary-size-of-our-ios-sdk-upon-every-release

Follow-up to previous commits in the stack. This commit performs these changes:
* remove copy/pasted code for generating SDK size reports by using a re-usable github action.

commit-id:ab126ca5
  • Loading branch information
levibostian committed Apr 12, 2024
1 parent bf56a21 commit f601bca
Showing 1 changed file with 19 additions and 103 deletions.
122 changes: 19 additions & 103 deletions .github/workflows/build-sample-apps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ jobs:
run: |
brew install sd # used in CI script as an easier to use sed CLI. Replaces text in files.
brew install xcbeautify # used by fastlane for output
brew install bloaty # used to generate SDK binary size reports
- name: Install tools from Gemfile (ruby language) used for building our apps with
uses: ruby/setup-ruby@v1
Expand Down Expand Up @@ -126,68 +125,23 @@ jobs:
FIREBASE_APP_DISTRIBUTION_SERVICE_ACCOUNT_CREDS_B64: ${{ secrets.FIREBASE_APP_DISTRIBUTION_SERVICE_ACCOUNT_CREDS_B64 }}

# xcodebuild creates builds that include a timestamp in the name. In order for bloaty to read the build, we need to rename it to a static name.
- name: Rename the same app build to a static name that bloaty can understand
- name: Rename the same app build to a static name that we can generate SDK size reports with
working-directory: Apps/${{ matrix.sample-app }}/build/
run: mv *.xcarchive App.xcarchive

#############
# Generate SDK size reports for the SDK size at this commit
#############

# We only need to run bloaty on 1 app. Therefore, we are hard-coding APN-UIKit into these steps below.

- name: Get the binary size of our SDK in an app, minus dependencies
id: sdk-size-report-minus-dependencies
if: ${{ matrix.sample-app == 'APN-UIKit' }}
working-directory: Apps/${{ matrix.sample-app }}/build/
run: |
{
echo 'report<<EOF'
bloaty --source-filter ".*(customerio-ios\/Sources).*" \
-d compileunits --debug-file=App.xcarchive/dSYMs/APN\ UIKit.app.dSYM/Contents/Resources/DWARF/APN\ UIKit \
App.xcarchive/Products/Applications/APN\ UIKit.app/APN\ UIKit \
-n 0
echo EOF
} >> "$GITHUB_OUTPUT"
- name: Get the binary size of our SDK in an app, including dependencies
id: sdk-size-report-including-dependencies
- name: Generate SDK size reports
uses: ./.github/actions/generate-sdk-size-report
if: ${{ matrix.sample-app == 'APN-UIKit' }}
working-directory: Apps/${{ matrix.sample-app }}/build/
# Run bloaty to generate report. The report is the STDOUT of the bloaty command. We save that into a GitHub Actions Env variable so we can use it later.
# https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#example-of-a-multiline-string
run: |
{
echo 'report<<EOF'
bloaty --source-filter ".*(customerio-ios\/Sources)|(SourcePackages\/checkouts).*" \
-d compileunits --debug-file=App.xcarchive/dSYMs/APN\ UIKit.app.dSYM/Contents/Resources/DWARF/APN\ UIKit \
App.xcarchive/Products/Applications/APN\ UIKit.app/APN\ UIKit \
-n 0
echo EOF
} >> "$GITHUB_OUTPUT"
#############
# Cache main builds for later use
#############

# If we are on the main branch, we want to cache the sample app build (.xcarchive directory) for later use.
# The main branch contains the latest version of our code. So, it's the new baseline that we compare all PRs against.
# By saving the sample app build, we can perform comparisons such as binary size changes between the main branch and the PR branch.

- name: Prepare the sample app build to be cached, if this is a main branch build
if: github.ref == 'refs/heads/main'
working-directory: Apps/${{ matrix.sample-app }}/build/
run: |
mv App.xcarchive MainBranchApp.xcarchive # Rename the app build to identify it and re-use it later.
- name: Cache the sample app build, if this is a main branch build
id: generate-sdk-size-report
with:
apn-app-xcarchive-name: App.xcarchive
generate-main-diff-report: ${{ github.event_name == 'pull_request' }}

- name: Save the sample app build, if this is a main branch build
if: github.ref == 'refs/heads/main'
uses: actions/cache/save@v4
uses: ./.github/actions/main-sample-app-build
with:
# the key must be unique. caches are immutable so the key must always be unique.
# https://github.com/actions/cache/blob/main/tips-and-workarounds.md#update-a-cache
key: ${{ matrix.sample-app }}-build-main-${{ github.run_id }}
path: Apps/${{ matrix.sample-app }}/build/MainBranchApp.xcarchive
apn-app-xcarchive-name: App.xcarchive

- name: Update sample builds PR comment with build information
if: ${{ github.event_name == 'pull_request' }}
Expand All @@ -210,44 +164,6 @@ jobs:
* ${{ matrix.sample-app }}: Build failed. See [CI job logs](https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}) to determine the issue and try re-building.
edit-mode: append # append new line to the existing PR comment to build a list of all sample app builds.

#############
# Generate SDK size diff report between main branch and PR
#############

# We want to determine if the SDK's binary size will change after merging the PR.
# To do that, we take the latest sample app build from the main branch and the PR branch and compare the SDK sizes between them.
#
# Note: We only need to use 1 sample app build to generate the SDK size diff report. Therefore, we are hard-coding APN-UIKit into these steps below.

- name: Download latest main sample app build to generate SDK size diff report
if: github.event_name == 'pull_request' && matrix.sample-app == 'APN-UIKit'
uses: actions/cache/restore@v4
with:
# key param is required for this action to run, but the value has no effect. Therefore, the value is a placeholder value.
# The restore-keys param is what will download the latest cache version for us.
key: ThisWillNotMatchAnything-ButValueIsRequiredHere
path: Apps/${{ matrix.sample-app }}/build/MainBranchApp.xcarchive
# The restore key is what will download the latest cache entry for us.
#
# "If there are multiple partial matches for a restore key, the action returns the most recently created cache."
# https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#matching-a-cache-key
restore-keys: |
${{ matrix.sample-app }}-build-main-
- name: Generate SDK binary diff report between main branch and PR
id: generate-sdk-size-diff-report
if: github.event_name == 'pull_request' && matrix.sample-app == 'APN-UIKit'
working-directory: Apps/${{ matrix.sample-app }}/build/
run: |
{
echo 'report<<EOF'
bloaty --source-filter ".*(customerio-ios\/Sources).*" -d compileunits \
--debug-file="MainBranchApp.xcarchive/dSYMs/APN UIKit.app.dSYM/Contents/Resources/DWARF/APN UIKit" \
--debug-file="App.xcarchive/dSYMs/APN UIKit.app.dSYM/Contents/Resources/DWARF/APN UIKit" \
"App.xcarchive/Products/Applications/APN UIKit.app/APN UIKit" -- "MainBranchApp.xcarchive/Products/Applications/APN UIKit.app/APN UIKit"
echo EOF
} >> "$GITHUB_OUTPUT"
- name: Find existing SDK size report comment, if there is one.
if: github.event_name == 'pull_request' && matrix.sample-app == 'APN-UIKit'
uses: peter-evans/find-comment@v3
Expand All @@ -269,28 +185,28 @@ jobs:
# SDK binary size reports 📊
<details>
<summary>SDK binary size of this PR, including dependencies</summary>
<summary>SDK binary size of this PR</summary>
```
${{ steps.sdk-size-report-including-dependencies.outputs.report }}
${{ steps.generate-sdk-size-report.outputs.sdk-size-report }}
```
</details>
<details>
<summary>SDK binary size of this PR, minus dependencies</summary>
<summary>SDK binary size of this PR, including dependencies</summary>
```
${{ steps.sdk-size-report-minus-dependencies.outputs.report }}
```
${{ steps.generate-sdk-size-report.outputs.sdk-size-including-dependencies-report }}
```
</details>
<details>
<summary>SDK binary size diff report between this PR and the main branch</summary>
```
${{ steps.generate-sdk-size-diff-report.outputs.report }}
${{ steps.generate-sdk-size-report.outputs.sdk-size-diff-report }}
```
</details>
</details>

0 comments on commit f601bca

Please sign in to comment.