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.
This commit is contained in:
@@ -11,6 +11,7 @@ import { spawnSync } from "child_process";
|
||||
import { basename, resolve } from "path";
|
||||
import { pathExists, readJSON } from "fs-extra";
|
||||
import { SourceMapConsumer } from "source-map";
|
||||
import { Open } from "unzipper";
|
||||
|
||||
if (process.argv.length !== 4) {
|
||||
console.error(
|
||||
@@ -24,6 +25,12 @@ const versionNumber = process.argv[2].startsWith("v")
|
||||
const filenameAndLine = process.argv[3];
|
||||
|
||||
async function extractSourceMap() {
|
||||
const releaseAssetsDirectory = resolve(
|
||||
__dirname,
|
||||
"..",
|
||||
"release-assets",
|
||||
versionNumber,
|
||||
);
|
||||
const sourceMapsDirectory = resolve(
|
||||
__dirname,
|
||||
"..",
|
||||
@@ -35,34 +42,64 @@ async function extractSourceMap() {
|
||||
if (!(await pathExists(sourceMapsDirectory))) {
|
||||
console.log("Downloading source maps...");
|
||||
|
||||
const workflowRuns = runGhJSON<WorkflowRunListItem[]>([
|
||||
"run",
|
||||
"list",
|
||||
"--workflow",
|
||||
"release.yml",
|
||||
"--branch",
|
||||
const release = runGhJSON<Release>([
|
||||
"release",
|
||||
"view",
|
||||
versionNumber,
|
||||
"--json",
|
||||
"databaseId,number",
|
||||
"id,name,assets",
|
||||
]);
|
||||
|
||||
if (workflowRuns.length !== 1) {
|
||||
throw new Error(
|
||||
`Expected exactly one workflow run for ${versionNumber}, got ${workflowRuns.length}`,
|
||||
const sourcemapAsset = release.assets.find(
|
||||
(asset) => asset.name === `vscode-codeql-sourcemaps-${versionNumber}.zip`,
|
||||
);
|
||||
|
||||
if (sourcemapAsset) {
|
||||
// This downloads a ZIP file of the source maps
|
||||
runGh([
|
||||
"release",
|
||||
"download",
|
||||
versionNumber,
|
||||
"--pattern",
|
||||
sourcemapAsset.name,
|
||||
"--dir",
|
||||
releaseAssetsDirectory,
|
||||
]);
|
||||
|
||||
const file = await Open.file(
|
||||
resolve(releaseAssetsDirectory, sourcemapAsset.name),
|
||||
);
|
||||
await file.extract({ path: sourceMapsDirectory });
|
||||
} else {
|
||||
const workflowRuns = runGhJSON<WorkflowRunListItem[]>([
|
||||
"run",
|
||||
"list",
|
||||
"--workflow",
|
||||
"release.yml",
|
||||
"--branch",
|
||||
versionNumber,
|
||||
"--json",
|
||||
"databaseId,number",
|
||||
]);
|
||||
|
||||
if (workflowRuns.length !== 1) {
|
||||
throw new Error(
|
||||
`Expected exactly one workflow run for ${versionNumber}, got ${workflowRuns.length}`,
|
||||
);
|
||||
}
|
||||
|
||||
const workflowRun = workflowRuns[0];
|
||||
|
||||
runGh([
|
||||
"run",
|
||||
"download",
|
||||
workflowRun.databaseId.toString(),
|
||||
"--name",
|
||||
"vscode-codeql-sourcemaps",
|
||||
"--dir",
|
||||
sourceMapsDirectory,
|
||||
]);
|
||||
}
|
||||
|
||||
const workflowRun = workflowRuns[0];
|
||||
|
||||
runGh([
|
||||
"run",
|
||||
"download",
|
||||
workflowRun.databaseId.toString(),
|
||||
"--name",
|
||||
"vscode-codeql-sourcemaps",
|
||||
"--dir",
|
||||
sourceMapsDirectory,
|
||||
]);
|
||||
}
|
||||
|
||||
const [filename, line, column] = filenameAndLine.split(":", 3);
|
||||
@@ -119,6 +156,17 @@ function runGhJSON<T>(args: readonly string[]): T {
|
||||
return JSON.parse(runGh(args));
|
||||
}
|
||||
|
||||
type ReleaseAsset = {
|
||||
id: string;
|
||||
name: string;
|
||||
};
|
||||
|
||||
type Release = {
|
||||
id: string;
|
||||
name: string;
|
||||
assets: ReleaseAsset[];
|
||||
};
|
||||
|
||||
type WorkflowRunListItem = {
|
||||
databaseId: number;
|
||||
number: number;
|
||||
|
||||
Reference in New Issue
Block a user