-
Notifications
You must be signed in to change notification settings - Fork 4
feat: automate app-modules release and app-monorepo sync #123
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
06caf61
feat: automate app-modules release and app-monorepo sync
huhuanming 0991722
test: remove prepare-release tests
huhuanming 9207fca
fix: harden release automation and sync all module pins
huhuanming bb35542
fix: refresh CI lockfiles and find existing release PRs
huhuanming 844713d
fix: poll npm visibility every 45 seconds up to ten times
huhuanming 42439d7
docs: clarify supported release workflow queue
huhuanming 8d528bf
feat: publish preview or latest based on version changes
huhuanming 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| import { execFileSync } from "node:child_process"; | ||
| import { dirname } from "node:path"; | ||
| import { fileURLToPath } from "node:url"; | ||
|
|
||
| import { loadReleaseWorkspaces } from "./validate-npm-dist-tag.mjs"; | ||
|
|
||
| const repoRoot = dirname(dirname(fileURLToPath(import.meta.url))); | ||
|
|
||
| export function detectReleaseChannel(before, after) { | ||
| const beforeVersions = new Map( | ||
| before.map(({ name, version }) => [name, version]) | ||
| ); | ||
| return after.some( | ||
| ({ name, version }) => beforeVersions.get(name) !== version | ||
| ) | ||
| ? "latest" | ||
| : "next"; | ||
| } | ||
|
|
||
| function readVersion(ref, manifestPath) { | ||
| try { | ||
| const manifest = execFileSync( | ||
| "git", | ||
| ["show", `${ref}:${manifestPath}`], | ||
| { cwd: repoRoot, encoding: "utf8" } | ||
| ); | ||
| return JSON.parse(manifest).version; | ||
| } catch { | ||
| return undefined; | ||
| } | ||
| } | ||
|
|
||
| async function main() { | ||
| const [baseRef, headRef] = process.argv.slice(2); | ||
| if (!baseRef || !headRef) { | ||
| throw new Error( | ||
| "Usage: node scripts/detect-release-channel.mjs <base-ref> <head-ref>" | ||
| ); | ||
| } | ||
| const workspaces = await loadReleaseWorkspaces(repoRoot); | ||
| const mergeBase = execFileSync("git", ["merge-base", baseRef, headRef], { | ||
| cwd: repoRoot, | ||
| encoding: "utf8", | ||
| }).trim(); | ||
| const before = workspaces.map(({ name, manifestPath }) => ({ | ||
| name, | ||
| version: readVersion(mergeBase, manifestPath), | ||
| })); | ||
| const after = workspaces.map(({ name, manifestPath }) => ({ | ||
| name, | ||
| version: readVersion(headRef, manifestPath), | ||
| })); | ||
| const channel = detectReleaseChannel(before, after); | ||
| const changed = after | ||
| .filter( | ||
| ({ name, version }) => | ||
| before.find((workspace) => workspace.name === name)?.version !== version | ||
| ) | ||
| .map(({ name }) => name); | ||
| console.error( | ||
| changed.length > 0 | ||
| ? `Version changes found in ${changed.length} publishable workspace(s); using latest` | ||
| : "No publishable workspace version changes found; using next preview" | ||
| ); | ||
| console.log(channel); | ||
| } | ||
|
|
||
| if (process.argv[1] === fileURLToPath(import.meta.url)) { | ||
| main().catch((error) => { | ||
| console.error(error.message); | ||
| process.exitCode = 1; | ||
| }); | ||
| } |
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 |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import assert from "node:assert/strict"; | ||
| import test from "node:test"; | ||
|
|
||
| import { detectReleaseChannel } from "./detect-release-channel.mjs"; | ||
|
|
||
| const release = [ | ||
| { name: "@onekeyfe/module-a", version: "3.0.152" }, | ||
| { name: "@onekeyfe/module-b", version: "3.0.152" }, | ||
| ]; | ||
|
|
||
| test("uses next when the change does not update package versions", () => { | ||
| assert.equal(detectReleaseChannel(release, release), "next"); | ||
| }); | ||
|
|
||
| test("uses latest when a package version changes", () => { | ||
| assert.equal( | ||
| detectReleaseChannel(release, [ | ||
| { name: "@onekeyfe/module-a", version: "3.0.153" }, | ||
| release[1], | ||
| ]), | ||
| "latest" | ||
| ); | ||
| }); | ||
|
|
||
| test("uses latest when a publishable package is added", () => { | ||
| assert.equal( | ||
| detectReleaseChannel(release, [ | ||
| ...release, | ||
| { name: "@onekeyfe/module-c", version: "3.0.153" }, | ||
| ]), | ||
| "latest" | ||
| ); | ||
| }); |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.