From 4140eb5d6377ba872e6665a6d3e4f0aefab852f2 Mon Sep 17 00:00:00 2001 From: Rehan Date: Fri, 6 Sep 2024 18:32:25 +0500 Subject: [PATCH] ci: sdk size main build cache hit --- .../generate-sdk-size-report/action.yml | 3 ++ .../actions/main-sample-app-build/action.yml | 53 +++++++++++++++++-- 2 files changed, 53 insertions(+), 3 deletions(-) diff --git a/.github/actions/generate-sdk-size-report/action.yml b/.github/actions/generate-sdk-size-report/action.yml index c6d66dd09..15d3d488c 100644 --- a/.github/actions/generate-sdk-size-report/action.yml +++ b/.github/actions/generate-sdk-size-report/action.yml @@ -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/command-output@v2.0.0 @@ -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 != '' }} diff --git a/.github/actions/main-sample-app-build/action.yml b/.github/actions/main-sample-app-build/action.yml index a71c1e51e..5221bb738 100644 --- a/.github/actions/main-sample-app-build/action.yml +++ b/.github/actions/main-sample-app-build/action.yml @@ -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: @@ -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: @@ -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.