-
Notifications
You must be signed in to change notification settings - Fork 0
119 lines (104 loc) · 4.12 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# Publish a new release of this package to NPM
name: Publish
on:
workflow_dispatch:
inputs:
release-type:
description: 'Release type'
required: true
type: choice
# The first option provided is the default selection, make this "please select" to ensure user has to explicitly choose a release type.
options:
- please select
- patch
- minor
- major
- prepatch
- preminor
- premajor
- prerelease
jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Validate selected release type - "${{ github.event.inputs.release-type }}"
if: contains(fromJSON('["patch","minor","major","prepatch","preminor","premajor","prerelease"]'), github.event.inputs.release-type) == false
uses: actions/github-script@v6
with:
script: core.setFailed('Please choose a valid Release Type!')
- name: Harden Runner
uses: step-security/harden-runner@18bf8ad2ca49c14cbb28b91346d626ccfb00c518 # v2.1.0
with:
disable-sudo: true
egress-policy: block
disable-telemetry: true
allowed-endpoints: >
github.com:443
registry.npmjs.org:443
api.github.com:443
- name: Checkout project
uses: actions/checkout@v3
with:
# using custom token to bypass branch protections and push directly to main.
token: ${{ secrets.WORKFLOW_GITHUB_PAT }}
- name: Configure Git User
run: |
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 18
cache: 'npm'
registry-url: 'https://registry.npmjs.org'
- name: Run Tests
run: |
npm ci
npm test
- name: npm version (@latest)
if: startsWith(github.event.inputs.release-type, 'pre') != true
run: |
echo "NEW_VERSION=$(npm --no-git-tag-version version $RELEASE_TYPE)" >> $GITHUB_ENV
echo "NPM_DIST_TAG=latest" >> $GITHUB_ENV
env:
RELEASE_TYPE: ${{ github.event.inputs.release-type }}
- name: npm version (@prerelease)
if: startsWith(github.event.inputs.release-type, 'pre')
run: |
echo $RELEASE_TYPE
echo "NEW_VERSION=$(npm --no-git-tag-version --preid=beta version $RELEASE_TYPE)" >> $GITHUB_ENV
echo "NPM_DIST_TAG=beta" >> $GITHUB_ENV
env:
RELEASE_TYPE: ${{ github.event.inputs.release-type }}
- name: Update CHANGELOG
uses: superfaceai/release-changelog-action@b1411d74107d4691016c93940673c67535a927aa # v2.0.0
with:
path-to-changelog: CHANGELOG.md
version: ${{ env.NEW_VERSION }}
operation: release
- name: Commit changes & tag
run: |
git add "package.json"
git add "package-lock.json"
git add "CHANGELOG.md"
git commit -m "chore: release ${{ env.NEW_VERSION }}"
git tag ${{ env.NEW_VERSION }}
- name: Publish to npm
run: npm publish --tag ${{ env.NPM_DIST_TAG }}
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
- name: Push changes & tags
run: git push --atomic origin main ${{ env.NEW_VERSION }}
- name: Get changes for Release
id: get-changelog
uses: superfaceai/release-changelog-action@b1411d74107d4691016c93940673c67535a927aa # v2.0.0
with:
path-to-changelog: CHANGELOG.md
version: ${{ env.NEW_VERSION }}
operation: read
- name: Create Github Release
uses: softprops/action-gh-release@de2c0eb89ae2a093876385947365aca7b0e5f844 # v0.1.15
with:
tag_name: ${{ env.NEW_VERSION }}
prerelease: ${{ startsWith(github.event.inputs.release-type, 'pre') }}
body: ${{ steps.get-changelog.outputs.changelog }}