-
Notifications
You must be signed in to change notification settings - Fork 0
53 lines (45 loc) · 1.48 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
name: Build and Publish
on:
push:
branches: [ main ]
jobs:
build-and-publish:
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v4
with:
fetch-depth: 2
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
registry-url: 'https://registry.npmjs.org'
scope: '@marherb-work'
- name: Check package.json version change
id: check_version
run: |
VERSION_IN_GIT=$(git diff HEAD~ -- package.json | grep -oP '(?<="version": ")[^"]*' || :)
if [ -z "$VERSION_IN_GIT" ]; then
echo "Unable to find previous version info or no previous commit."
VERSION_IN_GIT="None"
fi
CURRENT_VERSION=$(node -p "require('./package.json').version")
if [ "$VERSION_IN_GIT" == "$CURRENT_VERSION" ]; then
echo "Version has not changed."
echo "::set-output name=version_changed::false"
else
echo "Version has changed."
echo "::set-output name=version_changed::true"
fi
- name: Install dependencies
if: steps.check_version.outputs.version_changed == 'true'
run: yarn install
- name: Build package
if: steps.check_version.outputs.version_changed == 'true'
run: yarn build
- name: Publish to NPM
if: steps.check_version.outputs.version_changed == 'true'
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}