Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci(v3): improve usage of github actions cache #5563

Merged
merged 4 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions .github/actions/setup-env/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Setup env
description: Sets up node and pnpm

inputs:
pnpm-version:
description: Version of pnpm to install
required: false
default: "9"
node-version:
description: Version of node to install
required: false
default: "18"
cache-save:
description: Whether to save the pnpm cache
required: false
default: "false"
outputs:
cache-hit:
description: Whether the cache was restored
value: ${{ steps.setup-node.outputs.cache-hit || steps.cache-restore.outputs.cache-hit }}

runs:
using: composite
steps:
- uses: pnpm/action-setup@v4
with:
version: ${{ inputs.pnpm-version }}
- uses: actions/setup-node@v4
id: setup-node
with:
node-version: ${{ inputs.node-version }}
cache: ${{ inputs.cache-save == 'true' && 'pnpm' || '' }}
cache-dependency-path: "**/pnpm-lock.yaml"
- id: pnpm
if: inputs.cache-save == 'false'
run: pnpm store path --silent | xargs -I {} -0 echo "path={}" | tee -a $GITHUB_OUTPUT
shell: bash
- uses: actions/cache/restore@v4
id: cache-restore
if: inputs.cache-save == 'false'
with:
path: ${{ steps.pnpm.outputs.path }}
key: node-cache-${{ runner.os }}-pnpm-${{ hashFiles('**/pnpm-lock.yaml') }}
48 changes: 48 additions & 0 deletions .github/workflows/cache.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Cache

on:
push:
branches:
- main
- pre-release-testing-branch
- changeset-release/main
- v-next
paths:
- ".github/workflows/cache.yml"
- "**/pnpm-lock.yaml"
pull_request:
paths:
- ".github/workflows/cache.yml"
- "**/pnpm-lock.yaml"
workflow_dispatch:

concurrency:
group: ${{github.workflow}}-${{github.ref}}
cancel-in-progress: true

defaults:
run:
shell: bash

jobs:
cache:
name: Cache
runs-on: ${{ matrix.runner }}
strategy:
fail-fast: false
matrix:
runner: ["ubuntu-latest", "macos-latest", "windows-latest"]
steps:
- uses: actions/checkout@v4
- id: env
uses: ./.github/actions/setup-env
with:
cache-save: true
- name: Install
if: steps.env.outputs.cache-hit != 'true'
run: |
for lockfile in $(find "$(pwd)" -name pnpm-lock.yaml); do
pushd "$(dirname "$lockfile")"
pnpm install --frozen-lockfile --prefer-offline
popd
done
18 changes: 3 additions & 15 deletions .github/workflows/v-next-changesets-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,9 @@ jobs:
uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: pnpm/action-setup@v4
with:
version: 9
- uses: actions/setup-node@v4
- uses: ./.github/actions/setup-env
with:
node-version: 22
cache: "pnpm"
- name: Install
run: pnpm install --no-frozen-lockfile
- name: Changeset Check
Expand All @@ -48,13 +44,9 @@ jobs:
uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: pnpm/action-setup@v4
with:
version: 9
- uses: actions/setup-node@v4
- uses: ./.github/actions/setup-env
with:
node-version: 22
cache: "pnpm"
- name: Install
run: pnpm install --no-frozen-lockfile
- name: Run full check (build, lint and test)
Expand All @@ -72,13 +64,9 @@ jobs:
uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: pnpm/action-setup@v4
with:
version: 9
- uses: actions/setup-node@v4
- uses: ./.github/actions/setup-env
with:
node-version: 22
cache: "pnpm"
- name: Install
run: pnpm install --no-frozen-lockfile
- name: Apply and commit changesets
Expand Down
14 changes: 2 additions & 12 deletions .github/workflows/v-next-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,9 @@ jobs:

steps:
- uses: actions/checkout@v4
- name: Install pnpm
uses: pnpm/action-setup@v4
with:
version: 9
- uses: actions/setup-node@v4
- uses: ./.github/actions/setup-env
with:
node-version: 22
cache: "pnpm"
- name: Install dependencies
run: pnpm install --frozen-lockfile --prefer-offline
- name: Build
Expand All @@ -102,14 +97,9 @@ jobs:

steps:
- uses: actions/checkout@v4
- name: Install pnpm
uses: pnpm/action-setup@v4
with:
version: 9
- uses: actions/setup-node@v4
- uses: ./.github/actions/setup-env
with:
node-version: ${{ matrix.node }}
cache: "pnpm"
- name: Install dependencies
run: pnpm install --frozen-lockfile --prefer-offline
- name: Build
Expand Down