Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .github/workflows/auto-publish-shared.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Auto-publish shared
name: Maybe auto-release shared

on: workflow_call

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

Expand Down
17 changes: 12 additions & 5 deletions .github/workflows/npm-publish-switch.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
name: Release shared

run-name: |
${{
github.event_name == 'push'
&& 'Maybe release shared automatically'
|| 'Release shared explicitly'
}}

# 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.
# other workflows, which may do the actual releasing.

# So this 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
# - Can be run directly to explicitly release 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)
# auto-release workflow will take care of it)
#
# The idea of this setup is also shown in
# https://github.com/orgs/community/discussions/174507#discussioncomment-14723818
Expand All @@ -27,12 +34,12 @@ on:
type: string

jobs:
auto-publish:
auto-release:
if: ${{ github.event_name == 'push' }}
uses: ./.github/workflows/auto-publish-shared.yml
secrets: inherit

explicit-publish:
explicit-release:
if: ${{ github.event_name == 'workflow_dispatch' }}
uses: ./.github/workflows/release-shared.yml
with:
Expand Down
25 changes: 16 additions & 9 deletions .github/workflows/release-shared.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
name: Release shared
name: Release shared - Helper workflow

# This workflow is intended to be invoked by other workflows.
# It is no longer meant to be invoked directly.

on:
workflow_call:
Expand Down Expand Up @@ -31,7 +34,7 @@ jobs:
- name: Check if release is possible
run: |
if ! reason=$(npx tsx ./scripts/is-releasable.ts); then
echo "::error::$reason"
echo "🛑 Unable to release: $reason" >> $GITHUB_STEP_SUMMARY
exit 1
fi

Expand All @@ -45,19 +48,23 @@ jobs:
run:
npx tsx ./scripts/latest-changelog-entry.ts > release_notes.md

- name: Determine next tag
id: determine-next-tag
- name: Determine next version
id: determine-next-version
uses: actions/github-script@v7
with:
script: |
const version = require('./package.json').version;
core.setOutput('tag', `v${version.replace('.0.0', '')}`);
const version = require('./package.json').version.replace('.0.0', '');
core.setOutput('version', version);
core.setOutput('tag', `v${version}`);

- name: Create GitHub release
run: |
gh release create "${{ steps.determine-next-tag.outputs.tag }}" \
--title "${{ steps.determine-next-tag.outputs.tag }}" \
gh release create "${{ steps.determine-next-version.outputs.tag }}" \
--title "${{ steps.determine-next-version.outputs.tag }}" \
--notes-file release_notes.md

- name: Publish to npm
run: npm publish
run: |
npm publish

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