Skip to content

Commit

Permalink
ci: sdk size main build cache hit
Browse files Browse the repository at this point in the history
  • Loading branch information
mrehan27 committed Sep 6, 2024
1 parent b7d7d4f commit 4140eb5
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .github/actions/generate-sdk-size-report/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ runs:
uses: ./.github/actions/main-sample-app-build
with:
set-latest-main-build: ${{ steps.build-sample-app.outputs.app-xcarchive-name }}
GOOGLE_CLOUD_MATCH_READONLY_SERVICE_ACCOUNT_B64: ${{ inputs.GOOGLE_CLOUD_MATCH_READONLY_SERVICE_ACCOUNT_B64 }}

- name: Make the SDK size report
uses: mathiasvr/[email protected]
Expand Down Expand Up @@ -78,6 +79,8 @@ runs:
if: ${{ github.event_name == 'pull_request' }}
id: download-latest-main-build
uses: ./.github/actions/main-sample-app-build
with:
GOOGLE_CLOUD_MATCH_READONLY_SERVICE_ACCOUNT_B64: ${{ inputs.GOOGLE_CLOUD_MATCH_READONLY_SERVICE_ACCOUNT_B64 }}

- name: Generate SDK binary diff report between main branch and current branch
if: ${{ steps.download-latest-main-build.outputs.apn-app-xcarchive-path != '' }}
Expand Down
53 changes: 50 additions & 3 deletions .github/actions/main-sample-app-build/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ inputs:
type: string
required: false
default: ''
GOOGLE_CLOUD_MATCH_READONLY_SERVICE_ACCOUNT_B64:
description: 'Maps to the secret, GOOGLE_CLOUD_MATCH_READONLY_SERVICE_ACCOUNT_B64. Used for code signing. See the Fastlane config files to learn more.'
type: string
required: true

outputs:
apn-app-xcarchive-path:
Expand All @@ -29,6 +33,7 @@ runs:
echo "CACHE_KEY_BASE=APN-UIKit-build-main-" >> $GITHUB_ENV
- name: Download latest main sample app build to compare against
id: restore-build
if: ${{ inputs.set-latest-main-build == '' }}
uses: actions/cache/restore@v4
with:
Expand All @@ -43,17 +48,59 @@ runs:
restore-keys: |
${{ env.CACHE_KEY_BASE }}
# If the cache is found, we set the cache-hit status to true.
# This is useful for future steps to know if the cache was found or not.
- name: Set cache-hit status
id: set-cache-hit-status
shell: bash
run: |
BUILD_CACHE_HIT="${{ steps.restore-build.outputs.cache-hit || 'false' }}"
echo "CACHE_HIT=$BUILD_CACHE_HIT" >> $GITHUB_ENV
if [[ "${{ inputs.set-latest-main-build }}" != "" || "$BUILD_CACHE_HIT" == "false" ]]; then
echo "SHOULD_SAVE_BUILD=true" >> $GITHUB_ENV
else
echo "SHOULD_SAVE_BUILD=false" >> $GITHUB_ENV
fi
- name: Checkout main branch
if: env.BUILD_CACHE_HIT == 'false'
uses: actions/checkout@v4
with:
ref: main

- name: Make a build of the sample app to generate report for
if: env.BUILD_CACHE_HIT == 'false'
uses: ./.github/actions/build-sample-app
id: fallback-build-main
with:
apn-or-fcm: 'APN'
sample-app: 'APN-UIKit'
# Pass in a hard-coded version and build number to ensure that all sample app builds that are compiled for SDK size reports are consistent.
# When we compare size reports between different builds, we want to ensure that the only difference is the SDK code that was modified in a PR.
fastlane-build-args: '{"app_version": "1.0.0", "build_number": "1"}'
# workspace credentials do not matter since we are not using this app build.
customerio-workspace-siteid: "12345"
customerio-workspace-cdp-api-key: "12345"
GOOGLE_CLOUD_MATCH_READONLY_SERVICE_ACCOUNT_B64: ${{ inputs.GOOGLE_CLOUD_MATCH_READONLY_SERVICE_ACCOUNT_B64 }}

- name: Set build file name for fallback build
if: env.BUILD_CACHE_HIT == 'false'
shell: bash
run: |
echo "BUILD_FILE_NAME=${{ steps.build-sample-app.outputs.app-xcarchive-name }}" >> $GITHUB_ENV
# It's easiest if the latest main build always has the same name that easily identifies it.
# Therefore, we take the input build and copy it to have the name that we expect to upload.
- name: If saving a new build, create copy that we will save.
if: ${{ inputs.set-latest-main-build != '' }}
- name: If saving a new build, create copy or use fallback build that we will save.
if: env.SHOULD_SAVE_BUILD == 'true'
working-directory: ${{ env.APN_SAMPLE_APP_BUILD_PATH }}
shell: bash
run: |
cp -r ${{ inputs.set-latest-main-build }} ${{ env.BUILD_FILE_NAME }}
- name: Save latest main sample app build
if: ${{ inputs.set-latest-main-build != '' }}
if: env.SHOULD_SAVE_BUILD == 'true'
uses: actions/cache/save@v4
with:
# the key must be unique. caches are immutable so the key must always be unique.
Expand Down

0 comments on commit 4140eb5

Please sign in to comment.