Commit 011136d0 authored by Zach Pomerantz's avatar Zach Pomerantz Committed by GitHub

build: improve workflow caching (#6825)

* build: only cache on main

* build: do not glob yarn.lock

* build: do not cache on yarn.lock
parent 054d1de8
name: Cache on main
description: caches node_modules/.cache, but only saves from main
inputs:
path:
description: 'A list of files, directories, and wildcard patterns to cache and store'
required: true
key:
description: 'An explicit key for restoring and saving the cache'
required: true
restore-keys:
description: 'An ordered list of keys to use for restoring stale cache if no cache hit occured for key. Note `cache-hit` returns false in this case.'
required: false
# Many build steps have their own caches to improve subsequent build times.
# Build tools are configured to cache to node_modules/.cache, so they are cached independently of node_modules.
# Caches are saved every run *on main* (by keying on github.run_id), and the most recent available cache is loaded.
# Caches are not saved on feature branches because they have limited utility, and extend the runtime of the workflow.
# See https://jongleberry.medium.com/speed-up-your-ci-and-dx-with-node-modules-cache-ac8df82b7bb0.
runs:
using: composite
steps:
- uses: actions/cache/restore@v3
with:
path: ${{ inputs.path }}
key: ${{ inputs.key }}
restore-keys: ${{ inputs.restore-keys }}
- if: github.ref_name == 'main'
uses: actions/cache/save@v3
with:
path: ${{ inputs.path }}
key: ${{ inputs.key }}
\ No newline at end of file
...@@ -19,7 +19,7 @@ runs: ...@@ -19,7 +19,7 @@ runs:
path: | path: |
node_modules node_modules
!node_modules/.cache !node_modules/.cache
key: ${{ runner.os }}-install-${{ hashFiles('**/yarn.lock') }} key: ${{ runner.os }}-install-${{ hashFiles('yarn.lock') }}
- if: steps.install-cache.outputs.cache-hit != 'true' - if: steps.install-cache.outputs.cache-hit != 'true'
run: yarn install --frozen-lockfile --ignore-scripts run: yarn install --frozen-lockfile --ignore-scripts
shell: bash shell: bash
...@@ -55,8 +55,7 @@ runs: ...@@ -55,8 +55,7 @@ runs:
# Messages are extracted from source. # Messages are extracted from source.
# A record of source file content hashes and catalogs is maintained in node_modules/.cache/lingui. # A record of source file content hashes and catalogs is maintained in node_modules/.cache/lingui.
# Messages are always extracted, but extraction may short-circuit from the custom extractor's cache. # Messages are always extracted, but extraction may short-circuit from the custom extractor's cache.
- uses: actions/cache@v3 - uses: ./.github/actions/cache-on-main
id: i18n-extract-cache
with: with:
path: node_modules/.cache path: node_modules/.cache
key: ${{ runner.os }}-i18n-extract-${{ github.run_id }} key: ${{ runner.os }}-i18n-extract-${{ github.run_id }}
......
...@@ -17,12 +17,11 @@ jobs: ...@@ -17,12 +17,11 @@ jobs:
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- uses: ./.github/actions/setup - uses: ./.github/actions/setup
- uses: actions/cache@v3 - uses: ./.github/actions/cache-on-main
id: eslint-cache
with: with:
path: node_modules/.cache path: node_modules/.cache
key: ${{ runner.os }}-eslint-${{ hashFiles('**/yarn.lock') }}-${{ github.run_id }} key: ${{ runner.os }}-eslint-${{ github.run_id }}
restore-keys: ${{ runner.os }}-eslint-${{ hashFiles('**/yarn.lock') }}- restore-keys: ${{ runner.os }}-eslint-
- run: yarn lint - run: yarn lint
- if: failure() && github.ref_name == 'main' - if: failure() && github.ref_name == 'main'
uses: ./.github/actions/report uses: ./.github/actions/report
...@@ -35,12 +34,11 @@ jobs: ...@@ -35,12 +34,11 @@ jobs:
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- uses: ./.github/actions/setup - uses: ./.github/actions/setup
- uses: actions/cache@v3 - uses: ./.github/actions/cache-on-main
id: tsc-cache
with: with:
path: node_modules/.cache path: node_modules/.cache
key: ${{ runner.os }}-tsc-${{ hashFiles('**/yarn.lock') }}-${{ github.run_id }} key: ${{ runner.os }}-tsc-${{ github.run_id }}
restore-keys: ${{ runner.os }}-tsc-${{ hashFiles('**/yarn.lock') }}- restore-keys: ${{ runner.os }}-tsc-
- run: yarn typecheck - run: yarn typecheck
- if: failure() && github.ref_name == 'main' - if: failure() && github.ref_name == 'main'
uses: ./.github/actions/report uses: ./.github/actions/report
...@@ -65,12 +63,11 @@ jobs: ...@@ -65,12 +63,11 @@ jobs:
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- uses: ./.github/actions/setup - uses: ./.github/actions/setup
- uses: actions/cache@v3 - uses: ./.github/actions/cache-on-main
id: jest-cache
with: with:
path: node_modules/.cache path: node_modules/.cache
key: ${{ runner.os }}-jest-${{ hashFiles('**/yarn.lock') }}-${{ github.run_id }} key: ${{ runner.os }}-jest-${{ github.run_id }}
restore-keys: ${{ runner.os }}-jest-${{ hashFiles('**/yarn.lock') }}- restore-keys: ${{ runner.os }}-jest-
- run: yarn test --coverage --maxWorkers=100% - run: yarn test --coverage --maxWorkers=100%
- uses: codecov/codecov-action@v3 - uses: codecov/codecov-action@v3
with: with:
...@@ -88,12 +85,11 @@ jobs: ...@@ -88,12 +85,11 @@ jobs:
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- uses: ./.github/actions/setup - uses: ./.github/actions/setup
- uses: actions/cache@v3 - uses: ./.github/actions/cache-on-main
id: build-e2e-cache
with: with:
path: node_modules/.cache path: node_modules/.cache
key: ${{ runner.os }}-build-e2e-${{ hashFiles('**/yarn.lock') }}-${{ github.run_id }} key: ${{ runner.os }}-build-e2e-${{ github.run_id }}
restore-keys: ${{ runner.os }}-build-e2e-${{ hashFiles('**/yarn.lock') }}- restore-keys: ${{ runner.os }}-build-e2e-
- run: yarn build:e2e - run: yarn build:e2e
env: env:
NODE_OPTIONS: "--max_old_space_size=4096" NODE_OPTIONS: "--max_old_space_size=4096"
...@@ -120,8 +116,7 @@ jobs: ...@@ -120,8 +116,7 @@ jobs:
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- uses: ./.github/actions/setup - uses: ./.github/actions/setup
- uses: actions/cache@v3 - uses: ./.github/actions/cache-on-main
id: cypress-cache
with: with:
path: /root/.cache/Cypress path: /root/.cache/Cypress
key: ${{ runner.os }}-cypress-${{ hashFiles('**/node_modules/cypress/package.json') }} key: ${{ runner.os }}-cypress-${{ hashFiles('**/node_modules/cypress/package.json') }}
...@@ -134,8 +129,7 @@ jobs: ...@@ -134,8 +129,7 @@ jobs:
name: build-e2e name: build-e2e
path: build path: build
- uses: actions/cache@v3 - uses: ./.github/actions/cache-on-main
id: hardhat-cache
with: with:
path: cache path: cache
key: ${{ runner.os }}-hardhat-${{ hashFiles('hardhat.config.js') }}-${{ github.run_id }} key: ${{ runner.os }}-hardhat-${{ hashFiles('hardhat.config.js') }}-${{ github.run_id }}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment