Skip to content

Commit 5b9c09c

Browse files
committed
Download sourcemaps from release asset if available
This download download the sourcemaps from the release asset if it is available. Unfortunately, I'm not able to test this yet because we don't yet have any releases with sourcemaps attached. As a fallback, it will still try to download from the workflow run.
1 parent 6d1c66b commit 5b9c09c

1 file changed

Lines changed: 70 additions & 22 deletions

File tree

extensions/ql-vscode/scripts/source-map.ts

Lines changed: 70 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { spawnSync } from "child_process";
1111
import { basename, resolve } from "path";
1212
import { pathExists, readJSON } from "fs-extra";
1313
import { SourceMapConsumer } from "source-map";
14+
import { Open } from "unzipper";
1415

1516
if (process.argv.length !== 4) {
1617
console.error(
@@ -24,6 +25,12 @@ const versionNumber = process.argv[2].startsWith("v")
2425
const filenameAndLine = process.argv[3];
2526

2627
async function extractSourceMap() {
28+
const releaseAssetsDirectory = resolve(
29+
__dirname,
30+
"..",
31+
"release-assets",
32+
versionNumber,
33+
);
2734
const sourceMapsDirectory = resolve(
2835
__dirname,
2936
"..",
@@ -35,34 +42,64 @@ async function extractSourceMap() {
3542
if (!(await pathExists(sourceMapsDirectory))) {
3643
console.log("Downloading source maps...");
3744

38-
const workflowRuns = runGhJSON<WorkflowRunListItem[]>([
39-
"run",
40-
"list",
41-
"--workflow",
42-
"release.yml",
43-
"--branch",
45+
const release = runGhJSON<Release>([
46+
"release",
47+
"view",
4448
versionNumber,
4549
"--json",
46-
"databaseId,number",
50+
"id,name,assets",
4751
]);
4852

49-
if (workflowRuns.length !== 1) {
50-
throw new Error(
51-
`Expected exactly one workflow run for ${versionNumber}, got ${workflowRuns.length}`,
53+
const sourcemapAsset = release.assets.find(
54+
(asset) => asset.name === `vscode-codeql-sourcemaps-${versionNumber}.zip`,
55+
);
56+
57+
if (sourcemapAsset) {
58+
// This downloads a ZIP file of the source maps
59+
runGh([
60+
"release",
61+
"download",
62+
versionNumber,
63+
"--pattern",
64+
sourcemapAsset.name,
65+
"--dir",
66+
releaseAssetsDirectory,
67+
]);
68+
69+
const file = await Open.file(
70+
resolve(releaseAssetsDirectory, sourcemapAsset.name),
5271
);
72+
await file.extract({ path: sourceMapsDirectory });
73+
} else {
74+
const workflowRuns = runGhJSON<WorkflowRunListItem[]>([
75+
"run",
76+
"list",
77+
"--workflow",
78+
"release.yml",
79+
"--branch",
80+
versionNumber,
81+
"--json",
82+
"databaseId,number",
83+
]);
84+
85+
if (workflowRuns.length !== 1) {
86+
throw new Error(
87+
`Expected exactly one workflow run for ${versionNumber}, got ${workflowRuns.length}`,
88+
);
89+
}
90+
91+
const workflowRun = workflowRuns[0];
92+
93+
runGh([
94+
"run",
95+
"download",
96+
workflowRun.databaseId.toString(),
97+
"--name",
98+
"vscode-codeql-sourcemaps",
99+
"--dir",
100+
sourceMapsDirectory,
101+
]);
53102
}
54-
55-
const workflowRun = workflowRuns[0];
56-
57-
runGh([
58-
"run",
59-
"download",
60-
workflowRun.databaseId.toString(),
61-
"--name",
62-
"vscode-codeql-sourcemaps",
63-
"--dir",
64-
sourceMapsDirectory,
65-
]);
66103
}
67104

68105
const [filename, line, column] = filenameAndLine.split(":", 3);
@@ -119,6 +156,17 @@ function runGhJSON<T>(args: readonly string[]): T {
119156
return JSON.parse(runGh(args));
120157
}
121158

159+
type ReleaseAsset = {
160+
id: string;
161+
name: string;
162+
};
163+
164+
type Release = {
165+
id: string;
166+
name: string;
167+
assets: ReleaseAsset[];
168+
};
169+
122170
type WorkflowRunListItem = {
123171
databaseId: number;
124172
number: number;

0 commit comments

Comments
 (0)