Repository navigation
ci: publish v1 packages under legacy #836
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
roncohen
wants to merge
1
commit into
maintenance/v1
Choose a base branch
from
ci/v1-legacy-channel
base: maintenance/v1
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,12 @@ | ||
| import assert from "node:assert/strict"; | ||
| import { readFileSync } from "node:fs"; | ||
| import { test } from "node:test"; | ||
|
|
||
| import { checkReleasePlan, extendReleasePlan } from "./v1-release.mjs"; | ||
| import { | ||
| checkReleasePlan, | ||
| extendReleasePlan, | ||
| legacyTagPlan, | ||
| } from "./v1-release.mjs"; | ||
|
|
||
| const cli = { | ||
| name: "@reflag/cli", | ||
|
|
@@ -16,7 +21,10 @@ const sdk = { | |
| const plan = { [cli.name]: cli.version, [sdk.name]: sdk.version }; | ||
| const registry = { | ||
| isPublished: async () => false, | ||
| latest: async (name) => (name === cli.name ? "1.0.4" : "1.8.3"), | ||
| tags: async (name) => ({ | ||
| legacy: name === cli.name ? "1.0.4" : "1.8.3", | ||
| latest: "2.0.0", | ||
| }), | ||
| }; | ||
|
|
||
| test("keeps the already versioned CLI and adds versions changed by Changesets", () => { | ||
|
|
@@ -62,8 +70,8 @@ test("rejects a plan that differs from the checked-out packages or specifies a p | |
| } | ||
| }); | ||
|
|
||
| test("does not move latest backward or skip a patch", async () => { | ||
| for (const latest of [ | ||
| test("does not move legacy backward or skip a patch", async () => { | ||
| for (const legacy of [ | ||
| undefined, | ||
| "0.9.9", | ||
| "2.0.0", | ||
|
|
@@ -74,9 +82,117 @@ test("does not move latest backward or skip a patch", async () => { | |
| await assert.rejects( | ||
| checkReleasePlan({ [cli.name]: cli.version }, [cli], { | ||
| ...registry, | ||
| latest: async () => latest, | ||
| tags: async () => ({ legacy, latest: "2.0.0" }), | ||
| }), | ||
| /expected its next stable patch/, | ||
| ); | ||
| } | ||
| }); | ||
|
|
||
| test("can start legacy publishing while latest still points at v1", async () => { | ||
| assert.deepEqual( | ||
| await checkReleasePlan(plan, [cli, sdk], { | ||
| ...registry, | ||
| tags: async (name) => ({ | ||
| latest: name === cli.name ? "1.0.4" : "1.8.3", | ||
| }), | ||
| }), | ||
| ["@reflag/[email protected]", "@reflag/[email protected]"], | ||
| ); | ||
| }); | ||
|
|
||
| const legacyWorkspaces = [ | ||
| { name: "@reflag/browser-sdk", version: "1.7.4" }, | ||
| cli, | ||
| sdk, | ||
| { name: "@reflag/react-native-sdk", version: "0.3.7" }, | ||
| { name: "@reflag/react-sdk", version: "1.7.4" }, | ||
| { name: "@reflag/vue-sdk", version: "1.5.7" }, | ||
| ]; | ||
| const tagRegistry = { | ||
| isPublished: async () => true, | ||
| tags: async () => ({ latest: "2.0.0" }), | ||
| }; | ||
|
|
||
| test("seeds only the six coordinated legacy packages, including pre-1.0 Native", async () => { | ||
| assert.deepEqual( | ||
| await legacyTagPlan( | ||
| [ | ||
| ...legacyWorkspaces, | ||
| { name: "@reflag/management-sdk", version: "0.1.0" }, | ||
| ], | ||
| tagRegistry, | ||
| ), | ||
| legacyWorkspaces.map(({ name, version }) => `${name}@${version}`), | ||
| ); | ||
| }); | ||
|
|
||
| test("legacy tag seeding is idempotent and does not use latest as its target", async () => { | ||
| assert.deepEqual( | ||
| await legacyTagPlan(legacyWorkspaces, { | ||
| ...tagRegistry, | ||
| tags: async (name) => ({ | ||
| latest: "2.0.0", | ||
| legacy: legacyWorkspaces.find((pkg) => pkg.name === name).version, | ||
| }), | ||
| }), | ||
| [], | ||
| ); | ||
| }); | ||
|
|
||
| test("refuses missing, unpublished, prerelease, or v2 legacy tag targets", async () => { | ||
| for (const version of [undefined, "2.0.0", "1.8.4-next.0", "not-a-version"]) { | ||
| const packages = legacyWorkspaces.filter((pkg) => pkg.name !== sdk.name); | ||
| if (version !== undefined) packages.push({ ...sdk, version }); | ||
| await assert.rejects( | ||
| legacyTagPlan(packages, tagRegistry), | ||
| /Expected a published pre-v2 workspace version/, | ||
| ); | ||
| } | ||
| await assert.rejects( | ||
| legacyTagPlan(legacyWorkspaces, { | ||
| ...tagRegistry, | ||
| isPublished: async (name) => name !== sdk.name, | ||
| }), | ||
| /Expected a published pre-v2 workspace version/, | ||
| ); | ||
| }); | ||
|
|
||
| test("never replaces an existing legacy tag during seeding", async () => { | ||
| for (const legacy of ["1.8.3", "1.8.5", "2.0.0"]) { | ||
| await assert.rejects( | ||
| legacyTagPlan(legacyWorkspaces, { | ||
| ...tagRegistry, | ||
| tags: async (name) => ({ | ||
| legacy: name === sdk.name ? legacy : undefined, | ||
| }), | ||
| }), | ||
| /Refusing to replace existing npm legacy/, | ||
| ); | ||
| } | ||
| }); | ||
|
|
||
| test("the maintenance publisher never selects latest", () => { | ||
| const pkg = JSON.parse( | ||
| readFileSync(new URL("../package.json", import.meta.url)), | ||
| ); | ||
| assert.equal( | ||
| pkg.scripts["publish-v1-packages"], | ||
| "node scripts/v1-release.mjs check && yarn release --tag legacy", | ||
| ); | ||
| const workflow = readFileSync( | ||
| new URL("../.github/workflows/publish.yml", import.meta.url), | ||
| "utf8", | ||
| ); | ||
| const seedJob = workflow.split(" legacy-tags:\n")[1]; | ||
| assert.match(seedJob, /github\.event_name == 'workflow_dispatch'/); | ||
| assert.match(seedJob, /github\.ref == 'refs\/heads\/maintenance\/v1'/); | ||
| assert.match(seedJob, /vars\.V1_PUBLISH_ENABLED == 'true'/); | ||
| assert.match(seedJob, /environment: npm-v1-release/); | ||
| assert.match(seedJob, /id-token: write/); | ||
| assert.match( | ||
| seedJob, | ||
| /test "\$GITHUB_REF_PROTECTED" = true && test "\$head" = "\$GITHUB_SHA"/, | ||
| ); | ||
| assert.match(seedJob, /run: node scripts\/v1-release\.mjs tag-legacy/); | ||
| }); | ||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[P2] Provide npm authentication for legacy dist-tag updates
When any legacy tag is missing, this step invokes
npm dist-tag add, but the job supplies no npm credential.id-token: writeenables trusted publishing fornpm publish; it does not authenticate standalone dist-tag mutations, andsetup-nodeonly configures the registry/token reference rather than supplying a token. Consequently, the manual seeding job fails on its first required update instead of preserving the v1 tags. Supply an appropriately scoped npm write token throughNODE_AUTH_TOKENfor this protected step, or use another supported authenticated mechanism for dist-tag updates.