Skip to content

Commit c68013b

Browse files
authored
Merge pull request #6 from BlockheaderWeb3-Community/feature/cicd-pipeline-setup
feat: add CI/CD pipeline for SDK
2 parents bc8d4d7 + 36b3c81 commit c68013b

1 file changed

Lines changed: 87 additions & 0 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
name: CI/CD Pipeline - SDK
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
7+
jobs:
8+
build:
9+
name: Build SDK
10+
runs-on: ubuntu-latest
11+
strategy:
12+
matrix:
13+
package: [lib, demo]
14+
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v4
18+
19+
- name: Setup Node.js
20+
uses: actions/setup-node@v4
21+
with:
22+
node-version: '20'
23+
24+
- name: Install dependencies
25+
working-directory: ./${{ matrix.package }}
26+
run: npm install
27+
28+
- name: Build
29+
working-directory: ./${{ matrix.package }}
30+
run: npm run build
31+
32+
publish:
33+
name: Publish to NPM
34+
runs-on: ubuntu-latest
35+
needs: build
36+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
37+
38+
steps:
39+
- name: Checkout code
40+
uses: actions/checkout@v4
41+
42+
- name: Setup Node.js
43+
uses: actions/setup-node@v4
44+
with:
45+
node-version: '20'
46+
registry-url: 'https://registry.npmjs.org'
47+
48+
- name: Install dependencies
49+
working-directory: ./lib
50+
run: npm install
51+
52+
- name: Build
53+
working-directory: ./lib
54+
run: npm run build
55+
56+
- name: Check if version changed
57+
id: version_check
58+
working-directory: ./lib
59+
run: |
60+
PACKAGE_VERSION=$(node -p "require('./package.json').version")
61+
PUBLISHED_VERSION=$(npm view $(node -p "require('./package.json').name") version 2>/dev/null || echo "0.0.0")
62+
if [ "$PACKAGE_VERSION" != "$PUBLISHED_VERSION" ]; then
63+
echo "changed=true" >> $GITHUB_OUTPUT
64+
echo "New version detected: $PACKAGE_VERSION (published: $PUBLISHED_VERSION)"
65+
else
66+
echo "changed=false" >> $GITHUB_OUTPUT
67+
echo "Version unchanged: $PACKAGE_VERSION"
68+
fi
69+
70+
- name: Publish to NPM
71+
if: steps.version_check.outputs.changed == 'true'
72+
working-directory: ./lib
73+
run: npm publish --access public
74+
env:
75+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
76+
77+
- name: Create Git Tag
78+
if: steps.version_check.outputs.changed == 'true'
79+
working-directory: ./lib
80+
run: |
81+
PACKAGE_VERSION=$(node -p "require('./package.json').version")
82+
git config user.name github-actions
83+
git config user.email github-actions@github.com
84+
git tag -a "v$PACKAGE_VERSION" -m "Release v$PACKAGE_VERSION"
85+
git push origin "v$PACKAGE_VERSION"
86+
env:
87+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)