Skip to content

Commit 6e88e40

Browse files
committed
Add back reusable action
1 parent 0a1807d commit 6e88e40

3 files changed

Lines changed: 78 additions & 69 deletions

File tree

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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

.github/workflows/socket-fix.yml

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -27,39 +27,13 @@ jobs:
2727
- name: Checkout repo
2828
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
2929

30-
- name: Setup Node.js
31-
uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.0
30+
- name: Setup pnpm
31+
uses: ./.github/actions/setup-pnpm
3232
with:
3333
node-version: '22'
34-
35-
- name: Setup PNPM
36-
uses: pnpm/action-setup@fe02b34f77f8bc703788d5817da081398fad5dd2 # v4.0.0
37-
with:
38-
version: '^10.16.0'
39-
40-
- name: Get pnpm store directory
41-
id: pnpm-cache
42-
shell: bash
43-
run: echo "store-path=$(pnpm store path)" >> $GITHUB_OUTPUT
44-
45-
- name: Generate cache prefix
46-
id: pnpm-timed-expiration
47-
shell: bash
48-
# Change cache prefix every 120 days.
49-
run: echo "prefix=$(( $(date +%s) / 60 / 60 / 24 / 120 ))" >> $GITHUB_OUTPUT
50-
51-
- name: Cache pnpm
52-
uses: actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4
53-
with:
54-
path: ${{ steps.pnpm-cache.outputs.store-path }}
55-
# Cache key based on pnpm-lock.yaml hash and timed prefix.
56-
key: ${{ runner.os }}-pnpm-store-${{ steps.pnpm-timed-expiration.outputs.prefix }}-${{ hashFiles('pnpm-lock.yaml') }}
57-
restore-keys: |
58-
${{ runner.os }}-pnpm-store-${{ steps.pnpm-timed-expiration.outputs.prefix }}-
59-
60-
- name: Install dependencies
61-
shell: bash
62-
run: pnpm install
34+
pnpm-version: '^10.16.0'
35+
install-deps: 'true'
36+
socket-scan: 'false'
6337

6438
- name: Run Socket Fix CLI
6539
env:

.github/workflows/test.yml

Lines changed: 3 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -28,46 +28,11 @@ jobs:
2828
os: [ubuntu-latest, windows-latest]
2929
steps:
3030
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
31-
32-
- name: Setup Node.js
33-
uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.0
34-
with:
35-
node-version: ${{ matrix.node-version }}
36-
3731
- name: Setup PNPM
38-
uses: pnpm/action-setup@fe02b34f77f8bc703788d5817da081398fad5dd2 # v4.0.0
32+
uses: ./.github/actions/setup-pnpm
3933
with:
40-
version: '^10.16.0'
41-
42-
- name: Get pnpm store directory
43-
id: pnpm-cache
44-
shell: bash
45-
run: echo "store-path=$(pnpm store path)" >> $GITHUB_OUTPUT
46-
47-
- name: Generate cache prefix
48-
id: pnpm-timed-expiration
49-
shell: bash
50-
# Change cache prefix every 120 days.
51-
run: echo "prefix=$(( $(date +%s) / 60 / 60 / 24 / 120 ))" >> $GITHUB_OUTPUT
52-
53-
- name: Cache pnpm
54-
uses: actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4
55-
with:
56-
path: ${{ steps.pnpm-cache.outputs.store-path }}
57-
# Cache key based on pnpm-lock.yaml hash and timed prefix.
58-
key: ${{ runner.os }}-pnpm-store-${{ steps.pnpm-timed-expiration.outputs.prefix }}-${{ hashFiles('pnpm-lock.yaml') }}
59-
restore-keys: |
60-
${{ runner.os }}-pnpm-store-${{ steps.pnpm-timed-expiration.outputs.prefix }}-
61-
62-
- name: Socket security scan
63-
shell: bash
64-
run: pnpm dlx @socketsecurity/cli --config '{"settings":{"reportLevel":"error"}}' npm install --no-audit --no-fund --package-lock-only
65-
66-
- name: Install dependencies with pnpm
67-
shell: bash
68-
run: |
69-
rm -f package-lock.json
70-
pnpm install
34+
node-version: ${{ matrix.node-version }}
35+
pnpm-version: '^10.16.0'
7136

7237
- name: Run tests
7338
run: pnpm run test-ci

0 commit comments

Comments
 (0)