Skip to content

Commit d305d73

Browse files
committed
feat: Add CI/CD workflow for tags and releases
1 parent b61fecc commit d305d73

1 file changed

Lines changed: 82 additions & 0 deletions

File tree

.github/workflows/ci-release.yml

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
name: CI/CD Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*.*.*' # Trigger on tags like v1.0.0, v0.0.1, etc.
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout repository
13+
uses: actions/checkout@v3
14+
15+
- name: Setup Node.js
16+
uses: actions/setup-node@v3
17+
with:
18+
node-version: '22' # Align with project's Node.js version
19+
cache: 'npm' # Cache npm dependencies
20+
21+
- name: Install dependencies
22+
run: npm install
23+
24+
- name: Build project
25+
run: npm run build
26+
27+
- name: Upload build artifact
28+
uses: actions/upload-artifact@v3
29+
with:
30+
name: dist-build
31+
path: dist/
32+
33+
test:
34+
runs-on: ubuntu-latest
35+
needs: build # This job depends on the build job
36+
steps:
37+
- name: Checkout repository
38+
uses: actions/checkout@v3
39+
40+
- name: Setup Node.js
41+
uses: actions/setup-node@v3
42+
with:
43+
node-version: '22'
44+
cache: 'npm'
45+
46+
- name: Install dependencies
47+
run: npm install
48+
49+
- name: Run tests
50+
run: node tests/run-cli.js # Use the custom test runner
51+
52+
publish:
53+
runs-on: ubuntu-latest
54+
needs: test # This job depends on the test job
55+
permissions:
56+
contents: write # Required to create a GitHub release
57+
packages: write # Required to publish to GitHub Packages (if used)
58+
id-token: write # Required for OIDC authentication with npm (if used)
59+
steps:
60+
- name: Checkout repository
61+
uses: actions/checkout@v3
62+
63+
- name: Setup Node.js
64+
uses: actions/setup-node@v3
65+
with:
66+
node-version: '22'
67+
cache: 'npm'
68+
registry-url: 'https://registry.npmjs.org/' # Specify npm registry
69+
70+
- name: Install dependencies
71+
run: npm install
72+
73+
- name: Download build artifact
74+
uses: actions/download-artifact@v3
75+
with:
76+
name: dist-build
77+
path: dist/
78+
79+
- name: Publish to npm
80+
run: npm publish --access public
81+
env:
82+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} # npm token for authentication

0 commit comments

Comments
 (0)