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
9 changes: 8 additions & 1 deletion .github/projections/self-topology/releases.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,15 @@
// revision, which can't see that configuration, so it publishes nothing here: an npm job that waits for approval is
// no npm release. Turning publishing on in the workflow (an unconditional step, a dist `publish-jobs` entry) shows it.

// npm options that take a value, which may follow them after a space (`npm -w sdk publish`). Any other option before
// `publish` is a flag or carries its value after `=`, so `npm --silent run publish` isn't read as a publish.
const npmValueOptions = '--workspace|-w|--registry|--tag|--access|--otp|--userconfig|--prefix|-C|--cache|--loglevel'
const registries = [
{pattern: /\bnpm\s+publish\b(.*)$/u, registry: 'npm', option: /(?:--workspace|-w)[ =](\S+)/u},
{
pattern: new RegExp(`\\bnpm\\s+((?:(?:(?:${npmValueOptions})\\s+[^-\\s]\\S*|-[\\w-]+(?:=\\S*)?)\\s+)*publish\\b.*)$`, 'u'),
registry: 'npm',
option: /(?:--workspace|-w)[ =](\S+)/u,
},
{pattern: /\b(?:@vscode\/)?vsce\s+publish\b(.*)$/u, registry: 'Marketplace', option: /(?:--packagePath|-i)[ =](\S+)/u, vscode: true},
{pattern: /\bovsx\s+publish\b(.*)$/u, registry: 'Open VSX', option: /(?:--packagePath|-i)[ =](\S+)/u, vscode: true},
{pattern: /\bcargo\s+publish\b(.*)$/u, registry: 'crates.io', option: /(?:--package|-p)[ =](\S+)/u, crate: true},
Expand Down
21 changes: 21 additions & 0 deletions .github/projections/self-topology/releases.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,27 @@ ${condition} steps:
assert.deepEqual(channels({'.github/workflows/publish.yml': publish()}), {'npm:sdk': ['npm'], 'npm:ext': ['Marketplace']})
})

test('npm options before publish, the workspace among them, still publish the workspace', () => {
const publish = `jobs:
publish:
steps:
- run: npm --ignore-scripts --registry=https://registry.npmjs.org/ publish --workspace sdk
`
assert.deepEqual(channels({'.github/workflows/publish.yml': publish}), {'npm:sdk': ['npm']})
const before = 'jobs:\n publish:\n steps:\n - run: npm --ignore-scripts --workspace=sdk publish\n'
assert.deepEqual(channels({'.github/workflows/publish.yml': before}), {'npm:sdk': ['npm']})
for (const command of [
'npm --workspace sdk publish',
'npm -w sdk publish',
'npm --registry https://registry.npmjs.org/ publish --workspace sdk',
]) {
const spaced = `jobs:\n publish:\n steps:\n - run: ${command}\n`
assert.deepEqual(channels({'.github/workflows/publish.yml': spaced}), {'npm:sdk': ['npm']}, command)
}
const script = 'jobs:\n publish:\n steps:\n - run: npm --silent -w sdk run publish\n'
assert.deepEqual(channels({'.github/workflows/publish.yml': script}), {})
})

test('a TOML list is found by its literal key', () => {
const text = 'a.b = ["dot"]\naxb = ["any"]\npublish-jobs = ["./npm", \'homebrew\']\n'
assert.deepEqual(tomlList(text, 'a.b'), ['dot'])
Expand Down
82 changes: 67 additions & 15 deletions .github/workflows/publish-npm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ name: Publish npm package
# CLI's: a release whose tag, Cargo.toml and packages/sdk/package.json disagree publishes nothing. Run it by hand to publish
# a release again; a version already on npm is left as it is.
#
# Every publish runs as this workflow, started by workflow_dispatch. npm's trusted publishing checks the workflow that
# started the run, so when release.yml calls this one it would check release.yml instead. The release therefore
# dispatches this workflow at its tag rather than publishing itself, and npm trusts a single workflow: publish-npm.yml.
#
# Inert until configured: until the NPM_PUBLISHING repository variable says how it authenticates (trusted publishing,
# or an NPM_TOKEN secret in the npm environment), it only says so. npm publishing awaits security approval, so it stays
# unconfigured; meanwhile every release attaches the packed package, which renderers depend on by URL (release-proof.yml).
Expand Down Expand Up @@ -48,9 +52,29 @@ jobs:
exit 1
;;
esac
# Called by the release: start this workflow at the release's tag, so the publish runs as publish-npm.yml. Workflow
# runs that GITHUB_TOKEN starts by workflow_dispatch are allowed, unlike its other events.
dispatch:
needs: configured
if: needs.configured.outputs.ready == 'true' && inputs.plan != ''
runs-on: ubuntu-24.04
timeout-minutes: 5
permissions:
actions: write
steps:
- shell: bash
env:
GH_TOKEN: ${{ github.token }}
PLAN: ${{ inputs.plan }}
REPOSITORY: ${{ github.repository }}
run: |
set -euo pipefail
TAG=$(jq -r '.announcement_tag' <<< "$PLAN")
gh workflow run publish-npm.yml --repo "$REPOSITORY" --ref "$TAG" -f tag="$TAG"
echo "::notice title=npm publish started::Publish npm package is publishing $TAG in its own run."
publish:
needs: configured
if: needs.configured.outputs.ready == 'true'
if: needs.configured.outputs.ready == 'true' && inputs.tag != ''
runs-on: ubuntu-24.04
timeout-minutes: 20
# npm trusts this repository, workflow and environment (trusted publishing), or the environment holds NPM_TOKEN.
Expand All @@ -66,10 +90,8 @@ jobs:
- id: release
shell: bash
env:
PLAN: ${{ inputs.plan }}
TAG: ${{ inputs.tag }}
run: |
if [ -z "$TAG" ]; then TAG=$(jq -r '.announcement_tag' <<< "$PLAN"); fi
if ! [[ "$TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?$ ]]; then
echo "::error title=Not a release tag::$TAG is not a release tag such as v0.2.0."
exit 1
Expand All @@ -83,7 +105,8 @@ jobs:
- uses: actions/setup-node@v6.5.0
with:
node-version-file: .node-version
registry-url: https://registry.npmjs.org
# No registry-url: setup-node would then write an .npmrc that authenticates with NODE_AUTH_TOKEN. Trusted
# publishing needs no token, and token publishing configures its own below.
- name: Check the version
shell: bash
env:
Expand All @@ -93,37 +116,66 @@ jobs:
npm ci --ignore-scripts --no-audit --no-fund
# Every shipped manifest carries the release's version (docs/maintainers/releasing.md).
npm run --silent tools -- version --tag "$TAG"
# Trusted publishing needs npm 11.5.1 or later.
npm --version
# Trusted publishing needs npm 11.5.1 or later, which the Node in .node-version ships.
npm_version=$(npm --version)
if [ "$(printf '%s\n' 11.5.1 "$npm_version" | sort -V | head -n 1)" != 11.5.1 ]; then
echo "::error title=npm too old::Trusted publishing needs npm 11.5.1 or later, but this Node ships npm $npm_version."
exit 1
fi
- name: Build and check the package
shell: bash
run: |
for workspace in packages/schemas packages/renderers/sdk packages/renderers/kit packages/renderers/testing packages/sdk; do
npm run build --workspace "$workspace"
done
node packages/sdk/scripts/check-pack.mjs --contents
- name: Publish
- id: prepare
name: Prepare the publish
shell: bash
env:
VERSION: ${{ steps.release.outputs.version }}
METHOD: ${{ vars.NPM_PUBLISHING }}
# Unused with trusted publishing, which needs no token.
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
# Whether the secret is set, not the secret: only the token publish step sees NPM_TOKEN.
HAS_TOKEN: ${{ secrets.NPM_TOKEN != '' }}
run: |
set -euo pipefail
if [ "$METHOD" = token ] && [ -z "$NODE_AUTH_TOKEN" ]; then
if [ "$METHOD" = token ] && [ "$HAS_TOKEN" != true ]; then
echo "::error title=No npm token::NPM_PUBLISHING is token, but the npm environment has no NPM_TOKEN secret."
exit 1
fi
registry=https://registry.npmjs.org/
if npm view "@githubnext/projections-sdk@$VERSION" version --registry "$registry" > /dev/null 2>&1; then
if npm view "@githubnext/projections-sdk@$VERSION" version --registry https://registry.npmjs.org/ > /dev/null 2>&1; then
echo "::notice title=Already published::@githubnext/projections-sdk@$VERSION is already on npm; versions are immutable."
exit 0
fi
# A prerelease such as 0.3.0-beta.1 is published under the next tag, so latest stays the latest stable.
tag=latest
if [[ "$VERSION" == *-* ]]; then tag=next; fi
dist_tag=latest
if [[ "$VERSION" == *-* ]]; then dist_tag=next; fi
echo "dist-tag=$dist_tag" >> "$GITHUB_OUTPUT"
# npm uploads package.json as the version's registry metadata too, so it is the published manifest on disk
# (without the internal workspaces it is built from) before publishing starts.
node packages/sdk/scripts/manifest.mjs strip
npm publish --workspace packages/sdk --registry "$registry" --access public --provenance --tag "$tag"
echo publish=true >> "$GITHUB_OUTPUT"
# The package was built above; --ignore-scripts keeps npm from running lifecycle scripts while it holds the
# credential.
- name: Publish with trusted publishing
if: steps.prepare.outputs.publish == 'true' && vars.NPM_PUBLISHING == 'trusted'
shell: bash
# No NODE_AUTH_TOKEN: npm exchanges the job's OIDC token for a short-lived one that can publish only this package.
env:
DIST_TAG: ${{ steps.prepare.outputs.dist-tag }}
run: >-
npm --ignore-scripts publish --workspace packages/sdk --registry https://registry.npmjs.org/ --access public
--provenance --tag "$DIST_TAG"
- name: Publish with a token
if: steps.prepare.outputs.publish == 'true' && vars.NPM_PUBLISHING == 'token'
shell: bash
env:
DIST_TAG: ${{ steps.prepare.outputs.dist-tag }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
set -euo pipefail
# npm expands ${NODE_AUTH_TOKEN} itself, so the token is never written to disk.
# shellcheck disable=SC2016
printf '%s\n' '//registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN}' > "$RUNNER_TEMP/.npmrc"
NPM_CONFIG_USERCONFIG="$RUNNER_TEMP/.npmrc" npm --ignore-scripts publish --workspace packages/sdk \
--registry https://registry.npmjs.org/ --access public --provenance --tag "$DIST_TAG"
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ jobs:
plan: ${{ needs.plan.outputs.val }}
secrets: inherit
permissions:
"actions": "write"
"contents": "read"
"id-token": "write"

Expand Down
5 changes: 3 additions & 2 deletions dist-workspace.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,11 @@ global-artifacts-jobs = ["./release-proof"]
publish-jobs = ["./release-approval"]
# Once the release is announced, its JSON Schemas are published to the schemas host
# (publish-schemas.yml, docs/maintainers/schema-publishing.md) and @githubnext/projections-sdk to npm
# (publish-npm.yml, docs/maintainers/npm-publishing.md; inert until npm publishing is approved), and a stable
# (publish-npm.yml, docs/maintainers/npm-publishing.md; inert until npm publishing is approved, then it dispatches
# itself, hence actions: write, so npm's trusted publishing sees publish-npm.yml), and a stable
# release moves its major version tag, v0, which `uses: githubnext/projections@v0` follows (move-major-tag.yml).
post-announce-jobs = ["./publish-schemas", "./publish-npm", "./move-major-tag"]
github-custom-job-permissions = { "release-proof" = { contents = "read" }, "release-approval" = { actions = "read", attestations = "write", id-token = "write" }, "publish-schemas" = { contents = "read", id-token = "write" }, "publish-npm" = { contents = "read", id-token = "write" }, "move-major-tag" = { contents = "read" } }
github-custom-job-permissions = { "release-proof" = { contents = "read" }, "release-approval" = { actions = "read", attestations = "write", id-token = "write" }, "publish-schemas" = { contents = "read", id-token = "write" }, "publish-npm" = { actions = "write", contents = "read", id-token = "write" }, "move-major-tag" = { contents = "read" } }

[dist.github-custom-runners]
global = "ubuntu-24.04"
Expand Down
Loading