Skip to content
Draft
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
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,6 @@ jobs:
- run: npm ci
- run: npm test
- run: npm run build
- name: Test the publish script
if: matrix.dir == '.'
run: node --test scripts/
91 changes: 91 additions & 0 deletions .github/workflows/publish-npm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
name: Publish to npm

# Publishes the frontend and backend plugin packages at the version in their
# package.json files, the same way the extensions repository publishes its
# TypeScript bindings. Run it by hand from main; dry_run builds and checks
# without publishing. See scripts/publish-npm.mjs and docs/releases.md.
#
# A package's first release is staged with the NPM_STAGE_TOKEN secret, a
# stage-only token, and a maintainer approves it on npmjs.com. Later releases
# use npm trusted publishing: npm accepts this workflow file's OIDC identity,
# so no token is needed. Renaming this file breaks that trust.

on:
workflow_dispatch:
inputs:
dry_run:
description: 'Build and check both packages without publishing anything'
type: boolean
default: true

permissions:
contents: read

concurrency:
group: publish-npm
cancel-in-progress: false

jobs:
publish:
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-24.04
timeout-minutes: 20
permissions:
# The tag and GitHub release for a published version.
contents: write
# npm trusted publishing.
id-token: write
env:
EXECUTE: ${{ !inputs.dry_run }}
steps:
- name: Check out repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false

- name: Set up Node.js for npm trusted publishing
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: 24
registry-url: https://registry.npmjs.org

# npm stage publish needs npm 11.15.0 or later.
- name: Install npm with staged publishing
run: npm install --global npm@11.15.0

- name: Test the publish script
run: node --test scripts/

- name: Build and check both packages, then publish or stage them
id: publish
env:
NPM_STAGE_TOKEN: ${{ secrets.NPM_STAGE_TOKEN }}
run: |
if [[ "$EXECUTE" == true ]]; then
node scripts/publish-npm.mjs --execute
else
node scripts/publish-npm.mjs
fi

- name: Generate the OpenAPI specification
if: steps.publish.outputs.released == 'true'
env:
VERSION: ${{ steps.publish.outputs.version }}
run: |
cd backend
# npm ci again: the backend was skipped when only the frontend had a new version.
npm ci
npm run openapi:generate -- "$VERSION"

- name: Tag the release and create the GitHub release
if: steps.publish.outputs.released == 'true'
env:
GH_TOKEN: ${{ github.token }}
VERSION: ${{ steps.publish.outputs.version }}
run: |
set -euo pipefail
if gh release view "v$VERSION" > /dev/null 2>&1; then
echo "Release v$VERSION already exists."
exit 0
fi
gh release create "v$VERSION" backend/dist/openapi.yaml --target "$GITHUB_SHA" --generate-notes
78 changes: 0 additions & 78 deletions .github/workflows/release.yml

This file was deleted.

2 changes: 1 addition & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@runtimeconditions/plugin-runtime-conditions-backend",
"version": "0.0.0",
"version": "0.1.0",
"license": "MIT",
"repository": {
"type": "git",
Expand Down
55 changes: 53 additions & 2 deletions docs/releases.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,56 @@
# Releases

Merging a `feat`, `fix`, `perf`, `revert`, or breaking change to `main` publishes both packages to npm at the same version, tags the merge commit `vX.Y.Z`, and creates a GitHub release. The release also includes the backend's `openapi.yaml`. Other changes, such as docs or CI, do not release.
Both packages, `@runtimeconditions/plugin-runtime-conditions` and
`@runtimeconditions/plugin-runtime-conditions-backend`, are published to npm at
the same version, the way the extensions repository publishes its bindings.

Versions follow semantic versioning and come from the PR titles described in [CONTRIBUTING.md](../CONTRIBUTING.md). Publishing uses npm trusted publishing, so no token is stored. `CONTRIBUTING.md` lists the one-time setup.
## Releasing a version

1. In a pull request, set the next version in both `package.json` and
`backend/package.json`. They must be the same. Follow semantic versioning:
a fix is a patch, a new feature a minor version, and a breaking change a
major version.
2. After the merge, open **Actions → Publish to npm → Run workflow** on `main`.
Leave **dry_run** ticked first: it builds and checks both packages and
publishes nothing. Then run it again with **dry_run** unticked.
3. The run publishes each package whose version is not on npm yet, tags the
commit `vX.Y.Z`, and creates a GitHub release with the backend's
`openapi.yaml`. A version that is already on npm is skipped, so running the
workflow again is safe.

## How each package is published

| On npm | What the run does |
| --- | --- |
| The package does not exist | Stages the first release with the `NPM_STAGE_TOKEN` secret. A maintainer approves it on npmjs.com under **Staged Packages** (asks for 2FA). |
| Only the staged placeholder (`0.0.0-stage`) | Skips it: the first release still waits for approval. |
| The version is already there | Skips it. |
| Anything else | Publishes through npm trusted publishing. No token is used. |

The logic is in `scripts/publish-npm.mjs`, tested with `node --test scripts/`.

## One-time setup

1. **Stage-only token.** On npmjs.com, create a granular access token with
**Read and write (stage only)** for the `@runtimeconditions` packages, and
save it as the `NPM_STAGE_TOKEN` repository secret. It can only stage
releases, never publish them, so it stays useful for any future first
release.
2. **First release.** Run the workflow; both packages are staged. Approve both
on npmjs.com.
3. **Trusted publisher.** Once the packages exist, add this workflow as their
trusted publisher (asks for 2FA):

```sh
for p in @runtimeconditions/plugin-runtime-conditions @runtimeconditions/plugin-runtime-conditions-backend; do
npm trust github "$p" --file publish-npm.yml --repo runtimeconditions/backstage-plugin \
--allow-publish --allow-stage-publish --yes
sleep 2
done
```

npm drops a trusted publisher that is not used within 2 days, so add it
just before the next release rather than right after the first.

Renaming `.github/workflows/publish-npm.yml` breaks the trusted publisher;
add it again with the new file name.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@runtimeconditions/plugin-runtime-conditions",
"version": "0.0.0",
"version": "0.1.0",
"license": "MIT",
"repository": {
"type": "git",
Expand Down
Loading
Loading