Skip to content

Commit 22878c7

Browse files
mydeaZen-cronic
authored andcommitted
ci: Streamline some caching (getsentry#13355)
This streamlines some caching stuff for CI: 1. Extract dependency installation & cache out into a composite action for reusability 2. Updated the cache key for dependencies to only include package & dev-package `package.json`, not the E2E test ones.
1 parent c0239b1 commit 22878c7

File tree

2 files changed

+36
-33
lines changed

2 files changed

+36
-33
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: "Install yarn dependencies"
2+
description: "Installs yarn dependencies and caches them."
3+
4+
outputs:
5+
cache_key:
6+
description: "The dependency cache key"
7+
value: ${{ steps.compute_lockfile_hash.outputs.hash }}
8+
9+
runs:
10+
using: "composite"
11+
steps:
12+
# we use a hash of yarn.lock as our cache key, because if it hasn't changed, our dependencies haven't changed,
13+
# so no need to reinstall them
14+
- name: Compute dependency cache key
15+
id: compute_lockfile_hash
16+
run: echo "hash=dependencies-${{ hashFiles('yarn.lock', 'packages/*/package.json', 'dev-packages/*/package.json') }}" >> "$GITHUB_OUTPUT"
17+
shell: bash
18+
19+
- name: Check dependency cache
20+
uses: actions/cache@v4
21+
id: cache_dependencies
22+
with:
23+
path: ${{ env.CACHED_DEPENDENCY_PATHS }}
24+
key: ${{ steps.compute_lockfile_hash.outputs.hash }}
25+
26+
- name: Install dependencies
27+
if: steps.cache_dependencies.outputs.cache-hit != 'true'
28+
run: yarn install --ignore-engines --frozen-lockfile
29+
shell: bash

.github/workflows/build.yml

+7-33
Original file line numberDiff line numberDiff line change
@@ -146,22 +146,9 @@ jobs:
146146
with:
147147
node-version-file: 'package.json'
148148

149-
# we use a hash of yarn.lock as our cache key, because if it hasn't changed, our dependencies haven't changed,
150-
# so no need to reinstall them
151-
- name: Compute dependency cache key
152-
id: compute_lockfile_hash
153-
run: echo "hash=${{ hashFiles('yarn.lock', '**/package.json') }}" >> "$GITHUB_OUTPUT"
154-
155-
- name: Check dependency cache
156-
uses: actions/cache@v4
157-
id: cache_dependencies
158-
with:
159-
path: ${{ env.CACHED_DEPENDENCY_PATHS }}
160-
key: ${{ steps.compute_lockfile_hash.outputs.hash }}
161-
162-
- name: Install dependencies
163-
if: steps.cache_dependencies.outputs.cache-hit != 'true'
164-
run: yarn install --ignore-engines --frozen-lockfile
149+
- name: Install Dependencies
150+
uses: ./.github/actions/install-dependencies
151+
id: install_dependencies
165152

166153
- name: Check for Affected Nx Projects
167154
uses: dkhunt27/[email protected]
@@ -200,7 +187,7 @@ jobs:
200187
run: yarn build
201188

202189
outputs:
203-
dependency_cache_key: ${{ steps.compute_lockfile_hash.outputs.hash }}
190+
dependency_cache_key: ${{ steps.install_dependencies.outputs.cache_key }}
204191
changed_node_integration: ${{ needs.job_get_metadata.outputs.changed_ci == 'true' || contains(steps.checkForAffected.outputs.affected, '@sentry-internal/node-integration-tests') }}
205192
changed_remix: ${{ needs.job_get_metadata.outputs.changed_ci == 'true' || contains(steps.checkForAffected.outputs.affected, '@sentry/remix') }}
206193
changed_node: ${{ needs.job_get_metadata.outputs.changed_ci == 'true' || contains(steps.checkForAffected.outputs.affected, '@sentry/node') }}
@@ -293,22 +280,9 @@ jobs:
293280
with:
294281
node-version-file: 'package.json'
295282

296-
# we use a hash of yarn.lock as our cache key, because if it hasn't changed, our dependencies haven't changed,
297-
# so no need to reinstall them
298-
- name: Compute dependency cache key
299-
id: compute_lockfile_hash
300-
run: echo "hash=${{ hashFiles('yarn.lock', '**/package.json') }}" >> "$GITHUB_OUTPUT"
301-
302-
- name: Check dependency cache
303-
uses: actions/cache@v4
304-
id: cache_dependencies
305-
with:
306-
path: ${{ env.CACHED_DEPENDENCY_PATHS }}
307-
key: ${{ steps.compute_lockfile_hash.outputs.hash }}
308-
309-
- name: Install dependencies
310-
if: steps.cache_dependencies.outputs.cache-hit != 'true'
311-
run: yarn install --ignore-engines --frozen-lockfile
283+
- name: Install Dependencies
284+
uses: ./.github/actions/install-dependencies
285+
id: install_dependencies
312286

313287
- name: Check file formatting
314288
run: yarn lint:prettier && yarn lint:biome

0 commit comments

Comments
 (0)