2022-04-08 12:32:25 -04:00
|
|
|
#!/usr/bin/env -S deno run --allow-read --allow-write --allow-run=cargo,git,deno --allow-net --no-check
|
2022-03-08 18:10:03 -05:00
|
|
|
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
|
|
|
|
import { DenoWorkspace } from "./deno_workspace.ts";
|
|
|
|
import { GitLogOutput, path, semver } from "./deps.ts";
|
|
|
|
|
|
|
|
const workspace = await DenoWorkspace.load();
|
|
|
|
const repo = workspace.repo;
|
|
|
|
const cliCrate = workspace.getCliCrate();
|
|
|
|
const originalCliVersion = cliCrate.version;
|
|
|
|
|
2022-03-30 16:37:00 -04:00
|
|
|
// update the std version used in the code
|
2022-04-02 11:25:12 -04:00
|
|
|
console.log("Updating std version...");
|
2022-03-30 16:37:00 -04:00
|
|
|
await updateStdVersion();
|
|
|
|
|
2022-03-08 18:10:03 -05:00
|
|
|
// increment the cli version
|
2022-03-30 16:37:00 -04:00
|
|
|
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();
|
|
|
|
}
|
2022-03-08 18:10:03 -05:00
|
|
|
|
|
|
|
// increment the dependency crate versions
|
2022-03-16 20:33:14 -04:00
|
|
|
for (const crate of workspace.getCliDependencyCrates()) {
|
2022-03-08 18:10:03 -05:00
|
|
|
await crate.increment("minor");
|
|
|
|
}
|
|
|
|
|
|
|
|
// update the lock file
|
2022-03-30 16:37:00 -04:00
|
|
|
await workspace.getCliCrate().cargoUpdate("--workspace");
|
2022-03-08 18:10:03 -05:00
|
|
|
|
|
|
|
// try to update the Releases.md markdown text
|
|
|
|
try {
|
2022-04-02 11:25:12 -04:00
|
|
|
console.log("Updating Releases.md...");
|
2022-03-08 18:10:03 -05:00
|
|
|
await updateReleasesMd();
|
|
|
|
} catch (err) {
|
|
|
|
console.error(err);
|
|
|
|
console.error(
|
|
|
|
"Updating Releases.md failed. Please manually run " +
|
|
|
|
"`git log --oneline VERSION_FROM..VERSION_TO` and " +
|
|
|
|
"use the output to update Releases.md",
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
async function updateReleasesMd() {
|
|
|
|
const gitLog = await getGitLog();
|
2022-04-02 11:25:12 -04:00
|
|
|
const releasesMdFile = workspace.getReleasesMdFile();
|
|
|
|
releasesMdFile.updateWithGitLog({
|
|
|
|
version: cliCrate.version,
|
|
|
|
gitLog,
|
|
|
|
});
|
2022-03-08 18:10:03 -05:00
|
|
|
|
2022-04-02 11:25:12 -04:00
|
|
|
await workspace.runFormatter();
|
2022-03-08 18:10:03 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
async function getGitLog() {
|
2022-04-01 11:11:53 -04:00
|
|
|
const originalVersion = semver.parse(originalCliVersion)!;
|
|
|
|
const originalVersionTag = `v${originalCliVersion}`;
|
2022-03-08 18:10:03 -05:00
|
|
|
// fetch the upstream tags
|
|
|
|
await repo.gitFetchTags("upstream");
|
|
|
|
|
2022-04-01 11:11:53 -04:00
|
|
|
// make the repo unshallow so we can fetch the latest tag
|
|
|
|
if (await repo.gitIsShallow()) {
|
|
|
|
await repo.gitFetchUnshallow("origin");
|
|
|
|
}
|
|
|
|
|
2022-03-08 18:10:03 -05:00
|
|
|
// this means we're on the patch release
|
|
|
|
const latestTag = await repo.gitLatestTag();
|
2022-04-01 11:11:53 -04:00
|
|
|
if (latestTag === originalVersionTag) {
|
2022-03-08 18:10:03 -05:00
|
|
|
return await repo.getGitLogFromTags(
|
|
|
|
"upstream",
|
2022-04-01 11:11:53 -04:00
|
|
|
originalVersionTag,
|
2022-03-08 18:10:03 -05:00
|
|
|
undefined,
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
// otherwise, get the history of the last release
|
|
|
|
await repo.gitFetchHistory("upstream");
|
|
|
|
const lastMinorHistory = await repo.getGitLogFromTags(
|
|
|
|
"upstream",
|
2022-04-01 11:11:53 -04:00
|
|
|
`v${originalVersion.major}.${originalVersion.minor}.0`,
|
|
|
|
originalVersionTag,
|
2022-03-08 18:10:03 -05:00
|
|
|
);
|
|
|
|
const currentHistory = await repo.getGitLogFromTags(
|
|
|
|
"upstream",
|
|
|
|
latestTag,
|
|
|
|
undefined,
|
|
|
|
);
|
|
|
|
const lastMinorMessages = new Set(
|
|
|
|
lastMinorHistory.lines.map((r) => r.message),
|
|
|
|
);
|
|
|
|
return new GitLogOutput(
|
|
|
|
currentHistory.lines.filter((l) => !lastMinorMessages.has(l.message)),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2022-03-30 16:37:00 -04:00
|
|
|
|
|
|
|
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];
|
|
|
|
}
|
|
|
|
}
|