Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(test): fix unit test caching issues #5092

Merged
merged 1 commit into from
Oct 31, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 47 additions & 9 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,12 @@ jobs:
cache-name: cache-build
with:
path: './*'
key: ${{ runner.os }}-build-${{ matrix.node }}-${{ env.cache-name }}-${{ github.run_id }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
# Unique key for a workflow run. Should be invalidated in the next run
key: ${{ runner.os }}-build-${{ matrix.node }}-${{ env.cache-name }}-${{ github.run_id }}-${{ github.run_attempt }}

- name: Install project dependencies
if: steps.cache-node-modules.outputs.cache-hit != 'true'
run: yarn install --frozen-lockfile

- name: Build CLI
run: yarn build:cli # Needed for CLI tests
Expand Down Expand Up @@ -99,24 +100,30 @@ jobs:
with:
node-version: ${{ matrix.node }}

- uses: actions/cache@v3
- name: Restore node_modules cache
uses: actions/cache/restore@v3
id: restore-node-modules
env:
cache-name: cache-node-modules
with:
path: '**/node_modules'
key: ${{ runner.os }}-modules-${{ env.cache-name }}-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-modules-${{ env.cache-name }}-
${{ runner.os }}-modules-
${{ runner.os }}-

- uses: actions/cache@v3
- name: Restore build cache
uses: actions/cache/restore@v3
id: restore-build
env:
cache-name: cache-build
with:
path: ./*
key: ${{ runner.os }}-build-${{ matrix.node }}-${{ env.cache-name }}-${{ github.run_id }}
key: ${{ runner.os }}-build-${{ matrix.node }}-${{ env.cache-name }}-${{ github.run_id }}-${{ github.run_attempt }}

- name: Install project dependencies
if: steps.cache-node-modules.outputs.cache-hit != 'true'
if: steps.restore-node-modules.outputs.cache-hit != 'true'
run: yarn install --frozen-lockfile

- name: Test
Expand All @@ -128,3 +135,34 @@ jobs:
env:
SANITY_CI_CLI_AUTH_TOKEN: ${{ secrets.SANITY_CI_CLI_AUTH_TOKEN }}
GITHUB_SHARD_IDENTIFIER: ${{ matrix.shardIndex }}-${{ matrix.shardTotal }}

cleanup:
timeout-minutes: 60
name: Cleanup (${{ matrix.os }} / node ${{ matrix.node }})
runs-on: ${{ matrix.os }}
continue-on-error: ${{ matrix.experimental }}
needs: [test]

strategy:
# we want to know if a test fails on a specific node version
fail-fast: false
matrix:
os: [ubuntu-latest]
node: [18, 20]
experimental: [false]

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup node
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}

# Delete the cache so it is only used once
- name: Delete Cache
run: gh cache delete ${{ runner.os }}-build-${{ matrix.node }}-${{ env.cache-name }}-${{ github.run_id }}-${{ github.run_attempt }}
env:
cache-name: cache-build
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Loading