Skip to content

Commit

Permalink
meta: Fix yarn caching in github actions (#3526)
Browse files Browse the repository at this point in the history
* Fix yarn caching in github actions

* improve cache take 2

from https://github.com/actions/cache/blob/main/examples.md#node---yarn-2

* fix yarn -> corepack yarn

* fix order of corepack install

* add --immutable to all
  • Loading branch information
mifi committed Mar 3, 2022
1 parent 6559bea commit 32ea099
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 47 deletions.
56 changes: 44 additions & 12 deletions .github/workflows/ci.yml
Expand Up @@ -17,12 +17,23 @@ jobs:
steps:
- name: Checkout sources
uses: actions/checkout@v2
- name: Install Corepack if needed
run: corepack -v || npm install -g corepack
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(corepack yarn config get cacheFolder)"

- uses: actions/cache@v2
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install Node.js
uses: actions/setup-node@v2
with:
node-version: ${{matrix.node-version}}
- name: Install Corepack if needed
run: corepack -v || npm install -g corepack
- name: Install dependencies
run: corepack yarn install --immutable
- name: Run tests
Expand All @@ -34,12 +45,17 @@ jobs:
steps:
- name: Checkout sources
uses: actions/checkout@v2
- name: Cache npm dependencies
id: cache-npm-libraries
uses: actions/cache@v2
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(corepack yarn config get cacheFolder)"

- uses: actions/cache@v2
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: .yarn/cache/*
key: ${{ runner.os }}
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install Node.js
uses: actions/setup-node@v2
with:
Expand All @@ -55,12 +71,17 @@ jobs:
steps:
- name: Checkout sources
uses: actions/checkout@v2
- name: Cache npm dependencies
id: cache-npm-libraries
uses: actions/cache@v2
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(corepack yarn config get cacheFolder)"

- uses: actions/cache@v2
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: .yarn/cache/*
key: ${{ runner.os }}
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install Node.js
uses: actions/setup-node@v2
with:
Expand All @@ -76,6 +97,17 @@ jobs:
steps:
- name: Checkout sources
uses: actions/checkout@v2
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(corepack yarn config get cacheFolder)"

- uses: actions/cache@v2
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install Node.js
uses: actions/setup-node@v2
with:
Expand Down
19 changes: 12 additions & 7 deletions .github/workflows/companion.yml
Expand Up @@ -16,18 +16,23 @@ jobs:
steps:
- name: Checkout sources
uses: actions/checkout@v2
- name: Cache npm dependencies
id: cache-npm-libraries
uses: actions/cache@v2
- name: Install Corepack if needed
run: corepack -v || npm install -g corepack
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(corepack yarn config get cacheFolder)"

- uses: actions/cache@v2
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: .yarn/cache/*
key: ${{ runner.os }}
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install Node.js
uses: actions/setup-node@v2
with:
node-version: ${{matrix.node-version}}
- name: Install Corepack if needed
run: corepack -v || npm install -g corepack
- name: Install dependencies
run: corepack yarn install --immutable
env:
Expand Down
15 changes: 10 additions & 5 deletions .github/workflows/end-to-end.yml
Expand Up @@ -17,12 +17,17 @@ jobs:
# Necessary for yarn version plugin
# https://yarnpkg.com/features/release-workflow#commit-history
fetch-depth: 0
- name: Cache npm dependencies
id: cache-npm-libraries
uses: actions/cache@v2
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(corepack yarn config get cacheFolder)"

- uses: actions/cache@v2
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: .yarn/cache/*
key: ${{ runner.os }}
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install Node.js
uses: actions/setup-node@v2
with:
Expand Down
17 changes: 11 additions & 6 deletions .github/workflows/manual-cdn.yml
Expand Up @@ -13,18 +13,23 @@ jobs:
steps:
- name: Checkout sources
uses: actions/checkout@v2
- name: Cache npm dependencies
id: cache-npm-libraries
uses: actions/cache@v2
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(corepack yarn config get cacheFolder)"

- uses: actions/cache@v2
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: .yarn/cache/*
key: ${{ runner.os }}
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install Node.js
uses: actions/setup-node@v2
with:
node-version: 16.x
- name: Install dependencies
run: corepack yarn install
run: corepack yarn install --immutable
- name: Build before publishing
run: corepack yarn run build
- name: Upload `${{ github.event.inputs.name }}` to CDN
Expand Down
17 changes: 11 additions & 6 deletions .github/workflows/release-candidate.yml
Expand Up @@ -18,18 +18,23 @@ jobs:
git config --global user.email "actions@github.com"
git config --global user.name "GitHub Actions"
git rebase FETCH_HEAD
- name: Cache npm dependencies
id: cache-npm-libraries
uses: actions/cache@v2
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(corepack yarn config get cacheFolder)"

- uses: actions/cache@v2
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: .yarn/cache/*
key: ${{ runner.os }}
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install Node.js
uses: actions/setup-node@v2
with:
node-version: 16.x
- name: Install dependencies
run: corepack yarn install
run: corepack yarn install --immutable
- name: Bump candidate packages version
run: corepack yarn version apply --all --json | jq -s > releases.json
- name: Prepare changelog
Expand Down
17 changes: 11 additions & 6 deletions .github/workflows/release.yml
Expand Up @@ -13,18 +13,23 @@ jobs:
uses: actions/checkout@v2
with:
fetch-depth: 2
- name: Cache npm dependencies
id: cache-npm-libraries
uses: actions/cache@v2
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(corepack yarn config get cacheFolder)"

- uses: actions/cache@v2
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: .yarn/cache/*
key: ${{ runner.os }}
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install Node.js
uses: actions/setup-node@v2
with:
node-version: 16.x
- name: Install dependencies
run: corepack yarn install
run: corepack yarn install --immutable
- name: Get CHANGELOG diff
run: git --no-pager diff HEAD^ -- CHANGELOG.md | awk '{ if( substr($0,0,1) == "+" && $1 != "+##" && $1 != "+Released:" && $1 != "+++" ) { print substr($0,2) } }' > CHANGELOG.diff.md
- name: Copy README for `uppy` package
Expand Down
15 changes: 10 additions & 5 deletions .github/workflows/website.yml
Expand Up @@ -11,12 +11,17 @@ jobs:
steps:
- name: Checkout sources
uses: actions/checkout@v2
- name: Cache npm dependencies
id: cache-npm-libraries
uses: actions/cache@v2
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(corepack yarn config get cacheFolder)"

- uses: actions/cache@v2
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: .yarn/cache/*
key: ${{ runner.os }}
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install Node.js
uses: actions/setup-node@v2
with:
Expand Down

0 comments on commit 32ea099

Please sign in to comment.