Skip to content

Commit 99d01dd

Browse files
Add new npm publish switch workflow
With the trusted publisher model, npm now allows only a single workflow to be registered as the trusted publisher. But this workflow can then invoke other workflows, which may do the actual publishing. https://docs.npmjs.com/trusted-publishers So the new `npm-publish-switch.yml` workflow will act as a switch which: - If run on main branch as a result of a push, will check try to automatically release a new version - Can be run directly to explicitly publish a new version to npm (which only makes sense when running it on a branch apart from main, because there the auto-publish workflow will take care of it) The idea of this setup is also shown in https://github.com/orgs/community/discussions/174507#discussioncomment-14723818 Because trusted publishing requires npm CLI version 11.5.1 or later, this currently also means, that we have to update npm before running `npm publish`. Additionally `npm-publish-switch.yml` also needs to be registered as the trusted publisher in the npm settings for the pc-nrfconnect-shared package.
1 parent 8aee9b5 commit 99d01dd

File tree

3 files changed

+42
-5
lines changed

3 files changed

+42
-5
lines changed

.github/workflows/auto-publish-shared.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
name: Auto-publish shared
22

3-
on:
4-
push:
5-
branches: [main]
3+
on: workflow_call
64

75
jobs:
86
check:
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Release shared
2+
3+
# With the trusted publisher model, npm now allows only a single workflow to
4+
# be registered as the trusted publisher. But this workflow can then invoke
5+
# other workflows, which may do the actual publishing.
6+
7+
# So this workflow will act as a switch which:
8+
# - If run on main branch as a result of a push, will check try to
9+
# automatically release a new version
10+
# - Can be run directly to explicitly publish a new version to npm (which only
11+
# makes sense when running it on a branch apart from main, because there the
12+
# auto-publish workflow will take care of it)
13+
#
14+
# The idea of this setup is also shown in
15+
# https://github.com/orgs/community/discussions/174507#discussioncomment-14723818
16+
17+
on:
18+
push:
19+
branches: [main]
20+
workflow_dispatch:
21+
inputs:
22+
ref:
23+
description:
24+
Ref (Tag, branch, commit SHA) to release. Defaults to from
25+
where the workflow is triggered, usually the main branch.
26+
required: false
27+
type: string
28+
29+
jobs:
30+
auto-publish:
31+
if: ${{ github.event_name == 'push' }}
32+
uses: ./.github/workflows/auto-publish-shared.yml
33+
secrets: inherit
34+
35+
explicit-publish:
36+
if: ${{ github.event_name == 'workflow_dispatch' }}
37+
uses: ./.github/workflows/release-shared.yml
38+
with:
39+
ref: ${{ inputs.ref }}

.github/workflows/release-shared.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
name: Release shared
22

33
on:
4-
workflow_dispatch:
4+
workflow_call:
55
inputs:
66
ref:
77
description:
88
Ref (Tag, branch, commit SHA) to release. Defaults to from
99
where the workflow is triggered, usually the main branch.
1010
required: false
1111
type: string
12-
workflow_call:
1312

1413
jobs:
1514
release:
@@ -36,6 +35,7 @@ jobs:
3635
exit 1
3736
fi
3837
38+
- run: npm install --global npm@latest
3939
- run: npm ci
4040
- run: npm run check
4141
- run: npm test

0 commit comments

Comments
 (0)