renovate/.github/actions/setup-node/action.yml

110 lines
3.2 KiB
YAML

# This is the composite action:
# https://docs.github.com/en/actions/creating-actions/creating-a-composite-action
#
# Composite actions have some limitations:
# - many contexts are unavailable, e.g. `runner`
# - `env` can be specified per-step only
# - if `run` is used, `shell` must be explicitly specified
name: 'Setup Node and install dependencies'
description: 'Setup Node and install dependencies using cache'
inputs:
node-version:
description: 'Node version'
required: true
os:
description: 'Composite actions do not support `runner.os`, so it must be passed in as an input'
required: true
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-${{
inputs.os
}}-${{
inputs.node-version
}}-${{
hashFiles('pnpm-lock.yaml', 'package.json')
}}' >> "$GITHUB_ENV"
- name: Restore `node_modules`
id: node-modules-restore
uses: actions/cache/restore@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4.2.0
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
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
with:
node-version: ${{ inputs.node-version }}
- name: Calculate `PNPM_STORE`
shell: bash
run: |
echo "PNPM_STORE=$(pnpm store path)" >> "$GITHUB_ENV"
- name: Cache and restore `pnpm store`
if: env.CACHE_HIT != 'true'
uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4.2.0
with:
path: ${{ env.PNPM_STORE }}
key: |
pnpm_store-${{
inputs.os
}}-${{
inputs.node-version
}}-${{
hashFiles('pnpm-lock.yaml', 'package.json')
}}
enableCrossOsArchive: true
- name: Install dependencies
uses: nick-fields/retry@7152eba30c6575329ac0576536151aca5a72780e # v3.0.0
if: env.CACHE_HIT != 'true'
with:
timeout_minutes: 10
max_attempts: 3
command: pnpm install --frozen-lockfile
- name: Write `node_modules` cache
if: inputs.save-cache == 'true' && env.CACHE_HIT != 'true'
uses: actions/cache/save@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4.2.0
with:
path: node_modules
key: ${{ env.CACHE_KEY }}
enableCrossOsArchive: true
- name: Generate files
shell: bash
run: >
if [[ -d lib ]]; then
pnpm prepare:generate;
fi
- name: Git config
shell: bash
run: |
git config --global core.autocrlf false
git config --global core.symlinks true
git config --global user.email 'renovate@whitesourcesoftware.com'
git config --global user.name 'Renovate Bot'