# A tag produces a release: three platforms' binaries, their checksums, and # a changelog built from the commit subjects since the last tag. # # Nothing here rewrites the source it is building. The version in Cargo.toml # and the tag are checked against each other and the build stops if they # disagree, rather than the workflow editing the manifest to make them match # - a build that edits its own source produces a binary no checkout can # reproduce, which is a strange thing to hand somebody. release-pr.yml does # the bump, in a real commit, before the tag exists. # # A push to main is the other way in, and it is not a release: the same # three builds are packed under a canary prerelease version (npm/canary.js) # and published to npm under the `canary` dist-tag, so `npx opscope@canary` # runs whatever main is now. No tag, no GitHub release, no Homebrew or APT, # and `latest` does not move. It lives in this file rather than its own # because this is the file the four packages already trust for publishing. name: release on: push: tags: ['v*'] branches: [main] # A canary whose binaries are the previous canary's is noise. Path # filters are not evaluated for tag pushes, so this never holds back # a release. paths-ignore: - 'docs/**' - 'wiki/**' - '**/*.md' # Two uses. Dispatching at a branch exercises the whole build without # cutting a release, because the publish job is gated on the ref being a # tag. Dispatching at a tag does publish, and is how tag-release.yml # starts this workflow: a tag it pushes with GITHUB_TOKEN triggers # nothing, and workflow_dispatch is the documented exception. workflow_dispatch: # And on any change to the release machinery itself, because the first # time a release build runs should not be the release. Deliberately not # every pull request: this is three full builds and most changes here # cannot affect it. pull_request: paths: - '.github/workflows/release.yml' - 'cliff.toml' - 'Cargo.toml' - 'Cargo.lock' - 'homebrew/**' - 'debian/**' - 'npm/platform.js' permissions: # PR builds and post-release smoke tests only need read access. # The tag-only publish job grants its own write permissions, and the # canary job only id-token. contents: read # Canary runs replace each other: only the newest main is worth # publishing, so a merge that lands mid-build cancels the older run. # Every other run is its own group and is never cancelled. concurrency: group: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' && 'release-canary' || format('release-{0}', github.run_id) }} cancel-in-progress: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} jobs: build: name: ${{ matrix.target }} runs-on: ${{ matrix.runs-on }} strategy: # Every platform reports, rather than the first failure hiding the # others. When something breaks on one arch it is worth knowing # whether it broke on all three. fail-fast: false matrix: include: # Pinned, not `-latest`. The oldest glibc a binary runs on is the # one it was built against, so that is a decision rather than # something to inherit from whatever the runner image became this # month. 22.04 is glibc 2.35. - target: x86_64-unknown-linux-gnu runs-on: ubuntu-22.04 # Each macOS arch is built on its own kind of Mac, both # GitHub's standard hosted images, which are free on a public # repository. Building natively means the x86_64 binaries are # tested and started, not just compiled and packaged. # # GitHub has said macos-15-intel goes in about August 2027; # macos-26-intel is the newer standard Intel label. Move to # whichever Intel label GitHub still lists. If none is left, # x86_64 can be cross-compiled on the arm64 runner (Apple's # toolchain targets it natively), but then the tests and the # start check below cannot run for that target. # # Pinned to 15 rather than `macos-latest`, which has silently # changed arch before and would swap an artefact's contents # without its name changing. - target: aarch64-apple-darwin runs-on: macos-15 - target: x86_64-apple-darwin runs-on: macos-15-intel steps: # Pinned to a commit, not a tag. A tag is mutable: re-running this # workflow on the same release tag could execute different action code # than the release was built with, which makes "reproducible" a word # rather than a property. Comments carry the human-readable version so # a reader can tell what these are without resolving them. - uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5.1.0 with: # The changelog reads the history between two tags, and the build # stamps the commit into --version. A shallow clone has neither. fetch-depth: 0 persist-credentials: false - uses: dtolnay/rust-toolchain@6c977a6ca4077a0ceb28ffbe03f59d46e9ac8772 # master with: # An exact version, for the same reason. `stable` moves, and two # builds of one tag compiled by different compilers are two # different binaries wearing one version number. toolchain: "1.98.0" targets: ${{ matrix.target }} - uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2.9.2 with: key: ${{ matrix.target }} - name: The tag and the manifests must agree # Only meaningful on a tag; a dispatch has no version to check. if: startsWith(github.ref, 'refs/tags/v') run: | tag="${GITHUB_REF_NAME#v}" manifest=$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | head -1) if [ "$tag" != "$manifest" ]; then echo "tag v$tag but Cargo.toml says $manifest" >&2 echo "release-pr.yml bumps the manifest in a commit, and" >&2 echo "tag-release.yml tags that commit, rather than having" >&2 echo "this workflow rewrite the source it is building" >&2 exit 1 fi # The Luvus module manifest carries the same version, because the # module's build step fetches this tag's release by name. A module # checkout pinned to this commit with a stale version in it would # fetch an older release's binaries, or none at all, and the # failure would land on whoever installed it. module=$(sed -n 's/^version = "\(.*\)"/\1/p' luvus-module.toml | head -1) if [ "$tag" != "$module" ]; then echo "tag v$tag but luvus-module.toml says $module" >&2 echo "it is generated: UPDATE_LUVUS_MODULE=1 cargo test --test" >&2 echo "check generated_luvus_module_matches_the_widgets" >&2 exit 1 fi echo "v$tag" - name: The release profile still unwinds run: | # Three widgets wrap their poll thread in catch_unwind and record # why it stopped. Under panic = "abort" those arms are unreachable # and the source reads as protected while the binary is not - it # was shipped that way once. Costs about 4.5% of the total size, # measured. grep -q '^panic = "unwind"$' Cargo.toml || { echo "Cargo.toml no longer sets panic = unwind" >&2; exit 1; } # And nothing here may quietly override it. if [ -n "${RUSTFLAGS:-}" ]; then echo "RUSTFLAGS is set ($RUSTFLAGS) and could undo the profile" >&2 exit 1 fi - name: Tests env: # Where a release counts starts (OPS-127). Repository secrets, so # the project's analytics never appear in the source; a build # without them reports nowhere. The same three go to the test # step so it compiles the same binary rather than a second one. OPSCOPE_VERCEL_URL: ${{ secrets.OPSCOPE_VERCEL_URL }} OPSCOPE_GA_MEASUREMENT_ID: ${{ secrets.OPSCOPE_GA_MEASUREMENT_ID }} OPSCOPE_GA_API_SECRET: ${{ secrets.OPSCOPE_GA_API_SECRET }} run: cargo test --release --target ${{ matrix.target }} - name: Build env: # Where a release counts starts (OPS-127). Repository secrets, so # the project's analytics never appear in the source; a build # without them reports nowhere. The same three go to the test # step so it compiles the same binary rather than a second one. OPSCOPE_VERCEL_URL: ${{ secrets.OPSCOPE_VERCEL_URL }} OPSCOPE_GA_MEASUREMENT_ID: ${{ secrets.OPSCOPE_GA_MEASUREMENT_ID }} OPSCOPE_GA_API_SECRET: ${{ secrets.OPSCOPE_GA_API_SECRET }} run: cargo build --release --target ${{ matrix.target }} - name: Nothing dynamic beyond the C runtime shell: bash run: | # rusqlite is taken with `bundled` so SQLite is compiled in, and # the promise on the tin is that a binary needs nothing installed # alongside it. Checked rather than asserted: a crate that starts # wanting a system library would otherwise ship quietly. # # The two platforms name their own runtime differently and are # asked with different tools, so the allowance is per-platform # rather than one list that has to be loose enough for both. case "${{ runner.os }}" in Linux) tool="ldd" allowed='linux-vdso|libc\.so|libm\.so|libgcc_s\.so|ld-linux' ;; macOS) # otool lists the binary's own path on the first line, hence # the tail below. # # By location, not by name. Everything under /usr/lib and # /System/Library ships with macOS and is present on any Mac - # libSystem carries libc, libm and the pthreads, and chrono's # clock feature reaches CoreFoundation through iana-time-zone # to read the system timezone. What this is actually looking # for is a dylib the user would have to install, and those # live somewhere else: /opt/homebrew/lib/libsqlite3.dylib is # the exact thing that must never appear here, because # rusqlite is taken with `bundled` so that it does not. # # An earlier version listed dylib names instead and failed on # CoreFoundation, which is not a leak. Naming what is allowed # meant guessing the whole list correctly from another # platform; naming where it may come from does not. tool="otool -L" allowed='^\s*/usr/lib/|^\s*/System/Library/' ;; esac bad=0 for b in target/${{ matrix.target }}/release/*; do [ -f "$b" ] && [ -x "$b" ] || continue case "$b" in *.d|*.rlib|*.dSYM) continue ;; esac leaked=$($tool "$b" 2>/dev/null | tail -n +2 \ | grep -vE "$allowed" | grep -v '^[[:space:]]*$' || true) if [ -n "$leaked" ]; then # stdout as well as stderr: reading a failed job's log needs # admin rights on the repository, and the first time this # fired the reason was not visible to the person who wrote it. echo "$(basename "$b") links something it should carry:" echo "$leaked" bad=1 fi done [ "$bad" = 0 ] - name: It runs, and says what it is shell: bash run: | set -euo pipefail # A binary that builds and cannot start is not an artefact. Only # meaningful where the runner can execute what it just built, # which is every entry in this matrix today. # # Every binary, found by looking rather than named here. This step # used to run one, by name, and when that one was renamed the step # kept pointing at a path that no longer existed - which surfaced # as `No such file or directory` at release time, on a change that # had passed every other check. Nothing here knows what the # binaries are called, so nothing here can go stale. n=0 for b in target/${{ matrix.target }}/release/*; do [ -f "$b" ] && [ -x "$b" ] || continue case "$b" in *.d|*.rlib|*.dSYM) continue ;; esac out=$("$b" --version) echo "$out" case "$out" in *unknown*) echo "the build stamp did not resolve for $b" >&2; exit 1 ;; esac n=$((n + 1)) done # And a count, because a glob that matches nothing would otherwise # let this step pass having tested nothing at all. if [ "$n" -lt 16 ]; then echo "only $n binaries ran; expected all 16" >&2 exit 1 fi echo "$n binaries ran and reported themselves" - name: A tarball, and its checksum shell: bash run: | # On a tag this is v0.2.0; on a pull request it is "41/merge", # whose slash would become a directory in the tarball. A push to # main is named for the canary it will be published as. Anything # else is not a version and is just called dev. case "${GITHUB_EVENT_NAME}:${GITHUB_REF}" in *:refs/tags/v[0-9]*) version="${GITHUB_REF_NAME}" ;; push:refs/heads/main) version="v$(node npm/canary.js)" ;; *) version="dev" ;; esac name="opscope-${version}-${{ matrix.target }}" mkdir -p "dist/$name" # The binaries, repository docs, and each widget's owned README, # AI configuration guide, and settings declaration. for b in target/${{ matrix.target }}/release/*; do [ -f "$b" ] && [ -x "$b" ] || continue case "$b" in *.d|*.rlib|*.dSYM) continue ;; esac cp "$b" "dist/$name/" done cp -r docs README.md LICENSE config.example.json "dist/$name/" mkdir -p "dist/$name/widgets/src/widgets" "dist/$name/widgets/src/launcher" cp widgets/src/launcher/README.md widgets/src/launcher/help.txt \ "dist/$name/widgets/src/launcher/" for widget in widgets/src/widgets/*; do # The glob is every entry. refresh_wake.rs sits here and is a # source file, not a widget. Copying docs out of it is # `cannot stat .../README.md` and the publish stops. A widget # is a directory. A directory with no CONFIGURE.md still fails # this copy, as it did before. [ -d "$widget" ] || continue stem="$(basename "$widget")" mkdir -p "dist/$name/widgets/src/widgets/$stem" cp "$widget/README.md" "$widget/CONFIGURE.md" \ "dist/$name/widgets/src/widgets/$stem/" if [ -f "$widget/settings.json" ]; then cp "$widget/settings.json" "dist/$name/widgets/src/widgets/$stem/" fi done tar -C dist -czf "$name.tar.gz" "$name" # shasum is on both; sha256sum is not on macOS. shasum -a 256 "$name.tar.gz" > "$name.tar.gz.sha256" ls -la "$name.tar.gz" - name: Debian package from the tagged Linux build if: matrix.target == 'x86_64-unknown-linux-gnu' && startsWith(github.ref, 'refs/tags/v') run: node debian/package.js "${GITHUB_REF_NAME#v}" target/x86_64-unknown-linux-gnu/release . - uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0 with: name: ${{ matrix.target }} path: | opscope-*.tar.gz opscope-*.tar.gz.sha256 opscope_*_amd64.deb opscope_*_amd64.deb.sha256 if-no-files-found: error debian-lifecycle: needs: build if: startsWith(github.ref, 'refs/tags/v') runs-on: ubuntu-22.04 permissions: contents: read strategy: fail-fast: false matrix: image: ['ubuntu:22.04', 'debian:12', 'debian:11'] steps: - uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5.1.0 with: persist-credentials: false - uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0 with: name: x86_64-unknown-linux-gnu path: artifacts - name: Verify and install the release package env: IMAGE: ${{ matrix.image }} run: | set -euo pipefail (cd artifacts && sha256sum -c opscope_*_amd64.deb.sha256) node -e 'console.log(require("./npm/platform").binsFromManifest(process.cwd()).join("\n"))' > /tmp/opscope-expected-binaries mode=supported if [ "$IMAGE" = debian:11 ]; then mode=old-glibc; fi docker run --rm -v "$PWD:/work:ro" -v /tmp/opscope-expected-binaries:/expected-binaries:ro "$IMAGE" \ bash /work/debian/lifecycle.sh "/work/artifacts/opscope_${GITHUB_REF_NAME#v}_amd64.deb" "$mode" /expected-binaries publish: needs: [build, debian-lifecycle] runs-on: ubuntu-22.04 # A tag, and only a tag - whatever started the run. Dispatching at a # branch exercises the whole build and stops here, so the workflow can # be tested without leaving a release behind under a version nobody # meant to cut. Dispatching at a tag is a real release, and is how # tag-release.yml gets here. if: startsWith(github.ref, 'refs/tags/v') # One tagged publish at a time. Untagged `npm publish` moves # `latest` in the same write, so two overlapping tagged runs # can interleave their four packages and an older run finishing # last rolls `opscope@latest` backwards. tag-release.yml # dispatches this workflow without waiting, which is how two # tags overlap. cancel-in-progress is false so a second job # waits rather than killing a publish mid-flight. GitHub still # keeps only one pending: a third enqueue drops the waiting # job. Re-dispatch that tag. # # The group is shared across tags and unique per run otherwise. # Concurrency is joined before the job-level `if`, so a pull # request's skipped publish would otherwise sit in the same # slot as a real release. # # The latest-is-newer check in the publish step is the other # half: concurrency orders the writes, the check refuses a # queued older tag if a newer publish already owns `latest`. concurrency: group: ${{ startsWith(github.ref, 'refs/tags/v') && 'npm-release-publish' || format('npm-release-publish-{0}', github.run_id) }} cancel-in-progress: false # Only publication needs contents: write. id-token is for npm trusted # publishing — OIDC, no secret — the only path left after classic # automation tokens were revoked and is the one this repo uses. permissions: contents: write id-token: write steps: - uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5.1.0 with: fetch-depth: 0 - uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0 with: path: artifacts merge-multiple: true - name: Notes for this release run: | # The top section of CHANGELOG.md, which release-pr.yml wrote # when it prepared this version. Taking it from the file rather # than regenerating means the notes on the release are the same # text that was reviewed in the release PR, character for # character - a changelog regenerated here could differ if a # commit landed in between. awk '/^## \[/{n++} n==1' CHANGELOG.md > CHANGELOG-release.md if [ ! -s CHANGELOG-release.md ]; then echo "no section found in CHANGELOG.md for this release" >&2 exit 1 fi cat CHANGELOG-release.md # The four npm packages are generated from the tarballs this # job just built, not maintained in git. That is what keeps # `npx opscope@0.2.0` and `v0.2.0` the # same binaries: there is no second copy to forget to bump. # # npm first, then the GitHub release. A missing # trusted-publisher setup fails on the first package and # leaves nothing on either side, which is agreement. The # four publishes are not atomic, though: a later package # can fail after earlier ones have reached npm. The GitHub # release is then not created, but npm is partly published. # Inspect all four versions before retrying the tag; see # docs/releasing.md. The other order leaves a GitHub # release whose version npm has never heard of, and # `gh release create` will not run twice. # # This job also advertises: `npm publish` with no `--tag` moves # `latest` in the same registry write that creates the version. # See the note on the publish line for the split that was tried # instead and why it was backed out. - uses: actions/setup-node@249970729cb0ef3589644e2896645e5dc5ba9c38 # v6.5.0 with: node-version: "22" # Keep package caching disabled in the privileged OIDC publish job. package-manager-cache: false registry-url: https://registry.npmjs.org - name: npm that can do trusted publishing run: | # Node 22 ships npm 10.x. Trusted publishing's OIDC # handshake needs 11.5.1 or later; without it the # no-token path never attempts OIDC and 404s. npm install -g npm@11.5.1 test "$(npm --version)" = "11.5.1" - name: Pack the npm packages from those tarballs run: | set -euo pipefail version="${GITHUB_REF_NAME#v}" node npm/pack.js --version "$version" --artifacts artifacts --out npm-dist ls -la npm-dist - name: Publish to npm run: | set -euo pipefail # Trusted publishing is the whole story here: id-token: # write plus --provenance, and no secret anywhere in this # workflow. Classic automation tokens were revoked in # November 2025 and granular write tokens expire after 90 # days, so a stored credential is a thing that fails # silently on a release day months from now. # # setup-node with registry-url always writes # _authToken=${NODE_AUTH_TOKEN} into .npmrc, and any # credential at all - including an empty one, which is a # 401 rather than an anonymous request - makes npm skip the # OIDC exchange. NODE_AUTH_TOKEN is never set now, so this # always runs; it is what clears the line setup-node wrote. npm config delete '//registry.npmjs.org/:_authToken' || true npm config delete always-auth || true version="${GITHUB_REF_NAME#v}" # Refuse if latest already names a newer version on any # of the four. Concurrency lets only one publish run at # a time, but an older run queued behind a newer one # would otherwise move latest backwards the moment it # writes. Names come from npm/platform.js, the same # list pack.js publishes. node npm/refuse-stale-latest.js "$version" publish() { local dir="$1" local name published_sha # A relative path with no ./ is a package name to # require(), so this used to look in node_modules and # die with MODULE_NOT_FOUND before it reached npm. # readFileSync is a file on disk. name=$(node -p 'JSON.parse(require("fs").readFileSync(process.argv[1], "utf8")).name' "$dir/package.json") if npm view "${name}@${version}" version >/dev/null 2>&1; then # Skip is for retrying the same commit. npm will not # replace a version, so a package already published # from a different SHA is frozen — moving the tag and # publishing the rest would mix two commits under one # version. Cut the next one. published_sha=$(npm view "${name}@${version}" gitHead 2>/dev/null || true) published_sha=$(printf '%s' "$published_sha" | tr -d '[:space:]') # Fail closed: an empty or non-SHA gitHead cannot prove this # is the same commit, and skipping would mix versions. if [[ ! "$published_sha" =~ ^[0-9a-f]{40}$ ]]; then echo "${name}@${version} is already on npm but gitHead is missing or unreadable; cannot prove it is ${GITHUB_SHA}. Cut the next version." >&2 exit 1 fi if [ "$published_sha" != "$GITHUB_SHA" ]; then echo "${name}@${version} is already on npm from ${published_sha}; this run is ${GITHUB_SHA}. Cut the next version." >&2 exit 1 fi echo "${name}@${version} is already on npm from this commit" else # A path with a slash and no ./ is github shorthand # (owner/repo). The first 0.2.1 publish then ran # `git ls-remote ssh://git@github.com/npm-dist/opscope-darwin-arm64.git` # and died 128 before it reached the registry. # # No --tag, so this write creates the version and moves # `latest` at once. That buys a window: npm cannot serve # a version for some minutes after taking it - four, # measured on v0.16.0 - and for those minutes `latest` # names a version `npx opscope@latest` resolves and then # fails to fetch. # # That window is a known cost, weighed and accepted, not # an oversight. The careful shape was tried: publish # under `--tag next`, which nobody follows, and move # `latest` from a separate job once two clean runners had # installed the version by number. It worked and the # window went away. It was backed out because the second # half never ran once - `npm dist-tag add` needs a stored # credential and trusted publishing cannot supply one: # the npm CLI performs the OIDC exchange inside `npm # publish` and nowhere else. The only credential npm # still issues with write rights expires after 90 days, # so that shape costs a secret renewed four times a year # that fails on a release day, against a propagation # window that is brief, self-correcting and what most of # the ecosystem lives with. Four releases stopped at that # fence before it was removed. # # https://github.com/npm/cli/issues/8547 asks npm to # cover dist-tags with OIDC. The day it lands, the split # can come back: publish with `--tag next` here and move # `latest` after smoke-npm. npm publish "./$dir" --access public --provenance fi } # Platforms first. The launcher lists them as # optionalDependencies at this same version, and npm will # try to fetch them the moment the launcher is published. for pkg in npm-dist/opscope-*; do publish "$pkg" done publish npm-dist/opscope - name: Release env: GH_TOKEN: ${{ github.token }} run: | set -euo pipefail ls -la artifacts # `gh release create` will not run twice, and a re-dispatch at # the same tag is the ordinary way to finish a release whose # npm half landed and whose GitHub half did not. So an # existing *published* release is a thing to walk past, not # to fail on. A draft still is a failure: it is what a # half-finished upload leaves behind, and skipping it would # ship a release nobody can see. draft=$(gh release view "$GITHUB_REF_NAME" --json isDraft \ --jq .isDraft 2>/dev/null || true) if [ "$draft" = "true" ]; then echo "a draft release for $GITHUB_REF_NAME is in the way; delete it and re-dispatch" >&2 exit 1 fi if [ "$draft" = "false" ]; then echo "$GITHUB_REF_NAME is already released; leaving it alone" exit 0 fi gh release create "$GITHUB_REF_NAME" \ --title "$GITHUB_REF_NAME" \ --notes-file CHANGELOG-release.md \ artifacts/*.tar.gz artifacts/*.tar.gz.sha256 \ artifacts/*_amd64.deb artifacts/*_amd64.deb.sha256 # Main, published as a prerelease under the `canary` dist-tag. npm # requires --tag to publish a prerelease at all, and a publish with # --tag moves that tag and nothing else, so `latest` stays on the last # release. This is the same trusted-publishing write as `publish` - # OIDC inside `npm publish`, no stored credential - which is why it # works where moving a dist-tag after the fact (npm/cli#8547) does not. canary: needs: build if: github.event_name == 'push' && github.ref == 'refs/heads/main' runs-on: ubuntu-22.04 permissions: contents: read id-token: write outputs: version: ${{ steps.pack.outputs.version }} # false when a newer canary already owns the tag and this run # left it alone, so smoke-canary has nothing of its to install. published: ${{ steps.publish.outputs.published }} steps: - uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5.1.0 with: # canary.js reads the commit's time and sha. fetch-depth: 0 persist-credentials: false - uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0 with: path: artifacts merge-multiple: true - uses: actions/setup-node@249970729cb0ef3589644e2896645e5dc5ba9c38 # v6.5.0 with: node-version: "22" # Keep package caching disabled in the privileged OIDC publish job. package-manager-cache: false registry-url: https://registry.npmjs.org - name: npm that can do trusted publishing run: | npm install -g npm@11.5.1 test "$(npm --version)" = "11.5.1" - name: Pack the canary from those tarballs id: pack run: | set -euo pipefail version="$(node npm/canary.js)" echo "version=$version" >> "$GITHUB_OUTPUT" node npm/pack.js --version "$version" --artifacts artifacts --out npm-dist ls -la npm-dist - name: Publish to npm under canary id: publish run: | set -euo pipefail # The same reason as publish: any credential at all, an empty # one included, makes npm skip the OIDC exchange. npm config delete '//registry.npmjs.org/:_authToken' || true npm config delete always-auth || true version="${{ steps.pack.outputs.version }}" # The concurrency group cancels an older run, but a re-run of # an older commit after a newer one published would still move # the tag backwards. Its version would be new to npm, so the # already-published skip below would not catch it. current=$(npm view opscope@canary version 2>/dev/null || true) if ! node npm/canary.js --may-take-tag "$current" "$version"; then echo "leaving canary on ${current}; ${version} is older" echo "published=false" >> "$GITHUB_OUTPUT" exit 0 fi canary() { local pkg="$1" local name name=$(node -p 'JSON.parse(require("fs").readFileSync(process.argv[1], "utf8")).name' "$pkg/package.json") # The version names its commit, so one that is already on # npm is a re-run of this commit and is done. if npm view "${name}@${version}" version >/dev/null 2>&1; then echo "${name}@${version} is already on npm" else npm publish "./$pkg" --tag canary --access public --provenance fi } # Platforms first, as in publish: the launcher names them as # optionalDependencies at this same version. for pkg in npm-dist/opscope-*; do canary "$pkg" done canary npm-dist/opscope echo "published=true" >> "$GITHUB_OUTPUT" echo "npx opscope@canary is now ${version}" # Reports, like the release smoke jobs; it gates nothing, because the # canary tag has already moved. By version, not by tag, for the same # reason, and checked against the commit rather than the version: the # binary says the release it was built on (Cargo.toml) and the commit. smoke-canary: needs: canary if: needs.canary.outputs.published == 'true' runs-on: ubuntu-22.04 steps: - uses: actions/setup-node@249970729cb0ef3589644e2896645e5dc5ba9c38 # v6.5.0 with: node-version: "22" package-manager-cache: false - name: npx fetches this canary env: VERSION: ${{ needs.canary.outputs.version }} run: | set -euo pipefail sha="${GITHUB_SHA:0:7}" said="" for attempt in $(seq 1 16); do if said=$(npx -y "opscope@${VERSION}" --version 2>&1); then break fi echo "attempt ${attempt}: not yet installable" echo "$said" said="" sleep 30 done if [ -z "$said" ]; then echo "opscope@${VERSION} was not installable from npm eight minutes after publish" >&2 exit 1 fi echo "$said" # `opscope 2.2.0 (1a2b3c4, 2026-10-27)`: the release it was # built on, then the commit, which is the part that is this run. # git may abbreviate past seven, so the sha is a prefix. if ! printf '%s\n' "$said" | grep -q "^opscope [^ ]* (${sha}[0-9a-f]*,"; then echo "npx opscope@${VERSION} did not report commit ${sha}" >&2 exit 1 fi apt-repository: needs: publish if: startsWith(github.ref, 'refs/tags/v') runs-on: ubuntu-22.04 permissions: contents: read steps: # repository_dispatch needs Contents write on apt-repo. Listing # repositories replaces the default scope, so this repo is named # too. The token is not given to the checkout: that checkout does # not push. GITHUB_TOKEN is not a fallback: it cannot write apt-repo. - name: Mint the release app token id: app if: vars.RELEASE_APP_CLIENT_ID != '' uses: actions/create-github-app-token@64ab729a6294000f5aa4a4bc0b73d1f32bc45510 # v3.3.0 with: client-id: ${{ vars.RELEASE_APP_CLIENT_ID }} private-key: ${{ secrets.RELEASE_APP_PRIVATE_KEY }} owner: stealth-factory repositories: opscope,apt-repo permission-contents: write - uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5.1.0 with: persist-credentials: false - name: Notify the shared APT repository of this published release env: GH_TOKEN: ${{ steps.app.outputs.token || secrets.GH_TOKEN }} run: | set -euo pipefail if [ -z "$GH_TOKEN" ]; then echo "::error::Mint the release app token or set GH_TOKEN with Contents write on stealth-factory/apt-repo" exit 1 fi node debian/notify-apt.js homebrew: needs: publish if: startsWith(github.ref, 'refs/tags/v') runs-on: macos-15 permissions: contents: read concurrency: group: ${{ startsWith(github.ref, 'refs/tags/v') && 'homebrew-tap-opscope' || format('homebrew-tap-opscope-{0}', github.run_id) }} cancel-in-progress: false steps: # Contents write updates Formula/opscope.rb on homebrew-tap. The # checkout of this repo does not push, so it keeps the job token. # The formula download below stays on github.token. GITHUB_TOKEN # cannot write the tap, so it is not a fallback for the update. - name: Mint the release app token id: app if: vars.RELEASE_APP_CLIENT_ID != '' uses: actions/create-github-app-token@64ab729a6294000f5aa4a4bc0b73d1f32bc45510 # v3.3.0 with: client-id: ${{ vars.RELEASE_APP_CLIENT_ID }} private-key: ${{ secrets.RELEASE_APP_PRIVATE_KEY }} owner: stealth-factory repositories: opscope,homebrew-tap permission-contents: write - uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5.1.0 with: persist-credentials: false - uses: actions/setup-node@249970729cb0ef3589644e2896645e5dc5ba9c38 # v6.5.0 with: node-version: "22" - name: Generate and test the formula from the public release env: GH_TOKEN: ${{ github.token }} HOMEBREW_NO_AUTO_UPDATE: "1" HOMEBREW_NO_INSTALL_CLEANUP: "1" run: | set -euo pipefail version="${GITHUB_REF_NAME#v}" mkdir -p homebrew-artifacts gh release download "$GITHUB_REF_NAME" --repo "$GITHUB_REPOSITORY" \ --pattern '*apple-darwin.tar.gz*' --dir homebrew-artifacts node homebrew/formula.js "$version" homebrew-artifacts homebrew/opscope.rb brew tap stealth-factory/tap cp homebrew/opscope.rb "$(brew --repo stealth-factory/tap)/Formula/opscope.rb" brew install stealth-factory/tap/opscope brew test stealth-factory/tap/opscope - name: Update the shared Homebrew tap env: GH_TOKEN: ${{ steps.app.outputs.token || secrets.GH_TOKEN }} run: | set -euo pipefail if [ -z "$GH_TOKEN" ]; then echo "::error::Mint the release app token or set GH_TOKEN with Contents write access to stealth-factory/homebrew-tap" exit 1 fi # The commit message is written by homebrew/update-tap.sh. It # has no [skip ci]. An app token commit on the tap's main # starts that repository's push workflows, which the PAT # already did. Silencing them would be a change to the script # this job calls, and this job still passes the token as # GH_TOKEN. bash homebrew/update-tap.sh "${GITHUB_REF_NAME#v}" homebrew-artifacts # Both ways in, tried the way somebody would try them, after the release # exists. The build job proves the binaries work; nothing proved the paths # that deliver them, and those fail differently: npm can answer that a # version exists before its tarball is reachable, and the module fetches # release assets by name, so a rename in the packaging step would 404 for # everyone and be green here. # # Two jobs, where these were two steps of one. In that order, under # `set -e`: the npx retry loop can spend eight minutes failing, and the # module check then never ran at all - so a release broken on both paths # reported one problem and left the other question unanswered, which on # screen is indistinguishable from an answer of no. Neither can mask the # other now. # # NEITHER OF THESE IS A GATE. Both run after `publish`, and `publish` has # already moved `latest` - so by the time either of them can look, the # release is out and everyone who asks npm for `opscope` is being given # this version. They report; they do not decide. A failure here fails the # run loudly and that is the whole of what it does: it tells you a release # that has already happened is bad, which is worth knowing and is not the # same as having stopped it. # # smoke-npm used to be a gate - `promote` waited on it and moved `latest` # only if it passed. That job is gone (see the publish step's note on # npm/cli#8547), and a red smoke-npm now means a bad `latest` to be fixed # by cutting the next version, not a release held back. smoke-npm: needs: publish if: startsWith(github.ref, 'refs/tags/v') strategy: fail-fast: false matrix: runs-on: [ubuntu-22.04, macos-15] runs-on: ${{ matrix.runs-on }} # No checkout. Nothing here reads the repository, and what is being # tested is what a stranger with node and nothing else gets. steps: - uses: actions/setup-node@249970729cb0ef3589644e2896645e5dc5ba9c38 # v6.5.0 with: node-version: "22" # Keep this a clean install, as a user with only Node would get. package-manager-cache: false - name: npx fetches this version shell: bash run: | set -euo pipefail version="${GITHUB_REF_NAME#v}" # By version, not by tag. `latest` already names this version, # so asking for it by tag would answer a different question; # what is being asked is whether the exact version npm # accepted is one npm can serve. # # The registry can answer `npm view` before the tarball is # reachable from every edge, and the launcher's platform package # is a separate publish that npm fetches on install. So this # retries rather than failing early. v0.16.0 measured it: four # minutes between npm taking the publish and npm being able to # answer for it, so a three-minute window failed a release that # was fine. Eight, against an observed four. for attempt in $(seq 1 16); do if said=$(npx -y "opscope@${version}" --version 2>&1); then break fi echo "attempt ${attempt}: not yet installable" echo "$said" said="" sleep 30 done if [ -z "${said:-}" ]; then echo "opscope@${version} was still not installable from npm eight" >&2 echo "minutes after publish, which is long past propagation: treat" >&2 echo "this as a release that did not land, not a slow registry." >&2 echo >&2 echo "This job reports; it does not gate. The publish already" >&2 echo "happened and latest already names ${version}, so npx opscope" >&2 echo "is pointing at something that cannot be fetched. Nothing" >&2 echo "here can undo that: fix it forward by cutting the next" >&2 echo "version. Do not unpublish." >&2 exit 1 fi echo "$said" # `opscope 0.16.0 (abc1234, 2026-09-13)` - the version is the # second field, and it has to be the one this tag published. # stderr is folded into said, so an npx warning can sit on # line 1; take the banner, not the first line. got=$(printf '%s' "$said" | awk '/^opscope / { print $2; exit }') if [ -z "$got" ]; then echo "npx did not print an opscope version line" >&2 exit 1 fi if [ "$got" != "$version" ]; then echo "npx gave ${got}, this tag is ${version}" >&2 exit 1 fi smoke-module: needs: publish if: startsWith(github.ref, 'refs/tags/v') strategy: fail-fast: false matrix: runs-on: [ubuntu-22.04, macos-15] runs-on: ${{ matrix.runs-on }} steps: - uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5.1.0 with: # Do not leave the checkout token in .git while running the # module's downloaded binaries with the workspace as cwd. persist-credentials: false - name: The Luvus module's build step fetches this version shell: bash run: | set -euo pipefail version="${GITHUB_REF_NAME#v}" # By path, not by name. A macOS runner has failed a release test # with `sh: No such file or directory` when PATH was not what the # step assumed, and a test that can fail for a reason it is not # testing teaches people to press the button again. /bin/sh luvus/build.sh said=$(./luvus/bin/opscope --version) echo "$said" got=$(printf '%s' "$said" | awk 'NR==1{print $2}') if [ "$got" != "$version" ]; then echo "the module fetched ${got}, this tag is ${version}" >&2 exit 1 fi # Every pane the manifest declares has to be a binary that is # there. A pane naming a binary the release did not carry is a # menu entry that dies on open. pane-ids.sh reads only # [[panes]] so an action id is not demanded as a binary. missing=0 while read -r pane; do [ "$pane" = "menu" ] && continue if [ ! -x "luvus/bin/${pane}" ]; then echo "the manifest declares a ${pane} pane and the release has no such binary" >&2 missing=1 fi done <<< "$(/bin/sh luvus/pane-ids.sh luvus-module.toml)" [ "$missing" = 0 ] echo "every declared pane has a binary"