-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: improve bootstrap and caching (#397)
- Loading branch information
1 parent
350296d
commit 8708b9a
Showing
8 changed files
with
103 additions
and
35 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,35 @@ | ||
--- | ||
# Based on https://gist.github.com/belgattitude/838b2eba30c324f1f0033a797bab2e31 | ||
name: Install pnpm | ||
description: Setup pnpm and install dependencies | ||
|
||
runs: | ||
using: 'composite' | ||
steps: | ||
- id: pnpm-config | ||
name: Expose pnpm config(s) through "$GITHUB_OUTPUT" | ||
run: | | ||
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT | ||
shell: 'bash -Eeuo pipefail {0}' | ||
|
||
- id: cache-rotation | ||
name: Cache rotation keys | ||
run: | | ||
echo "YEAR_MONTH=$(/bin/date -u "+%Y%m")" >> $GITHUB_OUTPUT | ||
shell: 'bash -Eeuo pipefail {0}' | ||
|
||
- name: Setup pnpm cache | ||
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2 | ||
with: | ||
path: ${{ steps.pnpm-config.outputs.STORE_PATH }} | ||
key: ${{ runner.os }}-pnpm-store-cache-${{ steps.cache-rotation.outputs.YEAR_MONTH }}-${{ hashFiles('**/pnpm-lock.yaml') }} | ||
restore-keys: | | ||
${{ runner.os }}-pnpm-store-cache-${{ steps.cache-rotation.outputs.YEAR_MONTH }}- | ||
- name: Bootstrap monorepo | ||
env: | ||
HUSKY: '0' | ||
run: | | ||
# Use the bootstrap script to install dependencies and build packages | ||
pnpm bootstrap | ||
shell: 'bash -Eeuo pipefail {0}' |
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 |
---|---|---|
@@ -1,35 +1,19 @@ | ||
--- | ||
name: Prepare Job | ||
description: Prepare the job by installing required tools and dependencies | ||
|
||
runs: | ||
using: 'composite' | ||
steps: | ||
- name: Enable Corepack | ||
run: corepack enable | ||
shell: 'bash -Eeuo pipefail {0}' | ||
|
||
- id: setup-node | ||
name: Setup Node.js | ||
uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b # v4.0.3 | ||
with: | ||
cache: 'pnpm' | ||
node-version-file: '.node-version' | ||
|
||
- id: cache-node-modules | ||
name: Cache node_modules | ||
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2 | ||
- uses: pnpm/action-setup@fe02b34f77f8bc703788d5817da081398fad5dd2 | ||
with: | ||
key: node-${{ steps.setup-node.outputs.node-version }}-modules-${{ runner.os }}-${{ hashFiles('pnpm-lock.yaml') }} | ||
path: '**/node_modules' | ||
restore-keys: node-${{ steps.setup-node.outputs.node-version }}-modules-${{ runner.os }}- | ||
|
||
- if: steps.cache-node-modules.outputs.cache-hit != 'true' || steps.setup-node.outputs.cache-hit != 'true' | ||
env: | ||
HUSKY: '0' | ||
name: Install dependencies | ||
run: pnpm install | ||
shell: 'bash -Eeuo pipefail {0}' | ||
run_install: false | ||
|
||
- name: Build packages | ||
run: pnpm run build | ||
shell: 'bash -Eeuo pipefail {0}' | ||
- name: Install dependencies and build packages | ||
uses: ./.github/actions/pnpm-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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
--- | ||
# https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#force-deleting-cache-entries | ||
name: Cache Cleanup | ||
|
||
'on': | ||
pull_request: | ||
types: [closed] | ||
schedule: | ||
- cron: '0 0 * * *' | ||
workflow_dispatch: | ||
|
||
jobs: | ||
cleanup: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Check out code | ||
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 | ||
|
||
- id: cache-info | ||
name: Get branch name and cache keys | ||
env: | ||
BRANCH: >- | ||
${{ | ||
github.event_name == 'pull_request' && github.event.pull_request.merged && format('refs/pull/{0}/merge', github.event.pull_request.number) | ||
|| github.event_name != 'pull_request' && github.ref | ||
|| '' | ||
}} | ||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
gh extension install actions/gh-actions-cache | ||
echo "branch=$BRANCH" >> $GITHUB_OUTPUT | ||
if [ -n "$BRANCH" ]; then | ||
# Get cache keys that don't include the branch's SHA (if not a PR) | ||
gh actions-cache list -R ${{ github.repository }} -B $BRANCH --order asc --sort last-use | cut -f 1 > cache-keys.txt | ||
[ -z "${{ github.event.pull_request }}" ] && grep -v ${{ github.sha }} cache-keys.txt > cache-keys.txt.tmp && mv cache-keys.txt.tmp cache-keys.txt | ||
echo cache-keys="$(cat cache-keys.txt | tr '\n' ' ')" >> $GITHUB_OUTPUT | ||
fi | ||
- env: | ||
CACHE_KEYS: ${{ steps.cache-info.outputs.cache-keys }} | ||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
if: ${{ steps.cache-info.outputs.branch != '' }} | ||
name: Delete stale cache entries from ${{ steps.cache-info.outputs.branch }} | ||
run: | | ||
set +e | ||
for key in $CACHE_KEYS; do | ||
gh actions-cache delete $key -R ${{ github.repository }} -B ${{ steps.cache-info.outputs.branch }} --confirm | ||
done |
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
auto-install-peers = false | ||
resolution-mode = time-based | ||
save-prefix = | ||
save-prefix = '' | ||
shamefully-hoist = true | ||
shell-emulator = true | ||
strict-peer-dependencies = true |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.