-
-
Notifications
You must be signed in to change notification settings - Fork 18
60 lines (54 loc) · 2.28 KB
/
node-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
# https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages
# Requires repo secret: NPM_TOKEN ("automation" access token)
name: Node.js Publish
on:
release:
types:
- published
jobs:
node-publish:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: 'npm'
- run: npm ci
- id: publish
name: npm publish
# https://github.com/bitwarden/clients/pull/3272
run: |
echo 'registry="https://registry.npmjs.org/"' > ./.npmrc
echo "//registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN}" >> ./.npmrc
npm publish --regsitry=https://registry.npmjs.org/ --userconfig=./.npmrc --provenance --access public
{
echo "PACKAGE_NAME=$(jq --raw-output '.name' package.json)"
echo "PACKAGE_VERSION=$(jq --raw-output '.version' package.json)"
} >> "${GITHUB_OUTPUT}"
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
# Comment back on the PR that caused this push
- id: pr-finder
run: |
GIT_SHA=$(git rev-parse HEAD)
echo "${GIT_SHA}"
PR_NUMBER=$(curl -L \
--fail-with-body \
--silent \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"https://api.github.com/repos/${GITHUB_REPOSITORY}/commits/${GIT_SHA}/pulls" \
| jq --raw-output '.[0].number')
echo "PR_NUMBER=${PR_NUMBER}" >> "${GITHUB_OUTPUT}"
- uses: thollander/actions-comment-pull-request@v2
with:
message: |
## :package: npm Publish
This pull request resulted in the npm release: [v${{ steps.publish.outputs.PACKAGE_VERSION }}](https://www.npmjs.com/package/${{ steps.publish.outputs.PACKAGE_NAME }}/v/${{ steps.publish.outputs.PACKAGE_VERSION }})
_Comment generated by the [${{ github.workflow }}](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}/attempts/${{ github.run_attempt }}) workflow._
comment_tag: node-publish
pr_number: ${{ steps.pr-finder.outputs.PR_NUMBER }}