Skip to content

Commit

Permalink
ci: Do not fail on missing dependency cache (#13492)
Browse files Browse the repository at this point in the history
This PR updates CI to never fail on cache misses. Instead, we rerun
install or rebuild the tarballs, if necessary.

One tricky aspect of this is that `yarn install` will fail when running
on node 14, because some dependencies do not work with it. We "fix" this
by temporarily installing the default node version in this case, run
`yarn install`, then revert to node 14.
  • Loading branch information
mydea authored Aug 28, 2024
1 parent 14e56c7 commit 977c508
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 45 deletions.
27 changes: 23 additions & 4 deletions .github/actions/restore-cache/action.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
name: "Restore dependency & build cache"
description: "Restore the dependency & build cache."

inputs:
dependency_cache_key:
description: "The dependency cache key"
required: true
node_version:
description: "If set, temporarily set node version to default one before installing, then revert to this version after."
required: false

runs:
using: "composite"
steps:
Expand All @@ -9,15 +17,26 @@ runs:
uses: actions/cache/restore@v4
with:
path: ${{ env.CACHED_DEPENDENCY_PATHS }}
key: ${{ env.DEPENDENCY_CACHE_KEY }}
key: ${{ inputs.dependency_cache_key }}

- name: Restore build artifacts
uses: actions/download-artifact@v4
with:
name: build-output

- name: Check if caches are restored
uses: actions/github-script@v6
- name: Use default node version for install
if: inputs.node_version && steps.dep-cache.outputs.cache-hit != 'true'
uses: actions/setup-node@v4
with:
node-version-file: 'package.json'

- name: Install dependencies
if: steps.dep-cache.outputs.cache-hit != 'true'
run: yarn install --ignore-engines --frozen-lockfile
shell: bash

- name: Revert node version to ${{ inputs.node_version }}
if: inputs.node_version && steps.dep-cache.outputs.cache-hit != 'true'
uses: actions/setup-node@v4
with:
script: core.setFailed('Dependency cache could not be restored - please re-run ALL jobs.')
node-version: ${{ inputs.node_version }}
97 changes: 56 additions & 41 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,8 @@ jobs:
node-version-file: 'package.json'
- name: Restore caches
uses: ./.github/actions/restore-cache
env:
DEPENDENCY_CACHE_KEY: ${{ needs.job_build.outputs.dependency_cache_key }}
with:
dependency_cache_key: ${{ needs.job_build.outputs.dependency_cache_key }}
- name: Check bundle sizes
uses: ./dev-packages/size-limit-gh-action
with:
Expand All @@ -260,8 +260,8 @@ jobs:
node-version-file: 'package.json'
- name: Restore caches
uses: ./.github/actions/restore-cache
env:
DEPENDENCY_CACHE_KEY: ${{ needs.job_build.outputs.dependency_cache_key }}
with:
dependency_cache_key: ${{ needs.job_build.outputs.dependency_cache_key }}
- name: Lint source files
run: yarn lint:lerna
- name: Lint C++ files
Expand Down Expand Up @@ -306,8 +306,8 @@ jobs:
node-version-file: 'package.json'
- name: Restore caches
uses: ./.github/actions/restore-cache
env:
DEPENDENCY_CACHE_KEY: ${{ needs.job_build.outputs.dependency_cache_key }}
with:
dependency_cache_key: ${{ needs.job_build.outputs.dependency_cache_key }}
- name: Run madge
run: yarn circularDepCheck

Expand All @@ -328,8 +328,8 @@ jobs:
node-version-file: 'package.json'
- name: Restore caches
uses: ./.github/actions/restore-cache
env:
DEPENDENCY_CACHE_KEY: ${{ needs.job_build.outputs.dependency_cache_key }}
with:
dependency_cache_key: ${{ needs.job_build.outputs.dependency_cache_key }}

- name: Extract Profiling Node Prebuilt Binaries
uses: actions/download-artifact@v4
Expand Down Expand Up @@ -376,8 +376,8 @@ jobs:
node-version-file: 'package.json'
- name: Restore caches
uses: ./.github/actions/restore-cache
env:
DEPENDENCY_CACHE_KEY: ${{ needs.job_build.outputs.dependency_cache_key }}
with:
dependency_cache_key: ${{ needs.job_build.outputs.dependency_cache_key }}

- name: Run affected tests
run: yarn test:pr:browser --base=${{ github.event.pull_request.base.sha }}
Expand Down Expand Up @@ -413,8 +413,8 @@ jobs:
uses: oven-sh/setup-bun@v2
- name: Restore caches
uses: ./.github/actions/restore-cache
env:
DEPENDENCY_CACHE_KEY: ${{ needs.job_build.outputs.dependency_cache_key }}
with:
dependency_cache_key: ${{ needs.job_build.outputs.dependency_cache_key }}
- name: Run tests
run: |
yarn test:ci:bun
Expand Down Expand Up @@ -442,8 +442,8 @@ jobs:
deno-version: v1.38.5
- name: Restore caches
uses: ./.github/actions/restore-cache
env:
DEPENDENCY_CACHE_KEY: ${{ needs.job_build.outputs.dependency_cache_key }}
with:
dependency_cache_key: ${{ needs.job_build.outputs.dependency_cache_key }}
- name: Run tests
run: |
cd packages/deno
Expand Down Expand Up @@ -476,8 +476,9 @@ jobs:
node-version: ${{ matrix.node }}
- name: Restore caches
uses: ./.github/actions/restore-cache
env:
DEPENDENCY_CACHE_KEY: ${{ needs.job_build.outputs.dependency_cache_key }}
with:
dependency_cache_key: ${{ needs.job_build.outputs.dependency_cache_key }}
node_version: ${{ matrix.node == 14 && '14' || '' }}

- name: Run affected tests
run: yarn test:pr:node --base=${{ github.event.pull_request.base.sha }}
Expand Down Expand Up @@ -515,8 +516,8 @@ jobs:
python-version: '3.11.7'
- name: Restore caches
uses: ./.github/actions/restore-cache
env:
DEPENDENCY_CACHE_KEY: ${{ needs.job_build.outputs.dependency_cache_key }}
with:
dependency_cache_key: ${{ needs.job_build.outputs.dependency_cache_key }}
- name: Build Configure node-gyp
run: yarn lerna run build:bindings:configure --scope @sentry/profiling-node
- name: Build Bindings for Current Environment
Expand Down Expand Up @@ -583,8 +584,8 @@ jobs:
node-version-file: 'package.json'
- name: Restore caches
uses: ./.github/actions/restore-cache
env:
DEPENDENCY_CACHE_KEY: ${{ needs.job_build.outputs.dependency_cache_key }}
with:
dependency_cache_key: ${{ needs.job_build.outputs.dependency_cache_key }}

- name: Install Playwright
uses: ./.github/actions/install-playwright
Expand Down Expand Up @@ -635,8 +636,8 @@ jobs:
node-version-file: 'package.json'
- name: Restore caches
uses: ./.github/actions/restore-cache
env:
DEPENDENCY_CACHE_KEY: ${{ needs.job_build.outputs.dependency_cache_key }}
with:
dependency_cache_key: ${{ needs.job_build.outputs.dependency_cache_key }}

- name: Install Playwright
uses: ./.github/actions/install-playwright
Expand Down Expand Up @@ -674,8 +675,8 @@ jobs:
node-version-file: 'package.json'
- name: Restore caches
uses: ./.github/actions/restore-cache
env:
DEPENDENCY_CACHE_KEY: ${{ needs.job_build.outputs.dependency_cache_key }}
with:
dependency_cache_key: ${{ needs.job_build.outputs.dependency_cache_key }}
- name: Check for dts files that reference stuff in the temporary build folder
run: |
if grep -r --include "*.d.ts" --exclude-dir ".nxcache" 'import("@sentry(-internal)?/[^/]*/build' .; then
Expand Down Expand Up @@ -712,8 +713,9 @@ jobs:
node-version: ${{ matrix.node }}
- name: Restore caches
uses: ./.github/actions/restore-cache
env:
DEPENDENCY_CACHE_KEY: ${{ needs.job_build.outputs.dependency_cache_key }}
with:
dependency_cache_key: ${{ needs.job_build.outputs.dependency_cache_key }}
node_version: ${{ matrix.node == 14 && '14' || '' }}

- name: Overwrite typescript version
if: matrix.typescript
Expand Down Expand Up @@ -753,8 +755,8 @@ jobs:
node-version: ${{ matrix.node }}
- name: Restore caches
uses: ./.github/actions/restore-cache
env:
DEPENDENCY_CACHE_KEY: ${{ needs.job_build.outputs.dependency_cache_key }}
with:
dependency_cache_key: ${{ needs.job_build.outputs.dependency_cache_key }}

- name: Install Playwright
uses: ./.github/actions/install-playwright
Expand Down Expand Up @@ -791,8 +793,8 @@ jobs:
node-version-file: 'package.json'
- name: Restore caches
uses: ./.github/actions/restore-cache
env:
DEPENDENCY_CACHE_KEY: ${{ needs.job_build.outputs.dependency_cache_key }}
with:
dependency_cache_key: ${{ needs.job_build.outputs.dependency_cache_key }}
- name: NX cache
uses: actions/cache/restore@v4
with:
Expand Down Expand Up @@ -953,15 +955,19 @@ jobs:
uses: oven-sh/setup-bun@v2
- name: Restore caches
uses: ./.github/actions/restore-cache
env:
DEPENDENCY_CACHE_KEY: ${{ needs.job_build.outputs.dependency_cache_key }}
with:
dependency_cache_key: ${{ needs.job_build.outputs.dependency_cache_key }}

- name: Restore tarball cache
uses: actions/cache/restore@v4
id: restore-tarball-cache
with:
path: ${{ github.workspace }}/packages/*/*.tgz
key: ${{ env.BUILD_CACHE_TARBALL_KEY }}
fail-on-cache-miss: true

- name: Build tarballs if not cached
if: steps.restore-tarball-cache.outputs.cache-hit != 'true'
run: yarn build:tarball

- name: Install Playwright
uses: ./.github/actions/install-playwright
Expand Down Expand Up @@ -1053,15 +1059,19 @@ jobs:
node-version-file: 'dev-packages/e2e-tests/package.json'
- name: Restore caches
uses: ./.github/actions/restore-cache
env:
DEPENDENCY_CACHE_KEY: ${{ needs.job_build.outputs.dependency_cache_key }}
with:
dependency_cache_key: ${{ needs.job_build.outputs.dependency_cache_key }}

- name: Restore tarball cache
uses: actions/cache/restore@v4
id: restore-tarball-cache
with:
path: ${{ github.workspace }}/packages/*/*.tgz
key: ${{ env.BUILD_CACHE_TARBALL_KEY }}
fail-on-cache-miss: true

- name: Build tarballs if not cached
if: steps.restore-tarball-cache.outputs.cache-hit != 'true'
run: yarn build:tarball

- name: Install Playwright
uses: ./.github/actions/install-playwright
Expand Down Expand Up @@ -1148,8 +1158,8 @@ jobs:
node-version-file: 'dev-packages/e2e-tests/package.json'
- name: Restore caches
uses: ./.github/actions/restore-cache
env:
DEPENDENCY_CACHE_KEY: ${{ needs.job_build.outputs.dependency_cache_key }}
with:
dependency_cache_key: ${{ needs.job_build.outputs.dependency_cache_key }}
- name: Build Profiling Node
run: yarn lerna run build:lib --scope @sentry/profiling-node
- name: Extract Profiling Node Prebuilt Binaries
Expand All @@ -1158,12 +1168,17 @@ jobs:
pattern: profiling-node-binaries-${{ github.sha }}-*
path: ${{ github.workspace }}/packages/profiling-node/lib/
merge-multiple: true

- name: Restore tarball cache
uses: actions/cache/restore@v4
id: restore-tarball-cache
with:
path: ${{ github.workspace }}/packages/*/*.tgz
key: ${{ env.BUILD_CACHE_TARBALL_KEY }}
fail-on-cache-miss : true

- name: Build tarballs if not cached
if: steps.restore-tarball-cache.outputs.cache-hit != 'true'
run: yarn build:tarball

- name: Install Playwright
uses: ./.github/actions/install-playwright
Expand Down Expand Up @@ -1244,8 +1259,8 @@ jobs:
node-version-file: 'package.json'
- name: Restore caches
uses: ./.github/actions/restore-cache
env:
DEPENDENCY_CACHE_KEY: ${{ needs.job_build.outputs.dependency_cache_key }}
with:
dependency_cache_key: ${{ needs.job_build.outputs.dependency_cache_key }}

- name: Collect
run: yarn ci:collect
Expand Down

0 comments on commit 977c508

Please sign in to comment.