Skip to content

Commit

Permalink
ci(pnpm-install): refactor and fix the cache (#405)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcusrbrown committed Sep 25, 2024
1 parent 71cebf2 commit 6306115
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 33 deletions.
37 changes: 25 additions & 12 deletions .github/actions/pnpm-install/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,38 @@ 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}'
- name: Setup pnpm
uses: pnpm/action-setup@ac5bf11548bf5e19b8aadb8182072616590fa4a6
with:
run_install: false

- name: Setup Node.js
uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b # v4.0.3
with:
node-version-file: '.node-version'

- id: cache-rotation
name: Cache rotation keys
- id: cache-config
name: Configure cache
run: |
echo "YEAR_MONTH=$(/bin/date -u "+%Y%m")" >> $GITHUB_OUTPUT
pnpm_store_path="$(pnpm store path --silent)"
if [ -z "pnpm_store_path" ]; then
echo "Failed to get pnpm store path"
exit 1
fi
mkdir -p "pnpm_store_path" || exit 1
echo "path=$pnpm_store_path" >> $GITHUB_OUTPUT
year_month=$(date -u '+%Y%m')
base_key="${{ runner.os }}-pnpm-cache-v${year_month}"
echo "key=${base_key}-${{ hashFiles('**/pnpm-lock.yaml') }}" >> $GITHUB_OUTPUT
echo "restore-keys=${base_key}-" >> $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 }}-
key: ${{ steps.cache-config.outputs.key }}
path: ${{ steps.cache-config.outputs.path }}
restore-keys: ${{ steps.cache-config.outputs.restore-keys }}

- name: Bootstrap monorepo
env:
Expand Down
19 changes: 0 additions & 19 deletions .github/actions/prepare/action.yaml

This file was deleted.

4 changes: 2 additions & 2 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7

- name: Prepare job
uses: ./.github/actions/prepare
uses: ./.github/actions/pnpm-install

- name: Check formatting
run: pnpm run check-format
Expand Down Expand Up @@ -70,7 +70,7 @@ jobs:
token: ${{ steps.get-workflow-access-token.outputs.token }}

- name: Prepare job
uses: ./.github/actions/prepare
uses: ./.github/actions/pnpm-install

- name: Perform a dry run of `pnpm publish`
run: pnpm -r publish --dry-run
Expand Down

0 comments on commit 6306115

Please sign in to comment.