Skip to content

Commit 6cc9ca5

Browse files
CopilotBoshen
andauthored
Add reusable workflow for Node.js and pnpm setup (#31)
* Initial plan * Add reusable Node.js and pnpm setup action Co-authored-by: Boshen <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: Boshen <[email protected]>
1 parent 3f55c69 commit 6cc9ca5

File tree

5 files changed

+134
-52
lines changed

5 files changed

+134
-52
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Setup Node.js and pnpm Action
2+
3+
A reusable composite action that consolidates Node.js and pnpm installation steps for the Vibe Dashboard project.
4+
5+
## Features
6+
7+
- ✅ Sets up Node.js with configurable version (defaults to LTS)
8+
- ✅ Sets up pnpm using the project's configured version
9+
- ✅ Optional pnpm store caching for faster builds
10+
- ✅ Automatic dependency installation with configurable lockfile mode
11+
- ✅ Environment variable handling for GitHub tokens
12+
13+
## Usage
14+
15+
```yaml
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v5
19+
20+
- name: Setup Node.js and pnpm
21+
uses: ./.github/actions/setup-node-pnpm
22+
with:
23+
# Optional inputs
24+
node-version: 'lts/*' # Default: 'lts/*'
25+
enable-cache: true # Default: 'true'
26+
frozen-lockfile: true # Default: 'true'
27+
```
28+
29+
## Inputs
30+
31+
| Input | Description | Required | Default |
32+
|-------|-------------|----------|---------|
33+
| `node-version` | Node.js version to install | No | `'lts/*'` |
34+
| `enable-cache` | Enable pnpm store caching | No | `'true'` |
35+
| `frozen-lockfile` | Use frozen lockfile for pnpm install | No | `'true'` |
36+
37+
## What it does
38+
39+
1. **Setup Node.js**: Installs the specified Node.js version
40+
2. **Setup pnpm**: Installs pnpm using the project's configured version (from `packageManager` field)
41+
3. **Cache pnpm store** (optional): Sets up caching for pnpm store to speed up subsequent runs
42+
4. **Install dependencies**: Runs `pnpm install` with optional `--frozen-lockfile` flag
43+
44+
## Examples
45+
46+
### CI/CD with caching and frozen lockfile
47+
```yaml
48+
- name: Setup Node.js and pnpm
49+
uses: ./.github/actions/setup-node-pnpm
50+
with:
51+
enable-cache: true
52+
frozen-lockfile: true
53+
```
54+
55+
### Deployment without strict lockfile requirements
56+
```yaml
57+
- name: Setup Node.js and pnpm
58+
uses: ./.github/actions/setup-node-pnpm
59+
with:
60+
enable-cache: false
61+
frozen-lockfile: false
62+
```
63+
64+
### Custom Node.js version
65+
```yaml
66+
- name: Setup Node.js and pnpm
67+
uses: ./.github/actions/setup-node-pnpm
68+
with:
69+
node-version: '20'
70+
enable-cache: true
71+
frozen-lockfile: true
72+
```
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: 'Setup Node.js and pnpm'
2+
description: 'Reusable action to setup Node.js and pnpm with caching'
3+
4+
inputs:
5+
node-version:
6+
description: 'Node.js version to install'
7+
required: false
8+
default: 'lts/*'
9+
enable-cache:
10+
description: 'Enable pnpm store caching'
11+
required: false
12+
default: 'true'
13+
frozen-lockfile:
14+
description: 'Use frozen lockfile for pnpm install'
15+
required: false
16+
default: 'true'
17+
18+
runs:
19+
using: 'composite'
20+
steps:
21+
- name: Setup Node.js ${{ inputs.node-version }}
22+
uses: actions/setup-node@v4
23+
with:
24+
node-version: ${{ inputs.node-version }}
25+
env:
26+
GITHUB_TOKEN: ${{ github.token }}
27+
28+
- name: Setup pnpm
29+
uses: pnpm/action-setup@v4
30+
31+
- name: Get pnpm store directory
32+
if: inputs.enable-cache == 'true'
33+
shell: bash
34+
run: |
35+
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
36+
37+
- name: Setup pnpm cache
38+
if: inputs.enable-cache == 'true'
39+
uses: actions/cache@v4
40+
with:
41+
path: ${{ env.STORE_PATH }}
42+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
43+
restore-keys: |
44+
${{ runner.os }}-pnpm-store-
45+
46+
- name: Install dependencies
47+
shell: bash
48+
run: pnpm install${{ inputs.frozen-lockfile == 'true' && ' --frozen-lockfile' || '' }}
49+
env:
50+
GITHUB_TOKEN: ${{ github.token }}

.github/workflows/ci.yml

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -20,33 +20,11 @@ jobs:
2020
- name: Checkout code
2121
uses: actions/checkout@v5
2222

23-
- name: Setup Node.js LTS
24-
uses: actions/setup-node@v4
23+
- name: Setup Node.js and pnpm
24+
uses: ./.github/actions/setup-node-pnpm
2525
with:
26-
node-version: 'lts/*'
27-
env:
28-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
29-
30-
- name: Setup pnpm
31-
uses: pnpm/action-setup@v4
32-
33-
- name: Get pnpm store directory
34-
shell: bash
35-
run: |
36-
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
37-
38-
- name: Setup pnpm cache
39-
uses: actions/cache@v4
40-
with:
41-
path: ${{ env.STORE_PATH }}
42-
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
43-
restore-keys: |
44-
${{ runner.os }}-pnpm-store-
45-
46-
- name: Install dependencies
47-
run: pnpm install --frozen-lockfile
48-
env:
49-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
26+
enable-cache: true
27+
frozen-lockfile: true
5028

5129
- name: Lint code
5230
run: pnpm lint

.github/workflows/copilot-setup-steps.yml

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,11 @@ jobs:
2828
steps:
2929
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
3030

31-
- name: Setup Node.js
32-
uses: actions/setup-node@v4
31+
- name: Setup Node.js and pnpm
32+
uses: ./.github/actions/setup-node-pnpm
3333
with:
34-
node-version: 'lts/*'
35-
env:
36-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
37-
38-
- name: Setup pnpm
39-
uses: pnpm/action-setup@v4
40-
41-
- name: Install dependencies
42-
run: pnpm install
43-
env:
44-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
34+
enable-cache: false
35+
frozen-lockfile: false
4536

4637
- name: Run lint
4738
run: pnpm lint

.github/workflows/deploy.yml

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,11 @@ jobs:
2323
- name: Checkout
2424
uses: actions/checkout@v5
2525

26-
- name: Setup Node.js
27-
uses: actions/setup-node@v4
26+
- name: Setup Node.js and pnpm
27+
uses: ./.github/actions/setup-node-pnpm
2828
with:
29-
node-version: 'lts/*'
30-
env:
31-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
32-
33-
- name: Setup pnpm
34-
uses: pnpm/action-setup@v4
35-
36-
- name: Install dependencies
37-
run: pnpm install
38-
env:
39-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
29+
enable-cache: false
30+
frozen-lockfile: false
4031

4132
- name: Lint
4233
run: pnpm lint

0 commit comments

Comments
 (0)