Skip to content

Commit 7a20ca8

Browse files
fix(publish): authenticate to GitHub Packages before installing (#92)
A package whose own dependencies live on GitHub Packages could not be released. Both publish blocks ran `bun install` with no registry credentials, so a private first-party dependency failed with 401 then 403 and the publish step never ran. connect-basic hit this on v0.10.0: the version was bumped and the GitHub Release created, but no artifact was ever published. The token is now written to ~/.npmrc before install. Deliberately credentials only — no scope mapping. The existing ordering comment explains why the owner's scope must not be remapped this early: a package being published to both registries for the first time would stop resolving its own npmjs.org scope-siblings. Supplying a token for the host without touching the registry mapping fixes the install and preserves that property, because a repository that genuinely routes a scope to GitHub Packages already declares it in its own .npmrc. This is latent for any published package with a first-party dependency, not specific to connect-basic — hono-ts uses this workflow and carries @photon-hq/error as a devDependency. publish-npm has the same shape and is not covered here: it only accepts an npm-token, so giving it GitHub Packages credentials means a new input, and no package currently publishes to npmjs.org with a private first-party dependency. Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 43f12a6 commit 7a20ca8

2 files changed

Lines changed: 28 additions & 2 deletions

File tree

.github/blocks/publish-github-package/action.yaml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,23 @@ runs:
4141
with:
4242
bun-version: ${{ inputs.bun-version }}
4343

44+
# Credentials only, no scope mapping. A package whose own dependencies
45+
# live on GitHub Packages needs a token to install them, but remapping the
46+
# owner's scope here would break a package being published to both
47+
# registries for the first time — its npmjs.org scope-siblings would stop
48+
# resolving. Supplying the token without touching the registry mapping
49+
# fixes the former and preserves the latter; a repository that routes a
50+
# scope to GitHub Packages does so in its own .npmrc.
51+
- name: Authenticate to GitHub Packages
52+
shell: bash
53+
env:
54+
GITHUB_PACKAGES_TOKEN: ${{ inputs.github-token }}
55+
run: |
56+
printf '//npm.pkg.github.com/:_authToken=%s\n' \
57+
"$GITHUB_PACKAGES_TOKEN" >> "$HOME/.npmrc"
58+
4459
# Install and build before mapping the repository owner's npm scope to
45-
# GitHub Packages. This keeps ordinary npmjs.org dependencies resolvable
46-
# when a package is being published to both registries for the first time.
60+
# GitHub Packages, for the reason above.
4761
- name: Install dependencies
4862
shell: bash
4963
working-directory: ${{ inputs.working-directory }}

.github/blocks/publish-github-packages/action.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,18 @@ runs:
4242

4343
# Keep dependency installation on its existing registry configuration. The
4444
# GitHub Packages scope mapping is added only after dependencies are ready.
45+
# Credentials only, no scope mapping — see publish-github-package for the
46+
# reasoning. A package whose own dependencies live on GitHub Packages needs
47+
# a token to install them; remapping the owner's scope this early would
48+
# break one being published to both registries for the first time.
49+
- name: Authenticate to GitHub Packages
50+
shell: bash
51+
env:
52+
GITHUB_PACKAGES_TOKEN: ${{ inputs.github-token }}
53+
run: |
54+
printf '//npm.pkg.github.com/:_authToken=%s\n' \
55+
"$GITHUB_PACKAGES_TOKEN" >> "$HOME/.npmrc"
56+
4557
- name: Install dependencies
4658
shell: bash
4759
run: bun install

0 commit comments

Comments
 (0)