-
Notifications
You must be signed in to change notification settings - Fork 0
47 lines (45 loc) · 1.39 KB
/
publish-package-npm.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
name: Publish to NPM Packages
on:
push:
paths: 'package.json'
jobs:
publish-npm:
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2
submodules: true
- name: Configure Git
run: |
git config --global user.email "[email protected]"
git config --global user.name "xiangnanscu"
- uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
registry-url: https://registry.npmjs.org/
- name: Install jq
run: sudo apt-get install jq
- name: Check if version changed
id: version_changed
run: |
VERSION_OLD=$(git show ${{ github.event.before }}:package.json | jq -r .version)
VERSION_NEW=$(jq -r .version package.json)
if [ "$VERSION_OLD" != "$VERSION_NEW" ]; then
echo "Version changed from $VERSION_OLD to $VERSION_NEW"
echo "changed=true" >> $GITHUB_OUTPUT
else
echo "Version did not change"
echo "changed=false" >> $GITHUB_OUTPUT
fi
- name: Publish to npm
if: steps.version_changed.outputs.changed == 'true'
run: |
corepack enable
npm i
npm publish --access public
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_PUBLISH_TOKEN}}