-
Notifications
You must be signed in to change notification settings - Fork 1
77 lines (67 loc) · 2.05 KB
/
v3-publish-to-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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
name: Push to NPM
on:
workflow_call:
inputs:
NODE_VERSION:
required: false
type: string
default: 12
secrets:
NPM_TOKEN_WRITE:
required: true
# Ensure only a single instance of this workflow is running.
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
build-and-publish-to-npm:
environment: master
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: ${{ inputs.NODE_VERSION }}
registry-url: https://registry.npmjs.org
cache: 'npm'
- name: Install
run: |
git config --global url."https://github.com/".insteadOf ssh://[email protected]/
git config --global url."https://".insteadOf git://
npm ci
- name: Build
run: npm run build
- name: Get Version and Name
run: |
VERSION=$(cat package.json | jq -r '.version')
NAME=$(cat package.json | jq -r '.name')
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "NAME=$NAME" >> $GITHUB_ENV
- name: Check If Already Published
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN_WRITE }}
VERSION: ${{ env.VERSION }}
NAME: ${{ env.NAME }}
run: |
if exists=$(test -n "$(npm info $NAME@$VERSION)"); then
echo "PACKAGE_EXISTS=true" >> $GITHUB_ENV
fi
- name: Version & Tag
if: ${{ !env.PACKAGE_EXISTS }}
env:
VERSION: ${{ env.VERSION }}
run: |
git config --global user.name "github_actions"
git config --global user.email "[email protected]"
git tag v${VERSION} ${{ github.sha }}
git push origin v${VERSION}
- name: Publish to npm
id: publish-npm
if: ${{ !env.PACKAGE_EXISTS }}
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN_WRITE }}
run: npm publish