Skip to content

Commit

Permalink
ci: Streamline some caching (#13355)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mydea authored Aug 14, 2024
1 parent 7093d92 commit ecc299d
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 33 deletions.
29 changes: 29 additions & 0 deletions .github/actions/install-dependencies/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: "Install yarn dependencies"
description: "Installs yarn dependencies and caches them."

outputs:
cache_key:
description: "The dependency cache key"
value: ${{ steps.compute_lockfile_hash.outputs.hash }}

runs:
using: "composite"
steps:
# we use a hash of yarn.lock as our cache key, because if it hasn't changed, our dependencies haven't changed,
# so no need to reinstall them
- name: Compute dependency cache key
id: compute_lockfile_hash
run: echo "hash=dependencies-${{ hashFiles('yarn.lock', 'packages/*/package.json', 'dev-packages/*/package.json') }}" >> "$GITHUB_OUTPUT"
shell: bash

- name: Check dependency cache
uses: actions/cache@v4
id: cache_dependencies
with:
path: ${{ env.CACHED_DEPENDENCY_PATHS }}
key: ${{ steps.compute_lockfile_hash.outputs.hash }}

- name: Install dependencies
if: steps.cache_dependencies.outputs.cache-hit != 'true'
run: yarn install --ignore-engines --frozen-lockfile
shell: bash
40 changes: 7 additions & 33 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -146,22 +146,9 @@ jobs:
with:
node-version-file: 'package.json'

# we use a hash of yarn.lock as our cache key, because if it hasn't changed, our dependencies haven't changed,
# so no need to reinstall them
- name: Compute dependency cache key
id: compute_lockfile_hash
run: echo "hash=${{ hashFiles('yarn.lock', '**/package.json') }}" >> "$GITHUB_OUTPUT"

- name: Check dependency cache
uses: actions/cache@v4
id: cache_dependencies
with:
path: ${{ env.CACHED_DEPENDENCY_PATHS }}
key: ${{ steps.compute_lockfile_hash.outputs.hash }}

- name: Install dependencies
if: steps.cache_dependencies.outputs.cache-hit != 'true'
run: yarn install --ignore-engines --frozen-lockfile
- name: Install Dependencies
uses: ./.github/actions/install-dependencies
id: install_dependencies

- name: Check for Affected Nx Projects
uses: dkhunt27/action-nx-affected-list@v5.3
Expand Down Expand Up @@ -200,7 +187,7 @@ jobs:
run: yarn build

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

# we use a hash of yarn.lock as our cache key, because if it hasn't changed, our dependencies haven't changed,
# so no need to reinstall them
- name: Compute dependency cache key
id: compute_lockfile_hash
run: echo "hash=${{ hashFiles('yarn.lock', '**/package.json') }}" >> "$GITHUB_OUTPUT"

- name: Check dependency cache
uses: actions/cache@v4
id: cache_dependencies
with:
path: ${{ env.CACHED_DEPENDENCY_PATHS }}
key: ${{ steps.compute_lockfile_hash.outputs.hash }}

- name: Install dependencies
if: steps.cache_dependencies.outputs.cache-hit != 'true'
run: yarn install --ignore-engines --frozen-lockfile
- name: Install Dependencies
uses: ./.github/actions/install-dependencies
id: install_dependencies

- name: Check file formatting
run: yarn lint:prettier && yarn lint:biome
Expand Down

0 comments on commit ecc299d

Please sign in to comment.