Builds a Node.js package, publishes it and creates a GitHub release, when a version tag is pushed.
name: Release
on:
push:
tags:
- 'v*.*.*'
permissions:
contents: write
id-token: write
jobs:
publish:
uses: MyCoRe-Org/github-workflows/.github/workflows/node-release.yml@v1
with:
node-version: '24'
secrets:
MATRIX_ACCESS_TOKEN: ${{ secrets.MATRIX_ACCESS_TOKEN }}The workflow must run on a tag, it fails on branches to avoid a release named after the branch.
The published version comes from the package metadata, e.g. package.json, not from the tag,
so set both to the same version before tagging.
| Input | Required | Default | Description |
|---|---|---|---|
node-version |
yes | Node.js version, e.g. '24' |
|
build-script |
no | build |
Package script to run before publishing, empty to skip |
publish-command |
no | yarn npm publish --access public |
Publish command, e.g. npx jsr publish |
registry-url |
no | https://registry.npmjs.org |
Registry for publishing |
create-release |
no | true |
Create a GitHub release for the tag |
| Secret | Description |
|---|---|
MATRIX_ACCESS_TOKEN |
Optional, see notifications |
- A tag check stops runs on branches.
node-setupinstalls the dependencies as innode-build.ymland configuresregistry-urlfor npm.build-scriptruns withyarn run.publish-commandpublishes the package.- With
create-release, the GitHub release for the tag gets the notes GitHub generates since the previousv*tag. - A message reports the result to Matrix, if configured.
Publishing uses OIDC (trusted publishing), no npm token is passed. This needs:
id-token: writein the caller, as in the example.- The package configured for trusted publishing on npmjs.com, with this repository and the file name
of the calling workflow. npm checks the caller, not this reusable workflow, so renaming the caller requires
changing the trusted publisher as well. The template names the file
node-release.yml, projects that already publish withrelease.ymlcan keep that name. - A Yarn version that supports trusted publishing. The Vue projects publish this way with Yarn 4.12.
Publish to JSR, without build script:
with:
node-version: '24'
build-script: ''
publish-command: npx jsr publish