-
Notifications
You must be signed in to change notification settings - Fork 13
105 lines (89 loc) · 2.76 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
name: publish
on:
# push:
# branches:
# - master
pull_request:
branches:
- master
types: [closed]
env:
CI: true
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
jobs:
publish:
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Pull Request Merged
if: github.event.pull_request.merged == false
run: |
echo 'The pull request has not been merged'
exit 1
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Set git config
run: |
git config user.name github-actions
git config user.email [email protected]
- name: Use Node.js
uses: actions/setup-node@v2
with:
node-version: 16.x
registry-url: "https://registry.npmjs.org"
- name: Setup .npmrc
shell: bash
run: |
npm set //registry.npmjs.org/:_authToken=$NODE_AUTH_TOKEN
env:
NODE_AUTH_TOKEN: ${{ secrets.NODE_AUTH_TOKEN }}
- name: Ensure access
shell: bash
run: npm whoami --registry https://registry.npmjs.org/
env:
NODE_AUTH_TOKEN: ${{ secrets.NODE_AUTH_TOKEN }}
- name: Install global dependencies
run: npm i yarn standard-version -g
- name: Install dependencies
run: yarn
- name: Get Prev Version
shell: bash -ex {0}
run: |
PREV_VERSION=$(node -p 'require("./package.json").version')
echo "::set-env name=PREV_VERSION::${PREV_VERSION}"
- name: Bump version
run: |
standard-version
- name: Get Current Version
shell: bash -ex {0}
run: |
CURRENT_VERSION=$(node -p 'require("./package.json").version')
echo "::set-env name=CURRENT_VERSION::${CURRENT_VERSION}"
- name: Publish
if: env.PREV_VERSION != env.CURRENT_VERSION
run: |
npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NODE_AUTH_TOKEN }}
- name: Push changes
uses: ad-m/[email protected]
if: env.PREV_VERSION != env.CURRENT_VERSION
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ github.ref }}
tags: true
- name: Create comment
uses: actions/[email protected]
if: env.PREV_VERSION != env.CURRENT_VERSION
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
github.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: 'NPM package v${{ env.CURRENT_VERSION }} has been published 🎉'
})