-
Notifications
You must be signed in to change notification settings - Fork 5
87 lines (73 loc) · 2.46 KB
/
deploy.yml
File metadata and controls
87 lines (73 loc) · 2.46 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
name: CI/CD Pipeline - SDK
on:
push:
branches: [ main ]
jobs:
build:
name: Build SDK
runs-on: ubuntu-latest
strategy:
matrix:
package: [lib, demo]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install dependencies
working-directory: ./${{ matrix.package }}
run: npm install
- name: Build
working-directory: ./${{ matrix.package }}
run: npm run build
publish:
name: Publish to NPM
runs-on: ubuntu-latest
needs: build
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
registry-url: 'https://registry.npmjs.org'
- name: Install dependencies
working-directory: ./lib
run: npm install
- name: Build
working-directory: ./lib
run: npm run build
- name: Check if version changed
id: version_check
working-directory: ./lib
run: |
PACKAGE_VERSION=$(node -p "require('./package.json').version")
PUBLISHED_VERSION=$(npm view $(node -p "require('./package.json').name") version 2>/dev/null || echo "0.0.0")
if [ "$PACKAGE_VERSION" != "$PUBLISHED_VERSION" ]; then
echo "changed=true" >> $GITHUB_OUTPUT
echo "New version detected: $PACKAGE_VERSION (published: $PUBLISHED_VERSION)"
else
echo "changed=false" >> $GITHUB_OUTPUT
echo "Version unchanged: $PACKAGE_VERSION"
fi
- name: Publish to NPM
if: steps.version_check.outputs.changed == 'true'
working-directory: ./lib
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Create Git Tag
if: steps.version_check.outputs.changed == 'true'
working-directory: ./lib
run: |
PACKAGE_VERSION=$(node -p "require('./package.json').version")
git config user.name github-actions
git config user.email github-actions@github.com
git tag -a "v$PACKAGE_VERSION" -m "Release v$PACKAGE_VERSION"
git push origin "v$PACKAGE_VERSION"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}