Publish to GitHub Packages in addition to npm - #1152
Open
unblee wants to merge 1 commit into
Open
Conversation
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
WHY
The npm access token this repository publishes with is a granular access token, and those
expire. Every expiry stops the release. Publishing to GitHub Packages as well removes that
dependency for anyone who consumes the packages from there, because the job authenticates
with the
GITHUB_TOKENthe workflow already has.The obvious way to do that is to rename the six packages to the
@wantedlyscope, which iswhat #1146 does. That breaks the consumers. Their lockfiles resolve the unscoped names from
npm today, so a rename means they cannot pick up a new version until they rewrite the name,
and rewriting it points the lockfile at GitHub Packages, which asks for authentication even
for a public package.
So this PR leaves the tree, the lockfile and the published npm names byte-identical to
master, and scopes the manifests inside the release workflow instead, right before thepublish to GitHub Packages. The whole migration is one file.
WHAT
.github/workflows/release.ymlonly.create-release-prgains anoutputs.publishedline. Nothing else about it changes, sothe npm publish, the version bump, the tags and the GitHub Release behave exactly as they
do today.
release-to-github-packagesjob runs after it, gated onneeds.create-release-pr.outputs.published == 'true', so it only fires on an actualrelease and only once npm has already succeeded.
The new job rewrites three fields in each
packages/*/package.jsonwithjqbeforepublishing:
namepublishConfig.registrynpm.pkg.github.comrepositoryhttps://github.com/<owner>/<repo>.gitform. The current value is atree/master/packages/<name>URL, which does not match.repository.directorykeeps the subdirectory information that URL carrieddependenciesis deliberately left alone. The sourcesrequireeach other by the unscopednames, so rewriting the dependency ranges would mean rewriting the sources, the build output
and the snapshots too. Leaving them means
@wantedly/frolinton GitHub Packages resolves itsinternal dependencies from npm — all six are public there, so they resolve.
publishConfig.accessis left alone as well. It does not decide visibility on GitHubPackages; a package's first publish is private regardless, and the visibility is changed from
the package settings page afterwards.
The commit the job makes exists only inside the runner —
lerna publishrefuses to run froma dirty tree. It is never pushed.
Notes for the reviewer
release.ymlhere is written against the post-ci: Update GitHub Actions to latest major versions #1148 shape (@v7,Node 20.x, no
lerna bootstrap), and the base retargets tomasteronce ci: Update GitHub Actions to latest major versions #1148 merges.--no-verify-accessis needed because the rootdevDependenciespinlernaat^4.0.0.It can go once lerna is above 5.2.0.
master, so none of this is exercised by the CI on this PR.The first release after the merge is the real test. If the new job fails, npm has already
published by then, so nothing stops shipping and it can be fixed forward.
have to be switched to public by hand, to match how they are published on npm.