Skip to content

Commit d75dbb8

Browse files
Merge pull request #1078 from NordicSemiconductor/push-rpkxtsrkvzky
Enhance GitHub Actions for releasing shared
2 parents 6d78581 + 7fa979e commit d75dbb8

File tree

3 files changed

+31
-16
lines changed

3 files changed

+31
-16
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Auto-publish shared
1+
name: Maybe auto-release shared
22

33
on: workflow_call
44

@@ -24,7 +24,8 @@ jobs:
2424
if reason=$(npx tsx ./scripts/is-releasable.ts); then
2525
echo "ready_to_release=true" >> $GITHUB_OUTPUT
2626
else
27-
echo ":see_no_evil: Not releasing because: $reason" >> $GITHUB_STEP_SUMMARY
27+
echo "ℹ️ Doing no release, just testing if it is otherwise releasable." >> $GITHUB_STEP_SUMMARY
28+
echo "If you want an automatic release, you need to change this: $reason" >> $GITHUB_STEP_SUMMARY
2829
echo "ready_to_release=false" >> $GITHUB_OUTPUT
2930
fi
3031

.github/workflows/npm-publish-switch.yml

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

3+
run-name: |
4+
${{
5+
github.event_name == 'push'
6+
&& 'Maybe release shared automatically'
7+
|| 'Release shared explicitly'
8+
}}
9+
310
# With the trusted publisher model, npm now allows only a single workflow to
411
# be registered as the trusted publisher. But this workflow can then invoke
5-
# other workflows, which may do the actual publishing.
12+
# other workflows, which may do the actual releasing.
613

714
# So this workflow will act as a switch which:
815
# - If run on main branch as a result of a push, will check try to
916
# automatically release a new version
10-
# - Can be run directly to explicitly publish a new version to npm (which only
17+
# - Can be run directly to explicitly release a new version to npm (which only
1118
# makes sense when running it on a branch apart from main, because there the
12-
# auto-publish workflow will take care of it)
19+
# auto-release workflow will take care of it)
1320
#
1421
# The idea of this setup is also shown in
1522
# https://github.com/orgs/community/discussions/174507#discussioncomment-14723818
@@ -27,12 +34,12 @@ on:
2734
type: string
2835

2936
jobs:
30-
auto-publish:
37+
auto-release:
3138
if: ${{ github.event_name == 'push' }}
3239
uses: ./.github/workflows/auto-publish-shared.yml
3340
secrets: inherit
3441

35-
explicit-publish:
42+
explicit-release:
3643
if: ${{ github.event_name == 'workflow_dispatch' }}
3744
uses: ./.github/workflows/release-shared.yml
3845
with:

.github/workflows/release-shared.yml

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
name: Release shared
1+
name: Release shared - Helper workflow
2+
3+
# This workflow is intended to be invoked by other workflows.
4+
# It is no longer meant to be invoked directly.
25

36
on:
47
workflow_call:
@@ -31,7 +34,7 @@ jobs:
3134
- name: Check if release is possible
3235
run: |
3336
if ! reason=$(npx tsx ./scripts/is-releasable.ts); then
34-
echo "::error::$reason"
37+
echo "🛑 Unable to release: $reason" >> $GITHUB_STEP_SUMMARY
3538
exit 1
3639
fi
3740
@@ -45,19 +48,23 @@ jobs:
4548
run:
4649
npx tsx ./scripts/latest-changelog-entry.ts > release_notes.md
4750

48-
- name: Determine next tag
49-
id: determine-next-tag
51+
- name: Determine next version
52+
id: determine-next-version
5053
uses: actions/github-script@v7
5154
with:
5255
script: |
53-
const version = require('./package.json').version;
54-
core.setOutput('tag', `v${version.replace('.0.0', '')}`);
56+
const version = require('./package.json').version.replace('.0.0', '');
57+
core.setOutput('version', version);
58+
core.setOutput('tag', `v${version}`);
5559
5660
- name: Create GitHub release
5761
run: |
58-
gh release create "${{ steps.determine-next-tag.outputs.tag }}" \
59-
--title "${{ steps.determine-next-tag.outputs.tag }}" \
62+
gh release create "${{ steps.determine-next-version.outputs.tag }}" \
63+
--title "${{ steps.determine-next-version.outputs.tag }}" \
6064
--notes-file release_notes.md
6165
6266
- name: Publish to npm
63-
run: npm publish
67+
run: |
68+
npm publish
69+
70+
echo "✅ Successfully released package [pc-nrfconnect-shared@${{ steps.determine-next-version.outputs.version }}](https://www.npmjs.com/package/@nordicsemiconductor/pc-nrfconnect-shared/v/${{ steps.determine-next-version.outputs.version }}.0.0) to npm." >> $GITHUB_STEP_SUMMARY

0 commit comments

Comments
 (0)