forked from miraclx/xbytes
-
Notifications
You must be signed in to change notification settings - Fork 0
43 lines (38 loc) · 1.32 KB
/
version-check-for-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
name: version-check-for-npm
env:
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
on:
pull_request:
branches:
- release
jobs:
version-check-for-npm:
timeout-minutes: 30
runs-on: ubuntu-latest
if: "! contains(toJSON(github.event.commits.*.message), '[skip ci]')"
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup node
uses: actions/setup-node@v2
with:
node-version: '16'
- name: Extract current version
id: get_version
run: |
PACKAGE_NAME=$(node -p -e "require('./package.json').name")
echo "PACKAGE_NAME=${PACKAGE_NAME}" >> $GITHUB_ENV
CURRENT_VERSION=$(node -p -e "require('./package.json').version")
echo "CURRENT_VERSION=${CURRENT_VERSION}" >> $GITHUB_ENV
- name: Publish to NPM
run: |
LATEST_VERSION=$(npm show $PACKAGE_NAME version)
# https://www.npmjs.com/package/compare-versions-cli
npm install -g compare-versions-cli
COMPARE=$(compare-versions-cli $CURRENT_VERSION $LATEST_VERSION)
if [ $COMPARE -le 0 ]
then
echo "CURRENT_VERSION($CURRENT_VERSION) must greater than LATEST_VERSION($LATEST_VERSION)"
echo "npm: https://www.npmjs.com/package/$PACKAGE_NAME"
exit 1
fi