Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 70 additions & 22 deletions extensions/ql-vscode/scripts/source-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { spawnSync } from "child_process";
import { basename, resolve } from "path";
import { pathExists, readJSON } from "fs-extra";
import { RawSourceMap, SourceMapConsumer } from "source-map";
import { Open } from "unzipper";

if (process.argv.length !== 4) {
console.error(
Expand All @@ -36,6 +37,12 @@ const versionNumber = process.argv[2].startsWith("v")
const stacktrace = process.argv[3];

async function extractSourceMap() {
const releaseAssetsDirectory = resolve(
__dirname,
"..",
"release-assets",
versionNumber,
);
const sourceMapsDirectory = resolve(
__dirname,
"..",
Expand All @@ -47,34 +54,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,
]);
}

if (stacktrace.includes("at")) {
Expand Down Expand Up @@ -172,6 +209,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;
Expand Down