-
Notifications
You must be signed in to change notification settings - Fork 233
63 lines (56 loc) · 1.9 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
63
name: Test, Lint, Release and Publish
on:
push:
branches:
- main
jobs:
main:
name: Release and publish Node package
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Install and test
uses: actions/setup-node@v3
with:
node-version: 16.x
registry-url: 'https://registry.npmjs.org'
- run: npm install
- run: npm run build
- run: npm run lint
- run: npm test
- name: Extract version
id: extract_version
uses: Saionaro/extract-package-version@v1.2.1
- name: Get latest tag
id: get_latest_tag
uses: actions-ecosystem/action-get-latest-tag@v1
with:
initial_version: 'v${{ steps.extract_version.outputs.version }}'
- name: See if version changed
run: |
if [[ "v${{ steps.extract_version.outputs.version }}" == "${{ steps.get_latest_tag.outputs.tag }}" ]]; then
echo "VERSION_CHANGED=false" >> "$GITHUB_ENV"
else
echo "VERSION_CHANGED=true" >> "$GITHUB_ENV"
fi
- name: Create tag
uses: rickstaa/action-create-tag@v1
if: env.VERSION_CHANGED == 'true'
with:
tag: "v${{ steps.extract_version.outputs.version }}"
- name: Create release
if: env.VERSION_CHANGED == 'true'
uses: softprops/action-gh-release@v1
with:
tag_name: 'v${{ steps.extract_version.outputs.version }}'
generate_release_notes: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Publish new version
if: env.VERSION_CHANGED == 'true'
# Note: Setting NODE_AUTH_TOKEN as job|workspace wide env var won't work
# as it appears actions/setup-node sets own value
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: npm publish --verbose