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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
|
#!/usr/bin/env -S deno run -A --lock=tools/deno.lock.json
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { $ } from "jsr:@david/dax@0.41.0";
import { gray } from "jsr:@std/fmt@1/colors";
import { patchver } from "jsr:@deno/patchver@0.1.0";
const SUPPORTED_TARGETS = [
"aarch64-apple-darwin",
"aarch64-unknown-linux-gnu",
"x86_64-apple-darwin",
"x86_64-pc-windows-msvc",
"x86_64-unknown-linux-gnu",
];
const DENO_BINARIES = [
"deno",
"denort",
];
const CHANNEL = "rc";
const CANARY_URL = "https://dl.deno.land";
function getCanaryBinaryUrl(
version: string,
binary: string,
target: string,
): string {
return `${CANARY_URL}/canary/${version}/${binary}-${target}.zip`;
}
function getUnzippedFilename(binary: string, target: string) {
if (target.includes("windows")) {
return `${binary}.exe`;
} else {
return binary;
}
}
function getRcBinaryName(binary: string, target: string): string {
let ext = "";
if (target.includes("windows")) {
ext = ".exe";
}
return `${binary}-${target}-rc${ext}`;
}
function getArchiveName(binary: string, target: string): string {
return `${binary}-${target}.zip`;
}
interface CanaryVersion {
target: string;
version: string;
}
async function remove(filePath: string) {
try {
await Deno.remove(filePath);
} catch {
// pass
}
}
async function fetchLatestCanaryBinary(
version: string,
binary: string,
target: string,
) {
const url = getCanaryBinaryUrl(version, binary, target);
await $.request(url).showProgress().pipeToPath();
}
async function fetchLatestCanaryBinaries(canaryVersion: string) {
for (const binary of DENO_BINARIES) {
for (const target of SUPPORTED_TARGETS) {
$.logStep("Download", binary, gray("target:"), target);
await fetchLatestCanaryBinary(canaryVersion, binary, target);
}
}
}
async function unzipArchive(archiveName: string, unzippedName: string) {
await remove(unzippedName);
const output = await $`unzip ./${archiveName}`;
if (output.code !== 0) {
$.logError(`Failed to unzip ${archiveName} (error code ${output.code})`);
Deno.exit(1);
}
}
async function createArchive(rcBinaryName: string, archiveName: string) {
const output = await $`zip -r ./${archiveName} ./${rcBinaryName}`;
if (output.code !== 0) {
$.logError(
`Failed to create archive ${archiveName} (error code ${output.code})`,
);
Deno.exit(1);
}
}
async function runPatchver(
binary: string,
target: string,
rcBinaryName: string,
) {
const input = await Deno.readFile(binary);
const output = patchver(input, CHANNEL);
try {
await Deno.writeFile(rcBinaryName, output);
} catch (e) {
$.logError(
`Failed to promote to RC ${binary} (${target}), error:`,
e,
);
Deno.exit(1);
}
}
async function promoteBinaryToRc(binary: string, target: string) {
const unzippedName = getUnzippedFilename(binary, target);
const rcBinaryName = getRcBinaryName(binary, target);
const archiveName = getArchiveName(binary, target);
await remove(unzippedName);
await remove(rcBinaryName);
$.logStep(
"Unzip",
archiveName,
gray("binary"),
binary,
gray("rcBinaryName"),
rcBinaryName,
);
await unzipArchive(archiveName, unzippedName);
await remove(archiveName);
$.logStep(
"Patchver",
unzippedName,
`(${target})`,
gray("output to"),
rcBinaryName,
);
await runPatchver(unzippedName, target, rcBinaryName);
// Remove the unpatched binary and rename patched one.
await remove(unzippedName);
await Deno.rename(rcBinaryName, unzippedName);
// Set executable permission
if (!target.includes("windows")) {
Deno.chmod(unzippedName, 0o777);
}
await createArchive(unzippedName, archiveName);
await remove(unzippedName);
}
async function promoteBinariesToRc() {
const totalCanaries = SUPPORTED_TARGETS.length * DENO_BINARIES.length;
for (let targetIdx = 0; targetIdx < SUPPORTED_TARGETS.length; targetIdx++) {
const target = SUPPORTED_TARGETS[targetIdx];
for (let binaryIdx = 0; binaryIdx < DENO_BINARIES.length; binaryIdx++) {
const binaryName = DENO_BINARIES[binaryIdx];
const currentIdx = (targetIdx * 2) + binaryIdx + 1;
$.logLight(
`[${currentIdx}/${totalCanaries}]`,
"Promote",
binaryName,
target,
"to RC...",
);
await promoteBinaryToRc(binaryName, target);
$.logLight(
`[${currentIdx}/${totalCanaries}]`,
"Promoted",
binaryName,
target,
"to RC!",
);
}
}
}
async function dumpRcVersion() {
$.logStep("Compute version");
await unzipArchive(getArchiveName("deno", Deno.build.target), "deno");
const output = await $`./deno -V`.stdout("piped");
const denoVersion = output.stdout.slice(5).split("+")[0];
$.logStep("Computed version", denoVersion);
await Deno.writeTextFile("./release-rc-latest.txt", denoVersion);
}
async function main() {
const commitHash = Deno.args[0];
if (!commitHash) {
throw new Error("Commit hash needs to be provided as an argument");
}
$.logStep("Download canary binaries...");
await fetchLatestCanaryBinaries(commitHash);
console.log("All canary binaries ready");
$.logStep("Promote canary binaries to RC...");
await promoteBinariesToRc();
// Finally dump the version name to a `release.txt` file for uploading to GCP
await dumpRcVersion();
}
await main();
|