diff --git a/.github/actions/cocoa-cache-key/action.yml b/.github/actions/cocoa-cache-key/action.yml new file mode 100644 index 0000000000..1862eaa9e2 --- /dev/null +++ b/.github/actions/cocoa-cache-key/action.yml @@ -0,0 +1,13 @@ +name: Cocoa SDK cache key +description: Computes the cache key for the Cocoa SDK that Sentry.Bindings.Cocoa builds from the sentry-cocoa submodule +outputs: + key: + description: Covers the selected Xcode, build-sentry-cocoa.sh, sentry-cocoa.xcconfig and the submodule commit + value: ${{ steps.key.outputs.key }} +runs: + using: composite + + steps: + - id: key + shell: bash + run: echo "key=sentry-cocoa-$(xcodebuild -version | tr -cs '[:alnum:].' '-')-${{ hashFiles('scripts/build-sentry-cocoa.sh', 'scripts/sentry-cocoa.xcconfig') }}-${{ hashFiles('.git/modules/modules/sentry-cocoa/HEAD') }}" >> "$GITHUB_OUTPUT" diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 52976f9593..b3b3ad321b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -209,6 +209,22 @@ jobs: fail-on-cache-miss: true enableCrossOsArchive: true + # The Cocoa SDK is built from the submodule by the Sentry.Bindings.Cocoa project, which takes ~15 minutes + # on a hosted runner. build-sentry-cocoa.sh skips the build when the restored stamp matches. + # Release builds always build it from source, because it ships in the Sentry.Bindings.Cocoa package. + - name: Get Cocoa SDK cache key + id: cocoa-key + if: runner.os == 'macOS' + uses: ./.github/actions/cocoa-cache-key + + - name: Restore Cocoa SDK + id: cache-cocoa + if: runner.os == 'macOS' && !startsWith(github.ref_name, 'release/') + uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 + with: + path: modules/sentry-cocoa/Carthage + key: ${{ steps.cocoa-key.outputs.key }} + - name: Build Native Dependencies if: ${{ !matrix.container && !env.NO_MOBILE }} uses: ./.github/actions/buildnative @@ -220,6 +236,14 @@ jobs: id: build run: dotnet build ${{ matrix.slnf }} -c Release --no-restore --nologo -v:minimal -flp:logfile=build.log -p:CopyLocalLockFileAssemblies=true -bl:build.binlog + # Only a completed Cocoa build writes the stamp, so a failed one is never cached. + - name: Save Cocoa SDK + if: ${{ !cancelled() && steps.cache-cocoa.outputs.cache-primary-key != '' && steps.cache-cocoa.outputs.cache-hit != 'true' && hashFiles('modules/sentry-cocoa/Carthage/.built-from-sha') != '' }} + uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 + with: + path: modules/sentry-cocoa/Carthage + key: ${{ steps.cache-cocoa.outputs.cache-primary-key }} + - name: Upload build logs if: ${{ always() }} uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 diff --git a/.github/workflows/device-tests-ios.yml b/.github/workflows/device-tests-ios.yml index bbc751bcbe..222f969c52 100644 --- a/.github/workflows/device-tests-ios.yml +++ b/.github/workflows/device-tests-ios.yml @@ -75,9 +75,28 @@ jobs: - name: Setup Environment uses: ./.github/actions/environment + # See build.yml + - name: Get Cocoa SDK cache key + id: cocoa-key + uses: ./.github/actions/cocoa-cache-key + + - name: Restore Cocoa SDK + id: cache-cocoa + uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 + with: + path: modules/sentry-cocoa/Carthage + key: ${{ steps.cocoa-key.outputs.key }} + - name: Build iOS Test App run: pwsh ./scripts/device-test.ps1 ios -Build + - name: Save Cocoa SDK + if: ${{ !cancelled() && steps.cache-cocoa.outputs.cache-hit != 'true' && hashFiles('modules/sentry-cocoa/Carthage/.built-from-sha') != '' }} + uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 + with: + path: modules/sentry-cocoa/Carthage + key: ${{ steps.cache-cocoa.outputs.cache-primary-key }} + - name: Run Tests id: first-test-run continue-on-error: true