forked from denoland/deno_docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_update_deno.ts
96 lines (81 loc) · 2.32 KB
/
_update_deno.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
const DENO_TRACKING_BRANCH = "main";
const AUTOROLL_BRANCH = "autoroll";
function extractVersion() {
}
await run(["git", "checkout", "origin/main"]);
const currentVersion =
Deno.readTextFileSync("./debian.dockerfile").match(/DENO_VERSION=(.*)/)![1];
console.log(`Starting auto update. Currently on ${currentVersion}`);
async function run(cmd: string[], cwd?: string) {
const proc = Deno.run({ cmd, cwd });
const status = await proc.status();
if (!status.success) {
console.error(`Failed to run ${cmd.join(" ")}`);
Deno.exit(1);
}
}
const newVersion = Deno.version.deno;
if (currentVersion == newVersion) {
console.log(`No new version available. Staying on ${newVersion}`);
Deno.exit(0);
}
async function updateDenoVersion(fn: string) {
console.log(fn);
const dockerfile = await Deno.readTextFile(fn);
const updated = dockerfile.replaceAll(
`DENO_VERSION=${currentVersion}`,
`DENO_VERSION=${newVersion}`,
);
await Deno.writeTextFile(fn, updated);
}
const dockerfiles = [...Deno.readDirSync(".")].filter((e) =>
e.name.endsWith(".dockerfile")
);
for (const f of dockerfiles) {
console.log(f.name);
await updateDenoVersion(f.name);
}
async function updateDockerVersion(fn: string) {
const contents = await Deno.readTextFile(fn);
const updated = contents.replaceAll(
`deno:${currentVersion}`,
`deno:${newVersion}`,
);
await Deno.writeTextFile(fn, updated);
}
for (const fn of ["README.md", "example/Dockerfile"]) {
console.log(fn);
await updateDockerVersion(fn);
}
console.log(`Updated to version ${newVersion}`);
// Stage the changes
await run(["git", "add", "*.dockerfile", "README.md", "example/Dockerfile"]);
// Commit the changes
await run(["git", "commit", "-m", `Rolling to deno ${newVersion}`]);
// Push to the `denoland/deno_docker#autoroll`
await run(["git", "push", "origin", `+HEAD:${AUTOROLL_BRANCH}`]);
const proc = Deno.run({
cmd: ["gh", "pr", "view", AUTOROLL_BRANCH],
});
const status = await proc.status();
if (status.code == 1) {
console.log("No PR open. Creating a new PR.");
await run([
"gh",
"pr",
"create",
"--fill",
"--head",
AUTOROLL_BRANCH,
]);
} else {
console.log("Already open PR. Editing existing PR.");
await run([
"gh",
"pr",
"edit",
AUTOROLL_BRANCH,
"--title",
`Rolling to deno ${newVersion}`,
]);
}