-
Notifications
You must be signed in to change notification settings - Fork 0
100 lines (84 loc) · 2.62 KB
/
release.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
name: state
on:
push:
branches:
- main
paths:
- "package.json"
jobs:
check-version:
runs-on: ubuntu-latest
outputs:
version_changed: ${{ steps.check_version.outputs.version_changed }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 2
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
- name: Install jq
run: sudo apt-get install -y jq
- name: Debug current and previous versions
run: |
echo "Current version in package.json: $(jq -r .version < package.json)"
PREV_VERSION=$(git show HEAD~1:package.json | jq -r .version || echo "none")
echo "Previous version in package.json: $PREV_VERSION"
- name: Check version increment
id: check_version
run: |
PREV_VERSION=$(git show HEAD~1:package.json | jq -r .version || echo "none")
CURR_VERSION=$(jq -r .version < package.json)
echo "Previous version: $PREV_VERSION"
echo "Current version: $CURR_VERSION"
if [ "$PREV_VERSION" = "none" ] || [ "$PREV_VERSION" != "$CURR_VERSION" ]; then
echo "version_changed=true" >> $GITHUB_ENV
echo "version_changed=true" >> $GITHUB_OUTPUT
else
echo "version_changed=true" >> $GITHUB_ENV
echo "version_changed=true" >> $GITHUB_OUTPUT
fi
build:
runs-on: ubuntu-latest
needs: check-version
if: needs.check-version.outputs.version_changed == 'true'
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
- name: Install dependencies
run: npm i
- name: Building codebase
run: npm run build
- name: Test codebase
run: npm run test
- name: Upload dist artifacts
uses: actions/upload-artifact@v4
with:
name: dist
path: dist
publish:
needs:
- build
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Download dist artifacts
uses: actions/download-artifact@v4
with:
name: dist
path: dist
- name: Configure npm for publishing
run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc
- name: Publish to NPM
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}