Skip to content

Self-improving AI Employees for everyone

ci(release): route the GitHub Packages publish through ~/.npmrc; let dispatch republish a tag

trohitgcf4d8009d718
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index 9e484adc..f9c0e9d7 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -1,7 +1,11 @@
# Release workflow: predeploy gate, publish the registry tarball to npmjs and
# GitHub Packages with bun. No npm CLI and no setup-node: bun packs, authenticates
# (~/.npmrc written from the job's token) and publishes.
-# Triggers on version tag push.
+#
+# Triggers on version tag push. Manual dispatch publishes an EXISTING tag
+# again, to one or both registries (a lapsed token, a failed mirror): the
+# publish jobs check out that tag so the tarball is the tag's tree, while the
+# predeploy gate runs against the dispatching branch as it always has.
name: Release
@@ -9,6 +13,16 @@ on:
push:
tags: ['v*.*.*']
workflow_dispatch:
+ inputs:
+ tag:
+ description: Existing release tag to publish again (e.g. v0.2.0)
+ required: true
+ type: string
+ registries:
+ description: Registries to publish to
+ type: choice
+ options: [both, npmjs, github-packages]
+ default: both
permissions:
contents: read
@@ -20,12 +34,14 @@ jobs:
publish-npm:
name: Publish to npm
needs: predeploy
+ if: github.event_name == 'push' || inputs.registries != 'github-packages'
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
+ ref: ${{ inputs.tag || github.ref }}
persist-credentials: false
- uses: ./.github/actions/setup
- run: bun install --frozen-lockfile
@@ -43,6 +59,7 @@ jobs:
publish-github-packages:
name: Publish to GitHub Packages
needs: predeploy
+ if: github.event_name == 'push' || inputs.registries != 'npmjs'
runs-on: ubuntu-latest
permissions:
contents: read
@@ -50,22 +67,21 @@ jobs:
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
+ ref: ${{ inputs.tag || github.ref }}
persist-credentials: false
- uses: ./.github/actions/setup
- run: bun install --frozen-lockfile
- run: bun run build
- run: python -m cli version sync
- - name: Configure scoped package
- run: |
- bun -e "
- const pkg = require('./package.json');
- pkg.name = '@zeenie-ai/opencompany';
- pkg.publishConfig = { registry: 'https://npm.pkg.github.com' };
- require('fs').writeFileSync('package.json', JSON.stringify(pkg, null, 2));
- "
- # GitHub Packages uses the repository-scoped GITHUB_TOKEN.
+ # bun 1.4 ignores package.json publishConfig.registry, and it keeps an
+ # .npmrc token only for the registry that same file points at (the
+ # default or a scoped one), so the scope is routed to GitHub Packages
+ # here, next to the token. The v0.2.0 mirror publish went to npmjs
+ # with this GitHub token and failed with "missing authentication"
+ # before that was known. GitHub Packages uses the repository-scoped
+ # GITHUB_TOKEN.
- name: Configure GitHub Packages credentials
- run: printf '//npm.pkg.github.com/:_authToken=%s\n' "$NPM_TOKEN" > ~/.npmrc
+ run: printf '@zeenie-ai:registry=https://npm.pkg.github.com/\n//npm.pkg.github.com/:_authToken=%s\n' "$NPM_TOKEN" > ~/.npmrc
env:
NPM_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- run: bun publish
diff --git a/cli/tests/test_release_pipeline_config.py b/cli/tests/test_release_pipeline_config.py
index 802f9ffa..74a22d46 100644
--- a/cli/tests/test_release_pipeline_config.py
+++ b/cli/tests/test_release_pipeline_config.py
@@ -469,25 +469,47 @@ def test_npm_release_publishes_public_package_with_bun(release_yml: dict):
assert not any("setup-node" in str(step.get("uses", "")) for step in release_yml["jobs"]["publish-npm"]["steps"])
-def test_github_packages_release_keeps_github_owner_scope(release_yml: dict):
+def test_github_packages_release_routes_the_scope_through_npmrc(release_yml: dict):
+ """bun 1.4 ignores package.json ``publishConfig.registry``, and it keeps
+ an .npmrc token only for the registry that same file points at (the
+ default or a scoped one) -- ``--registry`` on the command line comes too
+ late. So the scope route and the token must sit together in ~/.npmrc.
+ Locked after the v0.2.0 mirror publish went to npmjs carrying the GitHub
+ token and died with "missing authentication" (docs-internal/errors.md
+ #24)."""
steps = _run_steps(release_yml["jobs"]["publish-github-packages"])
- configure = next(
- step for step in steps if "pkg.name = '@zeenie-ai/opencompany'" in step["run"]
- )
- assert configure["run"].lstrip().startswith("bun -e")
-
- registry_assignment = next(
- line.strip()
- for line in configure["run"].splitlines()
- if line.strip().startswith("pkg.publishConfig =")
- )
- assert registry_assignment == (
- "pkg.publishConfig = { registry: 'https://npm.pkg.github.com' };"
- )
- assert any(step["run"] == "bun publish" for step in steps)
auth = next(step for step in steps if "_authToken" in step["run"])
- assert "npm.pkg.github.com" in auth["run"]
+ assert "@zeenie-ai:registry=https://npm.pkg.github.com/" in auth["run"]
+ assert "//npm.pkg.github.com/:_authToken=" in auth["run"]
assert auth["env"]["NPM_TOKEN"] == "${{ secrets.GITHUB_TOKEN }}"
+ assert any(step["run"] == "bun publish" for step in steps)
+ assert not any("publishConfig" in step["run"] for step in steps)
+
+
+def test_release_dispatch_republishes_an_existing_tag(release_yml: dict):
+ """Manual dispatch exists to redo the publish of a tag that already
+ exists (a lapsed token, a failed mirror). It must check out that tag --
+ a shallow checkout of main has no tags for ``company version sync`` and
+ would otherwise pack untagged code -- and let one registry be chosen so
+ a registry that already holds the version is not published to again."""
+ triggers = release_yml.get("on") or release_yml[True]
+ inputs = triggers["workflow_dispatch"]["inputs"]
+ assert inputs["tag"]["required"] is True
+ assert set(inputs["registries"]["options"]) == {"both", "npmjs", "github-packages"}
+ assert inputs["registries"]["default"] == "both"
+
+ for job_name, skipped_for in (
+ ("publish-npm", "github-packages"),
+ ("publish-github-packages", "npmjs"),
+ ):
+ job = release_yml["jobs"][job_name]
+ assert job["if"] == (
+ f"github.event_name == 'push' || inputs.registries != '{skipped_for}'"
+ )
+ checkout = next(
+ step for step in job["steps"] if "actions/checkout" in str(step.get("uses", ""))
+ )
+ assert checkout["with"]["ref"] == "${{ inputs.tag || github.ref }}"
@pytest.mark.parametrize("scope", ["@zeenie", "@zeenie-ai"])
diff --git a/docs-internal/ci_cd.md b/docs-internal/ci_cd.md
index d8df29cd..111c7dac 100644
--- a/docs-internal/ci_cd.md
+++ b/docs-internal/ci_cd.md
@@ -104,7 +104,7 @@ Reusable `workflow_call` workflow with four independent jobs (no plan/change-det
| Trigger | Behaviour |
|---------|-----------|
| Push of `v*.*.*` tag | predeploy gate, then publish to npm + GitHub Packages |
-| `workflow_dispatch` | Same job graph (manual run; there is no dry-run switch) |
+| `workflow_dispatch` | Publish an existing tag again, to one or both registries (inputs `tag`, `registries`); the publish jobs check out that tag, the predeploy gate runs against the dispatching branch. Never cuts a new version |
The workflow default is `contents: read`. Publishing permissions are scoped to the job that needs them: the npmjs job needs nothing beyond `contents: read` (bun authenticates with the `NPM_TOKEN` it writes to `~/.npmrc`; npm provenance attestation, and the `id-token: write` it needed, went away with the npm CLI), while GitHub Packages receives `packages: write`. Checkout credentials are not persisted in either publishing job.
@@ -119,7 +119,7 @@ publish-npm publish-github-packages
| |
+- build +- build
+- cli version sync +- cli version sync
- +- write ~/.npmrc + bun pm whoami +- rewrite package name (bun -e)
+ +- write ~/.npmrc + bun pm whoami +- write ~/.npmrc (scope route + token)
+- publish canonical package +- publish mirror package
@zeenie-ai/opencompany @zeenie-ai/opencompany
npmjs, bun publish --access public npm.pkg.github.com, bun publish
@@ -127,7 +127,7 @@ publish-npm publish-github-packages
- Both publish jobs `needs: predeploy`, run on `ubuntu-latest`, and share the same prefix: immutable `actions/checkout` with `persist-credentials: false` → composite setup → `bun install --frozen-lockfile` → `bun run build` → `python -m cli version sync`. There is no `setup-node` step and no npm CLI anywhere in the release: bun packs, authenticates and publishes.
- `publish-npm` — writes `//registry.npmjs.org/:_authToken=<NPM_TOKEN>` to `~/.npmrc`, validates it with `bun pm whoami`, then publishes the canonical public npmjs package `@zeenie-ai/opencompany` via `bun publish --access public`. npm provenance attestation was an npm-CLI feature and is gone with it.
-- `publish-github-packages` — rewrites `package.json` `name` to `@zeenie-ai/opencompany` and sets `publishConfig.registry = https://npm.pkg.github.com` (a `bun -e` one-liner), writes the `//npm.pkg.github.com/:_authToken=<GITHUB_TOKEN>` line to `~/.npmrc`, then `bun publish`.
+- `publish-github-packages` — writes `@zeenie-ai:registry=https://npm.pkg.github.com/` and the `//npm.pkg.github.com/:_authToken=<GITHUB_TOKEN>` line to `~/.npmrc`, then a plain `bun publish`. bun 1.4 ignores `publishConfig.registry`, and it keeps an `.npmrc` token only for the registry that same file points at, so the route and the token must sit together; the v0.2.0 mirror publish went to npmjs with the GitHub token and failed with `missing authentication` before this was known ([errors.md #24](./errors.md#24-github-packages-publish-fails-with-missing-authentication-although-the-job-wrote-a-token-for-npmpkggithubcom)).
Both registries use `@zeenie-ai/opencompany`, matching the npm and GitHub
organization owned by the project.
@@ -141,15 +141,17 @@ There is currently no audit gate, no PyPI publish, no SLSA `attest-build-provena
The tag is the version. Everything else is derived from it, and there is no
CHANGELOG file: the annotated tag's message is the release notes (first line =
release title, the rest = body), which `desktop-release.yml` copies onto the
-GitHub Release. Nothing publishes until a `v*.*.*` tag is pushed. Tag push is
-also the only trigger that works: a `workflow_dispatch` run has a shallow
-checkout with no tags for `company version sync` to read.
+GitHub Release. Nothing publishes until a `v*.*.*` tag is pushed. A
+`workflow_dispatch` run never cuts a version: it publishes an existing tag
+again (inputs `tag` and `registries`), which is the retry path when a token
+had lapsed or one registry failed.
1. **Pre-flight.** `main` green on CI. `NPM_TOKEN` unexpired: the
`bun pm whoami` preflight fails only the npmjs job, after the predeploy
gate, while GitHub Packages and the installers still publish, so a lapsed
- token means a partial release (rotate the secret, then
- `gh run rerun <id> --failed`). `bun publish --dry-run --access public`
+ token means a partial release (rotate the secret, then dispatch the
+ Release workflow with `tag` set to the release and `registries` set to
+ the registry that failed). `bun publish --dry-run --access public`
packs cleanly from the checkout.
2. **Bump.** `python -m cli version sync vX.Y.Z` writes the version into the
root, client and desktop `package.json`, `pyproject.toml` and
diff --git a/docs-internal/errors.md b/docs-internal/errors.md
index d9fc243d..4ca4d1f1 100644
--- a/docs-internal/errors.md
+++ b/docs-internal/errors.md
@@ -521,3 +521,11 @@ bun add -g @zeenie-ai/opencompany
```
`install.sh`, `install.ps1` and the cloud-init templates seed that manifest before `bun add -g`, so the installer path never hits this. For the PATH variant open a new shell, or `export PATH="$HOME/.bun/bin:$PATH"` (`$env:USERPROFILE\.bun\bin` on Windows). Nothing in OpenCompany depends on where the global package lives: `company provision` runs from the shim's own package root, `uninstall.sh` uses `bun remove -g` rather than listing, and the installers address the shim through `bun pm bin -g`.
+
+## 24. GitHub Packages publish fails with `missing authentication` although the job wrote a token for `npm.pkg.github.com`
+
+**Symptom**: The `Publish to GitHub Packages` job of `release.yml` packs the tarball and then aborts with `error: missing authentication (run bunx npm login)`, while `Publish to npm` in the same run succeeds. First seen on v0.2.0, the first release published by bun.
+
+**Root cause**: Two bun 1.4 behaviours. `bun publish` ignores `publishConfig.registry` in package.json, so the `bun -e` rewrite the job used to do was inert and the publish went to the default registry, npmjs, where that job holds no token. And bun keeps an `.npmrc` `//host/:_authToken` line only when `host` is the registry that same file points at (the default `registry=` or a scoped `@scope:registry=`) at parse time; `--registry` on the command line comes too late, so a token for `npm.pkg.github.com` on its own is dropped whichever of `~/.npmrc` or the project `.npmrc` carries it. Verified with `bun publish --dry-run`: with only `publishConfig.registry` it prints `Registry: https://registry.npmjs.org/`; with `--registry https://npm.pkg.github.com/` and the token in either file it still reports `missing authentication`; with `registry=https://npm.pkg.github.com/` or `@zeenie-ai:registry=https://npm.pkg.github.com/` next to the token it prints `Registry: https://npm.pkg.github.com/` and succeeds.
+
+**Fix**: The job writes the scope route and the token into one `~/.npmrc` (`@zeenie-ai:registry=https://npm.pkg.github.com/` plus `//npm.pkg.github.com/:_authToken=<GITHUB_TOKEN>`) and runs a plain `bun publish`; the package.json rewrite is gone. To publish a mirror that failed this way, dispatch the Release workflow with `tag` set to the release and `registries` set to `github-packages`; the job checks out that tag. Locked by `test_github_packages_release_routes_the_scope_through_npmrc` in `cli/tests/test_release_pipeline_config.py`.