|
| 1 | +name: 'Setup PNPM' |
| 2 | +description: 'Set up Node.js, PNPM, and configure caching for faster builds' |
| 3 | + |
| 4 | +inputs: |
| 5 | + node-version: |
| 6 | + description: 'Node.js version to use' |
| 7 | + required: false |
| 8 | + default: '22' |
| 9 | + pnpm-version: |
| 10 | + description: 'PNPM version to use' |
| 11 | + required: false |
| 12 | + default: '^10.16.0' |
| 13 | + install-deps: |
| 14 | + description: 'Whether to install dependencies' |
| 15 | + required: false |
| 16 | + default: 'true' |
| 17 | + socket-scan: |
| 18 | + description: 'Whether to run Socket security scan during install' |
| 19 | + required: false |
| 20 | + default: 'true' |
| 21 | + |
| 22 | +runs: |
| 23 | + using: 'composite' |
| 24 | + steps: |
| 25 | + - name: Setup Node.js |
| 26 | + uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.0 |
| 27 | + with: |
| 28 | + node-version: ${{ inputs.node-version }} |
| 29 | + |
| 30 | + - name: Setup PNPM |
| 31 | + uses: pnpm/action-setup@fe02b34f77f8bc703788d5817da081398fad5dd2 # v4.0.0 |
| 32 | + with: |
| 33 | + version: ${{ inputs.pnpm-version }} |
| 34 | + |
| 35 | + - name: Get pnpm store directory |
| 36 | + id: pnpm-cache |
| 37 | + shell: bash |
| 38 | + run: echo "store-path=$(pnpm store path)" >> $GITHUB_OUTPUT |
| 39 | + |
| 40 | + - name: Generate cache prefix |
| 41 | + id: pnpm-timed-expiration |
| 42 | + shell: bash |
| 43 | + # Change cache prefix every 120 days. |
| 44 | + run: echo "prefix=$(( $(date +%s) / 60 / 60 / 24 / 120 ))" >> $GITHUB_OUTPUT |
| 45 | + |
| 46 | + - name: Cache pnpm |
| 47 | + uses: actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4 |
| 48 | + with: |
| 49 | + path: ${{ steps.pnpm-cache.outputs.store-path }} |
| 50 | + # Cache key based on pnpm-lock.yaml hash and timed prefix. |
| 51 | + key: ${{ runner.os }}-pnpm-store-${{ steps.pnpm-timed-expiration.outputs.prefix }}-${{ hashFiles('pnpm-lock.yaml') }} |
| 52 | + restore-keys: | |
| 53 | + ${{ runner.os }}-pnpm-store-${{ steps.pnpm-timed-expiration.outputs.prefix }}- |
| 54 | +
|
| 55 | + - name: Socket security scan |
| 56 | + if: ${{ inputs.install-deps == 'true' && inputs.socket-scan == 'true' }} |
| 57 | + shell: bash |
| 58 | + run: pnpm dlx @socketsecurity/cli --config '{"settings":{"reportLevel":"error"}}' npm install --no-audit --no-fund --package-lock-only |
| 59 | + |
| 60 | + - name: Install dependencies with pnpm |
| 61 | + if: ${{ inputs.install-deps == 'true' && inputs.socket-scan == 'true' }} |
| 62 | + shell: bash |
| 63 | + run: | |
| 64 | + rm -f package-lock.json |
| 65 | + pnpm install |
| 66 | +
|
| 67 | + - name: Install dependencies |
| 68 | + if: ${{ inputs.install-deps == 'true' && inputs.socket-scan == 'false' }} |
| 69 | + shell: bash |
| 70 | + run: pnpm install |
0 commit comments