Skip to content

Commit

Permalink
Merge pull request #5567 from NomicFoundation/galargh/github-actions-…
Browse files Browse the repository at this point in the history
…caching-v2

ci(v2): improve usage of github actions cache
  • Loading branch information
galargh authored Aug 2, 2024
2 parents 6f3b65e + a1c1932 commit 8c779d8
Show file tree
Hide file tree
Showing 29 changed files with 152 additions and 392 deletions.
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') }}
8 changes: 1 addition & 7 deletions .github/workflows/LATEST_DEPENDENCY_VERSIONS.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,7 @@ jobs:
runs-on: ${{ matrix.system }}
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
with:
version: 9
- uses: actions/setup-node@v4
with:
node-version: 18
cache: "pnpm"
- uses: ./.github/actions/setup-env
- name: Delete pnpm-lock.yaml
run: "rm pnpm-lock.yaml"
- name: Install
Expand Down
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
8 changes: 1 addition & 7 deletions .github/workflows/check-docs-site.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
with:
version: 9
- uses: actions/setup-node@v4
with:
node-version: 18
cache: "pnpm"
- uses: ./.github/actions/setup-env
- name: Install
run: pnpm install --frozen-lockfile --prefer-offline
- name: Install Docs
Expand Down
8 changes: 1 addition & 7 deletions .github/workflows/comment-on-linter-error.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,7 @@ jobs:
uses: actions/checkout@v4
with:
ref: "refs/pull/${{ github.event.number }}/merge"
- uses: pnpm/action-setup@v4
with:
version: 9
- uses: actions/setup-node@v4
with:
node-version: 18
cache: "pnpm"
- uses: ./.github/actions/setup-env
- name: Install
run: pnpm install --frozen-lockfile --prefer-offline
- name: Build
Expand Down
7 changes: 1 addition & 6 deletions .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,7 @@ jobs:
IS_WINDOWS: ${{ matrix.os == 'windows-latest' }}
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
with:
version: 9
- uses: actions/setup-node@v4
with:
node-version: 18
- uses: ./.github/actions/setup-env
- name: Run fixture-projects script
run: |
cd e2e
Expand Down
22 changes: 3 additions & 19 deletions .github/workflows/hardhat-chai-matchers-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,7 @@ jobs:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
with:
version: 9
- uses: actions/setup-node@v4
with:
node-version: 18
cache: "pnpm"
- uses: ./.github/actions/setup-env
- name: Install
run: pnpm install --frozen-lockfile --prefer-offline
- name: Build
Expand All @@ -52,13 +46,7 @@ jobs:
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
with:
version: 9
- uses: actions/setup-node@v4
with:
node-version: 18
cache: "pnpm"
- uses: ./.github/actions/setup-env
- name: Install
run: pnpm install --frozen-lockfile --prefer-offline
- name: Build
Expand All @@ -76,13 +64,9 @@ jobs:
node: [18, 20, 22]
steps:
- uses: actions/checkout@v4
- 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
run: pnpm install --frozen-lockfile --prefer-offline
- name: Build
Expand Down
20 changes: 3 additions & 17 deletions .github/workflows/hardhat-core-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,9 @@ jobs:
steps:
- uses: actions/checkout@v4

- uses: pnpm/action-setup@v4
with:
version: 9
- name: Install Node
uses: actions/setup-node@v4
- uses: ./.github/actions/setup-env
with:
node-version: ${{ matrix.node }}
cache: pnpm

- name: Install package
run: pnpm install --frozen-lockfile --prefer-offline
Expand Down Expand Up @@ -81,14 +76,9 @@ jobs:
steps:
- uses: actions/checkout@v4

- uses: pnpm/action-setup@v4
with:
version: 9
- name: Install Node
uses: actions/setup-node@v4
- uses: ./.github/actions/setup-env
with:
node-version: ${{ matrix.node }}
cache: pnpm

- name: Install package
run: pnpm install --frozen-lockfile --prefer-offline
Expand Down Expand Up @@ -121,13 +111,9 @@ jobs:
node: [18, 20]
steps:
- uses: actions/checkout@v4
- 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
run: pnpm install --frozen-lockfile --prefer-offline
- name: Install @types/node
Expand Down
22 changes: 3 additions & 19 deletions .github/workflows/hardhat-ethers-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,7 @@ jobs:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
with:
version: 9
- uses: actions/setup-node@v4
with:
node-version: 18
cache: "pnpm"
- uses: ./.github/actions/setup-env
- name: Install
run: pnpm install --frozen-lockfile --prefer-offline
- name: Build
Expand All @@ -52,13 +46,7 @@ jobs:
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
with:
version: 9
- uses: actions/setup-node@v4
with:
node-version: 18
cache: "pnpm"
- uses: ./.github/actions/setup-env
- name: Install
run: pnpm install --frozen-lockfile --prefer-offline
- name: Build
Expand All @@ -74,13 +62,9 @@ jobs:
node: [18, 20, 22]
steps:
- uses: actions/checkout@v4
- 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
run: pnpm install --frozen-lockfile --prefer-offline
- name: Build
Expand Down
22 changes: 3 additions & 19 deletions .github/workflows/hardhat-foundry-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,7 @@ jobs:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
with:
version: 9
- uses: actions/setup-node@v4
with:
node-version: 18
cache: "pnpm"
- uses: ./.github/actions/setup-env
- name: Install
run: pnpm install --frozen-lockfile --prefer-offline
- name: Build
Expand All @@ -52,13 +46,7 @@ jobs:
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
with:
version: 9
- uses: actions/setup-node@v4
with:
node-version: 18
cache: "pnpm"
- uses: ./.github/actions/setup-env
- name: Install
run: pnpm install --frozen-lockfile --prefer-offline
- name: Build
Expand All @@ -76,13 +64,9 @@ jobs:
node: [18, 20, 22]
steps:
- uses: actions/checkout@v4
- 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
run: pnpm install --frozen-lockfile --prefer-offline
- name: Build
Expand Down
22 changes: 3 additions & 19 deletions .github/workflows/hardhat-ledger-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,7 @@ jobs:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
with:
version: 9
- uses: actions/setup-node@v4
with:
node-version: 18
cache: "pnpm"
- uses: ./.github/actions/setup-env
- name: Install
run: pnpm install --frozen-lockfile --prefer-offline
- name: Build
Expand All @@ -52,13 +46,7 @@ jobs:
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
with:
version: 9
- uses: actions/setup-node@v4
with:
node-version: 18
cache: "pnpm"
- uses: ./.github/actions/setup-env
- name: Install
run: pnpm install --frozen-lockfile --prefer-offline
- name: Build
Expand All @@ -74,13 +62,9 @@ jobs:
node: [18, 20, 22]
steps:
- uses: actions/checkout@v4
- 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
run: pnpm install --frozen-lockfile --prefer-offline
- name: Build
Expand Down
Loading

0 comments on commit 8c779d8

Please sign in to comment.