-
Notifications
You must be signed in to change notification settings - Fork 619
/
01_bump_version.ts
executable file
·48 lines (41 loc) · 1.51 KB
/
01_bump_version.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env -S deno run --allow-read --allow-write --allow-run=git,deno --no-check
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { getReleasesMdFile, loadRepo, VersionFile } from "./repo.ts";
const repo = await loadRepo();
const versionFile = new VersionFile();
const currentVersion = versionFile.version;
const newVersion = versionFile.version.inc(getVersionIncrementKind());
// update version.ts
console.log(`Bumping version from ${currentVersion} to ${newVersion}...`);
versionFile.updateVersion(newVersion);
// update Releases.md
const releasesMdFile = getReleasesMdFile();
const versionGitLog = await getGitLogFromLastVersion();
releasesMdFile.updateWithGitLog({
gitLog: versionGitLog,
version: newVersion.toString(),
});
// run deno fmt
await repo.runCommandWithOutput(["deno", "fmt", "Releases.md"]);
function getVersionIncrementKind() {
if (Deno.args.some((a) => a === "--patch")) {
return "patch";
} else if (Deno.args.some((a) => a === "--minor")) {
return "minor";
} else if (Deno.args.some((a) => a === "--major")) {
return "major";
} else {
throw new Error("Please provide a --patch, --minor, or --major flag.");
}
}
async function getGitLogFromLastVersion() {
// fetch the upstream tags and history
await repo.gitFetchTags("upstream");
await repo.gitFetchHistory("upstream");
// get the git log from the current commit to the last version
return await repo.getGitLogFromTags(
"upstream",
currentVersion.toString(),
undefined,
);
}