Reusable GitHub Actions workflows and workflow templates for the Dice Roller organisation.
The shared publishing workflow is at .github/workflows/npm-publish.yml. It stages the calling repository's package from its package.json using npm Trusted Publishing (OIDC). A maintainer then reviews and approves the staged release with 2FA on npmjs.com before it becomes publicly available. No npm access token is stored.
mainstages stable versions under the npmlatestdist-tag. This is the only branch allowed to stage a final major release.nextstages prerelease versions only (for example6.0.0-beta.3) under the npmnextdist-tag. A stable6.0.0will be rejected.releases/vNstages versions of the same major only under npm dist-tagrelease-N(for examplereleases/v5accepts5.5.2underrelease-5, but rejects6.0.0). Maintenance branches may publish patch or minor updates without moving to a new major.- Other branches never stage; already-published versions are skipped.
- Invalid or mismatched versions fail before the workflow installs dependencies, builds or stages anything.
- npm rejects version-like dist-tags such as
v5, so thereleases/v5branch publishes underrelease-5. Users can install it withnpm install @dice-roller/rpg-dice-roller@release-5, or request any compatible v5 directly using@^5. - An unexpected registry response fails the workflow instead of treating the package as unpublished.
- Optional caller inputs
test-commandandbuild-commandoverride the defaultnpm test --if-presentandnpm run build --if-present.
Important: A staged release does not become publicly installable until a maintainer approves it. Once staged, its dist-tag is fixed. Staged versions are not visible through the public registry lookup used by this workflow; rerunning before approval may fail because the same version is already staged. Check Staged Packages on npmjs.com before retrying. Publishing an existing version again is not possible. Promoting an already-published version from next to latest requires npm dist-tag add separately; this workflow doesn't manage existing tags.
Copy workflow-templates/npm-publish.yml to .github/workflows/publish.yml in each package repository, or choose the organisation's Dice Roller npm publishing workflow template from GitHub Actions.
By default it references dice-roller/.github/.github/workflows/npm-publish.yml@main. Once the central workflow is established, pin the reference to a protected release tag or an immutable commit SHA for stronger supply-chain protection.
In each npm package's npmjs.com settings, create a GitHub Actions Trusted Publisher with:
- Organisation:
dice-roller - Repository: the package's own repository (for example
vitepress-plugin) - Workflow filename:
publish.yml(the calling workflow, notnpm-publish.yml) - Allowed actions: leave Allow npm publish and Allow npm dist-tag unchecked.
npm stage publishis always permitted.
Do not configure the central .github repository as the npm package's Trusted Publisher. Both workflows declare id-token: write. GitHub-hosted runners and a compatible Node/npm version are required.
A new Trusted Publisher must complete its first successful release within two days or be recreated. Staged publishing supports new packages too (npm creates a temporary 0.0.0-stage placeholder), but the release is not complete until you approve the staged version.
With the caller workflow on a package's default branch, open Actions → Publish to npm → Run workflow and choose main, next or an existing releases/vN branch. Pushing a new version to any of those branches also triggers staging automatically, provided the caller includes the appropriate branch filter. Afterwards, sign in to npmjs.com, open Staged Packages, review the artefact and choose Approve (2FA required).
- This repository must be public for public package repositories to use its reusable workflow and workflow templates.
- Protect
main,nextand maintainedreleases/vNbranches in package repositories, and protect the central workflow's release references. - The workflow validates versions at publication time. It does not stop someone committing an incorrect version; add a PR status check if you also want to block invalid version bumps from merging.
- Existing package-specific callers (such as the VitePress plugin pilot) must explicitly opt into
releases/v*pushes to enable maintenance publishing. - By default, the workflow releases the public npm package at the repository root. Set
package-directoryfor a nested npm workspace. Dependency installation always uses the committed rootpackage-lock.json. - Package-specific test/build commands and
prepublishOnlyscripts may duplicate work; adapt the caller inputs as needed. - Check that each package's
repository.urlmatches its GitHub repository.
The reusable .github/workflows/prepare-release.yml separates release preparation from the existing npm staging/publishing workflow. The organisation workflow template at workflow-templates/prepare-release.yml installs the caller as .github/workflows/prepare-release.yml in each package repository.
- Install the caller workflow in the package repository's default branch (usually
main). It must also be present on any other branch selected for manual dispatch, such asnextorreleases/v5. - Enable Settings → Actions → General → Allow GitHub Actions to create and approve pull requests for that repository. The workflow needs
contents: writeandpull-requests: write, which are explicitly requested. - In the package's Actions → Prepare Release → Run workflow, choose the branch to release, the version increment and an optional prerelease identifier (default
beta). - The shared workflow runs
npm versionwithout committing or tagging, checks the new version against the selected branch and creates a version-bump PR targeting that branch. - Review and merge the PR. A separate job checks that it really is a generated, merged release PR and creates an annotated
vX.Y.ZGit tag on the merged commit. - The existing npm workflow runs from the branch push, stages the package under the correct npm dist-tag, and you approve the release on npmjs.com.
Use a GitHub App to let the tagging job create tags when a ruleset restricts creations:
- Register an organisation-owned GitHub App with Contents: Read and write, disable webhooks and install it on the package repositories.
- Store its numeric App ID as the organisation Actions variable
RELEASE_APP_ID. - Generate an app private key and store the entire PEM file contents as the organisation Actions secret
RELEASE_APP_PRIVATE_KEY. Grant the package repositories access to both the variable and secret. - Add the app to the tag-creation ruleset's bypass list with Always allow.
- Pass the variable and secret from the caller's
tagjob (the organisation template already includes this):
with:
mode: tag
release-app-id: ${{ vars.RELEASE_APP_ID }}
secrets:
RELEASE_APP_PRIVATE_KEY: ${{ secrets.RELEASE_APP_PRIVATE_KEY }}Only the tagging job uses the app. It creates a short-lived token limited to the calling repository with Contents: write, and the token is revoked at the end of the job. Release preparation still uses GITHUB_TOKEN.
The app credentials are optional for callers without protected tag creation, which continue to use GITHUB_TOKEN.
Tags pushed with the app token can trigger tag-based workflows. The shared npm publishing workflow runs from branch pushes, so its publishing behaviour is unchanged.
| Target branch | Allowed version bump inputs | Required resulting version |
|---|---|---|
main |
patch, minor, major |
Stable release, no prerelease suffix |
next |
prerelease, prepatch, preminor, premajor |
Must have a prerelease suffix |
releases/vN |
patch, minor, prerelease, prepatch, preminor |
Major must equal N (before and after the bump) |
| Other branches | None | Release preparation rejected |
premajor on next prepares a prerelease of the next major (e.g. 7.0.0-beta.0); it cannot produce a stable major release. Only main can prepare a stable major bump. The shared npm staging workflow independently checks the final branch/version policy again.
The release branch name is release/prepare/<target>/v<version>, with slashes in target names replaced by hyphens. PRs are not automatically merged; the Git tag only appears once a matching generated PR is merged. The tag job works with normal merge, squash merge or rebase merge and refuses to move an existing tag to another commit.
- A PR created using the built-in
GITHUB_TOKENmay display Approve workflows to run before normal PR CI executes. GitHub requires this additional approval for PRs created by workflow automation. For CI to run automatically on these PRs instead, the release workflow would need to use a dedicated GitHub App installation token or fine-grained personal access token. - Never merge the release PR before its required CI checks pass. Keep branch protections in place on
main,nextand supportedreleases/vNbranches. - This workflow uses
npm version --no-git-tag-version --ignore-scripts, so it updatespackage.jsonandpackage-lock.jsonbut does not run lifecycle hooks, create a version commit or create a tag until our own release steps do so. It supports a root package or selected npm workspace, with a committed root lockfile. - The npm staging workflow is separate: the merge is a real user action, so its push event triggers staging. The Git tag is for Git history only; publishing is not triggered by the tag.
- A tag is created after the release PR merge, not after npm staging approval. If staging or approval fails, the tag still identifies the prepared release and the workflow can be retried.
Both central workflows accept an optional package-directory input, defaulting
to .. The Prepare Release workflow also accepts tag-prefix, defaulting to
v. Existing callers need no changes and retain their current version bumps,
release branch names and vX.Y.Z tags.
For the SVG presenter, the publishing caller can use:
jobs:
publish-svg:
uses: dice-roller/.github/.github/workflows/npm-publish.yml@main
with:
package-directory: packages/svgThe caller still needs the existing branch filters and id-token: write
permission. To stage only SVG manifest changes automatically, use
paths: ['packages/svg/package.json'] on its push trigger. Configure npm Trusted
Publishing for the package's calling workflow filename, as described above.
Set the same package directory and prefix in both preparation and tagging:
jobs:
prepare-svg:
if: github.event_name == 'workflow_dispatch'
uses: dice-roller/.github/.github/workflows/prepare-release.yml@main
with:
mode: prepare
package-directory: packages/svg
tag-prefix: svg-v
bump: ${{ inputs.bump }}
prerelease-id: ${{ inputs.prerelease-id }}
tag-svg:
if: github.event_name == 'pull_request' && github.event.pull_request.merged == true
uses: dice-roller/.github/.github/workflows/prepare-release.yml@main
with:
mode: tag
package-directory: packages/svg
tag-prefix: svg-v
release-app-id: ${{ vars.RELEASE_APP_ID }}
secrets:
RELEASE_APP_PRIVATE_KEY: ${{ secrets.RELEASE_APP_PRIVATE_KEY }}Use the existing dispatch inputs and merged-PR trigger from the template. The
reusable workflow retains its checks for generated, same-repository release PRs.
For additional presenters, add explicit jobs with their own package directory
and a unique prefix, such as terminal-v. Tag jobs skip PRs for other prefixes.
For SVG version 1.2.0 on main, the release branch is
release/prepare/main/svg-v1.2.0 and the Git tag is svg-v1.2.0. The npm package
version remains 1.2.0; the prefix only identifies Git releases. Include these
prefixed tags in any existing tag-protection rules.
The workflows:
- Read the selected package's name and version, not the private workspace root.
- Bump only that workspace using
npm version --workspace, synchronise the root lockfile, and commit the selected manifest plus that lockfile. - Install dependencies and run the configured test/build commands at the root.
Override
test-commandorbuild-commandto target a single workspace if wanted. - Run
npm stage publish --workspaces=falsefrom the selected package directory; staging does not depend on npm's workspace auto-detection. - Validate that package directories and manifests resolve inside the checkout, reject private packages, and validate tag prefixes before changing versions.
Use repository-relative package paths made from letters, numbers, ., _, -
and /. Tag prefixes must start with a letter or number and contain only letters,
numbers, ., _ or -, and must produce a valid Git tag.
There are no automatic multi-package releases or repository-specific release scripts. Each caller explicitly selects the package it wants to release.
npm ci
npm testThe TypeScript tests compile with tsc and run with Jest. They execute shell steps extracted from the actual workflow YAML against
root-package and npm-workspace fixtures. Versioning runs offline with lifecycle
hooks disabled, and tag pushes target disposable local Git repositories. npm
staging is never executed. The checks run automatically on workflow/template/test
pull requests and pushes to main.