-
Notifications
You must be signed in to change notification settings - Fork 4
62 lines (52 loc) · 1.74 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
59
60
61
62
name: Publish to npm
on:
push:
branches: main
permissions:
contents: write
jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: "18"
- run: npm ci
- name: Get current npm version
id: current_version
run: |
CURRENT_VERSION=$(node -p 'require(`./package.json`).version')
echo "current_version=${CURRENT_VERSION}" >> $GITHUB_ENV
echo "Current npm version: ${CURRENT_VERSION}"
- name: Get previous npm version
id: previous_version
run: |
PREV_VERSION=$(npm show $(node -p 'require(`./package.json`).name') version)
echo "prev_version=${PREV_VERSION}" >> $GITHUB_ENV
echo "Previous npm version: ${PREV_VERSION}"
- name: Check version change
id: version_check
run: |
if [ "${{ env.current_version }}" != "${{ env.prev_version }}" ]; then
echo "changed=true" >> $GITHUB_ENV
else
echo "changed=false" >> $GITHUB_ENV
fi
echo "Version changed: ${{ env.changed }}"
- name: Publish to npm
if: env.changed == 'true'
uses: JS-DevTools/npm-publish@v3
with:
token: ${{ secrets.NPM_TOKEN }}
- name: Create GitHub Release
if: env.changed == 'true'
uses: actions/create-release@v1
with:
tag_name: v${{ env.current_version }}
release_name: Release v${{ env.current_version }}
body: New release v${{ env.current_version }}
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}