ci: simplify (#883)

This commit is contained in:
Michael Kriese 2024-11-08 14:06:34 +01:00 committed by GitHub
parent 4c22a107ea
commit a0608873fb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 90 additions and 44 deletions

60
.github/actions/setup-node/action.yml vendored Normal file
View file

@ -0,0 +1,60 @@
name: 'Setup Node.js'
description: 'Setup Node and install dependencies using cache'
inputs:
save-cache:
description: 'Save cache when needed'
required: false
default: 'false'
runs:
using: 'composite'
steps:
- name: ⚙️ Calculate `CACHE_KEY`
shell: bash
run: |
echo 'CACHE_KEY=node_modules-${{
hashFiles('.node-version', 'pnpm-lock.yaml')
}}' >> "$GITHUB_ENV"
- name: ♻️ Restore `node_modules`
uses: actions/cache/restore@6849a6489940f00c2f30c0fb92c6274307ccb58a # v4.1.2
id: node-modules-restore
with:
path: node_modules
key: ${{ env.CACHE_KEY }}
enableCrossOsArchive: true
- name: Calculate `CACHE_HIT`
shell: bash
run: |
echo 'CACHE_HIT=${{
(steps.node-modules-restore.outputs.cache-hit == 'true') && 'true' || ''
}}' >> "$GITHUB_ENV"
- name: ⚙️ Setup pnpm
uses: pnpm/action-setup@fe02b34f77f8bc703788d5817da081398fad5dd2 # v4.0.0
with:
standalone: true
- name: ⚙️ Setup Node.js ${{ inputs.node-version }}
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
with:
node-version-file: .node-version
cache: ${{ env.CACHE_HIT != 'true' && 'pnpm' || '' }}
- name: 📥 Install dependencies
if: env.CACHE_HIT != 'true'
shell: bash
run: pnpm install --frozen-lockfile
env:
# Other environment variables
HUSKY: '0' # By default do not run HUSKY install
- name: ♻️ Write `node_modules` cache
if: inputs.save-cache == 'true' && env.CACHE_HIT != 'true'
uses: actions/cache/save@6849a6489940f00c2f30c0fb92c6274307ccb58a # v4.1.2
with:
path: node_modules
key: ${{ env.CACHE_KEY }}
enableCrossOsArchive: true