Skip to content

Commit 5cc4b28

Browse files
committed
chore(ci): Add release workflow to automate npm releases
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
1 parent aaba505 commit 5cc4b28

1 file changed

Lines changed: 65 additions & 0 deletions

File tree

.github/workflows/npm-publish.yml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# This workflow is provided via the organization template repository
2+
#
3+
# https://github.com/nextcloud/.github
4+
# https://docs.github.com/en/actions/learn-github-actions/sharing-workflows-with-your-organization
5+
6+
name: Publish
7+
8+
on:
9+
release:
10+
types: [published]
11+
12+
permissions:
13+
contents: read
14+
packages: write
15+
16+
jobs:
17+
publish:
18+
runs-on: ubuntu-latest
19+
20+
name: Build and publish to npm
21+
steps:
22+
- name: Check actor permission level
23+
uses: skjnldsv/check-actor-permission@e591dbfe838300c007028e1219ca82cc26e8d7c5 # v2.1
24+
with:
25+
require: write
26+
27+
- name: Checkout
28+
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
29+
30+
- name: Read package.json node and npm engines version
31+
uses: skjnldsv/read-package-engines-version-actions@8205673bab74a63eb9b8093402fd9e0e018663a1 # v2.2
32+
id: versions
33+
with:
34+
fallbackNode: '^20'
35+
fallbackNpm: '^9'
36+
37+
- name: Set up node ${{ steps.versions.outputs.nodeVersion }}
38+
uses: actions/setup-node@e33196f7422957bea03ed53f6fbb155025ffc7b8 # v3
39+
with:
40+
node-version: ${{ steps.versions.outputs.nodeVersion }}
41+
42+
- name: Set up npm ${{ steps.versions.outputs.npmVersion }}
43+
run: npm i -g npm@"${{ steps.versions.outputs.npmVersion }}"
44+
45+
- name: Install dependencies & build
46+
run: |
47+
npm ci
48+
npm run build --if-present
49+
50+
- name: Publish
51+
run: |
52+
npm config set //registry.npmjs.org/:_authToken=$NODE_AUTH_TOKEN
53+
npm publish
54+
env:
55+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
56+
57+
- name: Setup Github Package Registry
58+
uses: actions/setup-node@e33196f7422957bea03ed53f6fbb155025ffc7b8 # v3
59+
with:
60+
registry-url: 'https://npm.pkg.github.com'
61+
62+
- name: Publish package on GPR
63+
run: npm publish
64+
env:
65+
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)