-
Notifications
You must be signed in to change notification settings - Fork 4
65 lines (51 loc) · 1.48 KB
/
nodejs-package.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
name: Node.js Package
on:
push:
tags:
- '*' # Trigger when any tag is pushed
jobs:
build:
name: Build and Test
runs-on: ubuntu-latest
steps:
# Step 1: Check out the code
- uses: actions/checkout@v3
# Step 2: Set up Node.js
- uses: actions/setup-node@v3
with:
node-version: '20'
# Step 3: Cache npm dependencies
- name: Cache npm dependencies
uses: actions/cache@v3
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
# Step 4: Install dependencies
- run: npm install
# Step 5: Run build script
- run: npm run build
# Step 6: Run tests
- run: npm run test
publish-npm:
name: Publish to npm
needs: build
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/') # Ensure only runs on tag push
steps:
# Step 1: Check out the code
- uses: actions/checkout@v3
# Step 2: Set up Node.js and npm registry
- uses: actions/setup-node@v3
with:
node-version: '20'
registry-url: 'https://registry.npmjs.org/'
# Step 3: Install dependencies
- run: npm install
# Step 4: Run build script (ensures built files are up-to-date)
- run: npm run build
# Step 5: Publish to npm
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}