-
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16581 from belgattitude/ci-improve-install-time
CI: speed up CI time by improving yarn install and caches (iteration 1 / >30%)
- Loading branch information
Showing
7 changed files
with
153 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
######################################################################################## | ||
# "yarn install" composite action for yarn 3/4+ and "nodeLinker: node-modules" # | ||
#--------------------------------------------------------------------------------------# | ||
# Requirement: @setup/node should be run before # | ||
# # | ||
# Usage in workflows steps: # | ||
# # | ||
# - name: 馃摜 Monorepo install # | ||
# uses: ./.github/actions/yarn-nm-install # | ||
# with: # | ||
# enable-corepack: false # (default) # | ||
# cache-install-state: false # (default) # | ||
# cache-node-modules: false # (default) # | ||
# # | ||
# Reference: # | ||
# - latest: https://gist.github.com/belgattitude/042f9caf10d029badbde6cf9d43e400a # | ||
######################################################################################## | ||
|
||
name: 'Monorepo install (yarn)' | ||
description: 'Run yarn install with node_modules linker and cache enabled' | ||
inputs: | ||
enable-corepack: | ||
description: 'Enable corepack' | ||
required: false | ||
default: 'false' | ||
cache-node-modules: | ||
description: 'Cache node_modules, might speed up link step (invalidated lock/os/node-version/branch)' | ||
required: false | ||
default: 'false' | ||
cache-install-state: | ||
description: 'Cache yarn install state, might speed up resolution step when node-modules cache is activated (invalidated lock/os/node-version/branch)' | ||
required: false | ||
default: 'false' | ||
|
||
runs: | ||
using: 'composite' | ||
|
||
steps: | ||
- name: 鈿欙笍 Enable Corepack | ||
if: ${{ inputs.enable-corepack }} == 'true' | ||
shell: bash | ||
run: corepack enable | ||
|
||
- name: 鈿欙笍 Expose yarn config as "$GITHUB_OUTPUT" | ||
id: yarn-config | ||
shell: bash | ||
env: | ||
YARN_ENABLE_GLOBAL_CACHE: "false" | ||
run: | | ||
echo "CACHE_FOLDER=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT | ||
echo "CURRENT_NODE_VERSION="node-$(node --version)"" >> $GITHUB_OUTPUT | ||
echo "CURRENT_BRANCH=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's,/,-,g')" >> $GITHUB_OUTPUT | ||
- name: 鈾伙笍 Restore yarn cache | ||
uses: actions/cache@v3 | ||
id: yarn-download-cache | ||
with: | ||
path: ${{ steps.yarn-config.outputs.CACHE_FOLDER }} | ||
key: yarn-download-cache-${{ hashFiles('yarn.lock', '.yarnrc.yml') }} | ||
restore-keys: | | ||
yarn-download-cache- | ||
- name: 鈾伙笍 Restore node_modules | ||
if: inputs.cache-node-modules == 'true' | ||
id: yarn-nm-cache | ||
uses: actions/cache@v3 | ||
with: | ||
path: '**/node_modules' | ||
key: yarn-nm-cache-${{ runner.os }}-${{ steps.yarn-config.outputs.CURRENT_NODE_VERSION }}-${{ steps.yarn-config.outputs.CURRENT_BRANCH }}-${{ hashFiles('yarn.lock', '.yarnrc.yml') }} | ||
|
||
- name: 鈾伙笍 Restore yarn install state | ||
if: inputs.cache-install-state == 'true' && inputs.cache-node-modules == 'true' | ||
id: yarn-install-state-cache | ||
uses: actions/cache@v3 | ||
with: | ||
path: .yarn/ci-cache | ||
key: yarn-install-state-cache-${{ runner.os }}-${{ steps.yarn-config.outputs.CURRENT_NODE_VERSION }}-${{ steps.yarn-config.outputs.CURRENT_BRANCH }}-${{ hashFiles('yarn.lock', '.yarnrc.yml') }} | ||
|
||
- name: 馃摜 Install dependencies | ||
shell: bash | ||
run: yarn install --immutable --inline-builds | ||
env: | ||
# Overrides/align yarnrc.yml options (v3, v4) for a CI context | ||
YARN_ENABLE_GLOBAL_CACHE: "false" # Use local cache folder to keep downloaded archives | ||
YARN_NM_MODE: "hardlinks-local" # Reduce node_modules size | ||
YARN_INSTALL_STATE_PATH: ".yarn/ci-cache/install-state.gz" # Might speed up resolutions when node_modules present | ||
# Other environment variables | ||
HUSKY: '0' # By default do not run HUSKY install |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#force-deleting-cache-entries | ||
name: Cleanup caches for closed branches | ||
|
||
on: | ||
pull_request: | ||
types: | ||
- closed | ||
workflow_dispatch: | ||
|
||
jobs: | ||
cleanup: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Check out code | ||
uses: actions/checkout@v3 | ||
|
||
- name: 馃Ч Cleanup | ||
run: | | ||
gh extension install actions/gh-actions-cache | ||
REPO=${{ github.repository }} | ||
BRANCH="refs/pull/${{ github.event.pull_request.number }}/merge" | ||
echo "Fetching list of cache key" | ||
cacheKeysForPR=$(gh actions-cache list -R $REPO -B $BRANCH | cut -f 1 ) | ||
## Setting this to not fail the workflow while deleting cache keys. | ||
set +e | ||
echo "Deleting caches..." | ||
for cacheKey in $cacheKeysForPR | ||
do | ||
gh actions-cache delete $cacheKey -R $REPO -B $BRANCH --confirm | ||
done | ||
echo "Done" | ||
env: | ||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters