-
Notifications
You must be signed in to change notification settings - Fork 26
58 lines (48 loc) · 1.59 KB
/
publish.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
name: Publish
on:
push:
branches:
- main
jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
registry-url: 'https://registry.npmjs.org'
- name: Check if version has changed
id: version_check
run: |
# Get the current version from package.json
current_version=$(jq -r '.version' package.json)
echo "Current version: $current_version"
# Get the previous version from the last commit
git fetch --depth=2
previous_version=$(git show HEAD^1:package.json | jq -r '.version')
echo "Previous version: $previous_version"
if [ "$current_version" != "$previous_version" ]; then
echo "::set-output name=version_changed::true"
echo "::set-output name=current_version::$current_version"
else
echo "::set-output name=version_changed::false"
fi
- name: Publish to NPM
if: steps.version_check.outputs.version_changed == 'true'
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_CI_TOKEN }}
run: npm publish
- name: Create GitHub Release
if: steps.version_check.outputs.version_changed == 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
current_version=${{ steps.version_check.outputs.current_version }}
gh release create "v$current_version" \
--title "Release v$current_version" \
--generate-notes