diff options
Diffstat (limited to 'tools/release')
-rwxr-xr-x | tools/release/01_bump_crate_versions.ts | 40 | ||||
-rwxr-xr-x | tools/release/02_create_pr.ts | 51 | ||||
-rwxr-xr-x | tools/release/02_publish_crates.ts | 23 | ||||
-rwxr-xr-x | tools/release/03_publish_crates.ts | 48 | ||||
-rwxr-xr-x | tools/release/04_create_release_tag.ts | 17 | ||||
-rw-r--r-- | tools/release/deno_workspace.ts | 5 | ||||
-rw-r--r-- | tools/release/deps.ts | 3 |
7 files changed, 159 insertions, 28 deletions
diff --git a/tools/release/01_bump_crate_versions.ts b/tools/release/01_bump_crate_versions.ts index eea49279f..70c92637e 100755 --- a/tools/release/01_bump_crate_versions.ts +++ b/tools/release/01_bump_crate_versions.ts @@ -1,4 +1,4 @@ -#!/usr/bin/env -S deno run --allow-read --allow-write --allow-run=cargo +#!/usr/bin/env -S deno run --allow-read --allow-write --allow-run=cargo,git --allow-net --no-check // Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. import { DenoWorkspace } from "./deno_workspace.ts"; import { GitLogOutput, path, semver } from "./deps.ts"; @@ -8,8 +8,19 @@ const repo = workspace.repo; const cliCrate = workspace.getCliCrate(); const originalCliVersion = cliCrate.version; +// update the std version used in the code +await updateStdVersion(); + // increment the cli version -await cliCrate.promptAndIncrement(); +if (Deno.args.some((a) => a === "--patch")) { + await cliCrate.increment("patch"); +} else if (Deno.args.some((a) => a === "--minor")) { + await cliCrate.increment("minor"); +} else if (Deno.args.some((a) => a === "--major")) { + await cliCrate.increment("major"); +} else { + await cliCrate.promptAndIncrement(); +} // increment the dependency crate versions for (const crate of workspace.getCliDependencyCrates()) { @@ -17,7 +28,7 @@ for (const crate of workspace.getCliDependencyCrates()) { } // update the lock file -await workspace.getCliCrate().cargoCheck(); +await workspace.getCliCrate().cargoUpdate("--workspace"); // try to update the Releases.md markdown text try { @@ -101,3 +112,26 @@ async function getGitLog() { ); } } + +async function updateStdVersion() { + const newStdVersion = await getLatestStdVersion(); + const compatFilePath = path.join(cliCrate.folderPath, "compat/mod.rs"); + const text = Deno.readTextFileSync(compatFilePath); + Deno.writeTextFileSync( + compatFilePath, + text.replace(/std@[0-9]+\.[0-9]+\.[0-9]+/, `std@${newStdVersion}`), + ); +} + +async function getLatestStdVersion() { + const url = + "https://raw.githubusercontent.com/denoland/deno_std/main/version.ts"; + const result = await fetch(url); + const text = await result.text(); + const version = /"([0-9]+\.[0-9]+\.[0-9]+)"/.exec(text); + if (version == null) { + throw new Error(`Could not find version in text: ${text}`); + } else { + return version[1]; + } +} diff --git a/tools/release/02_create_pr.ts b/tools/release/02_create_pr.ts new file mode 100755 index 000000000..e64638277 --- /dev/null +++ b/tools/release/02_create_pr.ts @@ -0,0 +1,51 @@ +#!/usr/bin/env -S deno run --allow-read --allow-write --allow-env --allow-net --allow-run=cargo,git --no-check +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. +import { DenoWorkspace } from "./deno_workspace.ts"; +import { createOctoKit, getGitHubRepository } from "./deps.ts"; + +const octoKit = createOctoKit(); +const workspace = await DenoWorkspace.load(); +const repo = workspace.repo; +const cliCrate = workspace.getCliCrate(); + +const originalBranch = await repo.gitCurrentBranch(); +const newBranchName = `release_${cliCrate.version.replace(/\./, "_")}`; + +// Create and push branch +console.log(`Creating branch ${newBranchName}...`); +await repo.gitBranch(newBranchName); +await repo.gitAdd(); +await repo.gitCommit(cliCrate.version); +console.log("Pushing branch..."); +await repo.gitPush("-u", "origin", "HEAD"); + +// Open PR +console.log("Opening PR..."); +const openedPr = await octoKit.request("POST /repos/{owner}/{repo}/pulls", { + ...getGitHubRepository(), + base: originalBranch, + head: newBranchName, + draft: true, + title: cliCrate.version, + body: getPrBody(), +}); +console.log(`Opened PR at ${openedPr.data.url}`); + +function getPrBody() { + let text = `Bumped versions for ${cliCrate.version}\n\n` + + `Please ensure:\n` + + `- [ ] Crate versions are bumped correctly\n` + + `- [ ] deno_std version is incremented in the code\n` + + `- [ ] Releases.md is updated correctly\n\n` + + `To make edits to this PR:\n` + + "```shell\n" + + `git fetch upstream ${newBranchName} && git checkout -b ${newBranchName} upstream/${newBranchName}\n` + + "```\n"; + + const actor = Deno.env.get("GH_WORKFLOW_ACTOR"); + if (actor != null) { + text += `\ncc @${actor}`; + } + + return text; +} diff --git a/tools/release/02_publish_crates.ts b/tools/release/02_publish_crates.ts deleted file mode 100755 index 5910827c3..000000000 --- a/tools/release/02_publish_crates.ts +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/env -S deno run --allow-read --allow-write --allow-run=cargo --allow-net=crates.io -// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. -import { DenoWorkspace } from "./deno_workspace.ts"; -import { getCratesPublishOrder } from "./deps.ts"; - -const workspace = await DenoWorkspace.load(); -const cliCrate = workspace.getCliCrate(); - -const dependencyCrates = getCratesPublishOrder( - workspace.getCliDependencyCrates(), -); - -try { - for (const [i, crate] of dependencyCrates.entries()) { - await crate.publish(); - console.log(`Published ${i + 1} of ${dependencyCrates.length} crates.`); - } - - await cliCrate.publish(); -} finally { - // system beep to notify error or completion - console.log("\x07"); -} diff --git a/tools/release/03_publish_crates.ts b/tools/release/03_publish_crates.ts new file mode 100755 index 000000000..4c9cb23d3 --- /dev/null +++ b/tools/release/03_publish_crates.ts @@ -0,0 +1,48 @@ +#!/usr/bin/env -S deno run --allow-read --allow-write --allow-run=cargo --allow-net=crates.io --no-check +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. +import { DenoWorkspace } from "./deno_workspace.ts"; +import { Crate, getCratesPublishOrder } from "./deps.ts"; + +const isReal = parseIsReal(); +console.log(`Running a ${isReal ? "real" : "dry"} cargo publish...`); + +const workspace = await DenoWorkspace.load(); +const cliCrate = workspace.getCliCrate(); + +const dependencyCrates = getCratesPublishOrder( + workspace.getCliDependencyCrates(), +); + +try { + for (const [i, crate] of dependencyCrates.entries()) { + await publishCrate(crate); + console.log(`Finished ${i + 1} of ${dependencyCrates.length} crates.`); + } + + await publishCrate(cliCrate); +} finally { + // system beep to notify error or completion + console.log("\x07"); +} + +async function publishCrate(crate: Crate) { + if (isReal) { + await crate.publish(); + } else { + await crate.publishDryRun(); + } +} + +function parseIsReal() { + const isReal = Deno.args.some((a) => a === "--real"); + const isDry = Deno.args.some((a) => a === "--dry"); + + // force the call to be explicit and provide one of these + // so that it's obvious what's happening + if (!isDry && !isReal) { + console.error("Please run with `--dry` or `--real`."); + Deno.exit(1); + } + + return isReal; +} diff --git a/tools/release/04_create_release_tag.ts b/tools/release/04_create_release_tag.ts new file mode 100755 index 000000000..1a770e6cd --- /dev/null +++ b/tools/release/04_create_release_tag.ts @@ -0,0 +1,17 @@ +#!/usr/bin/env -S deno run --allow-read --allow-write --allow-run=cargo --no-check +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. +import { DenoWorkspace } from "./deno_workspace.ts"; + +const workspace = await DenoWorkspace.load(); +const repo = workspace.repo; +const cliCrate = workspace.getCliCrate(); + +await repo.gitFetchTags("origin"); +const tags = await repo.getGitTags(); + +if (tags.has(cliCrate.version)) { + console.log(`Tag ${cliCrate.version} already exists.`); +} else { + await repo.gitTag(cliCrate.version); + await repo.gitPush(cliCrate.version); +} diff --git a/tools/release/deno_workspace.ts b/tools/release/deno_workspace.ts index 6f5b64590..d36a2a22f 100644 --- a/tools/release/deno_workspace.ts +++ b/tools/release/deno_workspace.ts @@ -12,7 +12,10 @@ export class DenoWorkspace { static async load(): Promise<DenoWorkspace> { return new DenoWorkspace( - await Repo.load("deno", DenoWorkspace.rootDirPath), + await Repo.load({ + name: "deno", + path: DenoWorkspace.rootDirPath, + }), ); } diff --git a/tools/release/deps.ts b/tools/release/deps.ts index 86f1db10f..9c23e509e 100644 --- a/tools/release/deps.ts +++ b/tools/release/deps.ts @@ -1,3 +1,4 @@ // Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. -export * from "https://raw.githubusercontent.com/denoland/automation/0.5.0/mod.ts"; +export * from "https://raw.githubusercontent.com/denoland/automation/0.9.0/mod.ts"; +export * from "https://raw.githubusercontent.com/denoland/automation/0.9.0/github_actions.ts"; |