Skip to content

Commit 3917b14

Browse files
committed
Merge remote-tracking branch 'origin/main' into koesie10/improve-test-setup
2 parents 642b8e5 + 57f9ff6 commit 3917b14

File tree

16 files changed

+214
-822
lines changed

16 files changed

+214
-822
lines changed

.github/workflows/release.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,23 @@ jobs:
9494
asset_name: ${{ format('vscode-codeql-{0}.vsix', steps.prepare-artifacts.outputs.ref_name) }}
9595
asset_content_type: application/zip
9696

97+
- name: Create sourcemap ZIP file
98+
run: |
99+
cd dist/vscode-codeql/out
100+
zip -r ../../vscode-codeql-sourcemaps.zip *.map
101+
102+
- name: Upload sourcemap ZIP file
103+
uses: actions/upload-release-asset@v1.0.1
104+
if: success()
105+
env:
106+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
107+
with:
108+
# Get the `upload_url` from the `create-release` step above.
109+
upload_url: ${{ steps.create-release.outputs.upload_url }}
110+
asset_path: dist/vscode-codeql-sourcemaps.zip
111+
asset_name: ${{ format('vscode-codeql-sourcemaps-{0}.zip', steps.prepare-artifacts.outputs.ref_name) }}
112+
asset_content_type: application/zip
113+
97114
###
98115
# Do Post release work: version bump and changelog PR
99116
# Only do this if we are running from a PR (ie- this is part of the release process)

CONTRIBUTING.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,13 @@ Pre-recorded scenarios are stored in `./src/mocks/scenarios`. However, it's poss
229229
1. Double-check the `CHANGELOG.md` contains all desired change comments and has the version to be released with date at the top.
230230
* Go through all recent PRs and make sure they are properly accounted for.
231231
* Make sure all changelog entries have links back to their PR(s) if appropriate.
232+
* For picking the new version number, we default to increasing the patch version number, but make our own judgement about whether a change is big enough to warrant a minor version bump. Common reasons for a minor bump could include:
233+
* Making substantial new features available to all users. This can include lifting a feature flag.
234+
* Breakage in compatibility with recent versions of the CLI.
235+
* Minimum required version of VS Code is increased.
236+
* New telemetry events are added.
237+
* Deprecation or removal of commands.
238+
* Accumulation of many changes, none of which are individually big enough to warrant a minor bump, but which together are. This does not include changes which are purely internal to the extension, such as refactoring, or which are only available behind a feature flag.
232239
1. Double-check that the node version we're using matches the one used for VS Code. If it doesn't, you will then need to update the node version in the following files:
233240
* `.nvmrc` - this will enable `nvm` to automatically switch to the correct node version when you're in the project folder
234241
* `.github/workflows/main.yml` - all the "node-version: <version>" settings

extensions/ql-vscode/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@
365365
{
366366
"command": "codeQLVariantAnalysisRepositories.openConfigFile",
367367
"title": "Open Database Configuration File",
368-
"icon": "$(edit)"
368+
"icon": "$(json)"
369369
},
370370
{
371371
"command": "codeQLVariantAnalysisRepositories.addNewDatabase",
@@ -379,7 +379,7 @@
379379
},
380380
{
381381
"command": "codeQLVariantAnalysisRepositories.setSelectedItem",
382-
"title": ""
382+
"title": "Select"
383383
},
384384
{
385385
"command": "codeQLVariantAnalysisRepositories.setSelectedItemContextMenu",
@@ -822,7 +822,7 @@
822822
},
823823
{
824824
"command": "codeQLVariantAnalysisRepositories.setSelectedItem",
825-
"when": "view == codeQLVariantAnalysisRepositories && viewItem =~ /canBeSelected/ && false",
825+
"when": "view == codeQLVariantAnalysisRepositories && viewItem =~ /canBeSelected/",
826826
"group": "inline"
827827
},
828828
{

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

Lines changed: 70 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { spawnSync } from "child_process";
2020
import { basename, resolve } from "path";
2121
import { pathExists, readJSON } from "fs-extra";
2222
import { RawSourceMap, SourceMapConsumer } from "source-map";
23+
import { Open } from "unzipper";
2324

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

3839
async function extractSourceMap() {
40+
const releaseAssetsDirectory = resolve(
41+
__dirname,
42+
"..",
43+
"release-assets",
44+
versionNumber,
45+
);
3946
const sourceMapsDirectory = resolve(
4047
__dirname,
4148
"..",
@@ -47,34 +54,64 @@ async function extractSourceMap() {
4754
if (!(await pathExists(sourceMapsDirectory))) {
4855
console.log("Downloading source maps...");
4956

50-
const workflowRuns = runGhJSON<WorkflowRunListItem[]>([
51-
"run",
52-
"list",
53-
"--workflow",
54-
"release.yml",
55-
"--branch",
57+
const release = runGhJSON<Release>([
58+
"release",
59+
"view",
5660
versionNumber,
5761
"--json",
58-
"databaseId,number",
62+
"id,name,assets",
5963
]);
6064

61-
if (workflowRuns.length !== 1) {
62-
throw new Error(
63-
`Expected exactly one workflow run for ${versionNumber}, got ${workflowRuns.length}`,
65+
const sourcemapAsset = release.assets.find(
66+
(asset) => asset.name === `vscode-codeql-sourcemaps-${versionNumber}.zip`,
67+
);
68+
69+
if (sourcemapAsset) {
70+
// This downloads a ZIP file of the source maps
71+
runGh([
72+
"release",
73+
"download",
74+
versionNumber,
75+
"--pattern",
76+
sourcemapAsset.name,
77+
"--dir",
78+
releaseAssetsDirectory,
79+
]);
80+
81+
const file = await Open.file(
82+
resolve(releaseAssetsDirectory, sourcemapAsset.name),
6483
);
84+
await file.extract({ path: sourceMapsDirectory });
85+
} else {
86+
const workflowRuns = runGhJSON<WorkflowRunListItem[]>([
87+
"run",
88+
"list",
89+
"--workflow",
90+
"release.yml",
91+
"--branch",
92+
versionNumber,
93+
"--json",
94+
"databaseId,number",
95+
]);
96+
97+
if (workflowRuns.length !== 1) {
98+
throw new Error(
99+
`Expected exactly one workflow run for ${versionNumber}, got ${workflowRuns.length}`,
100+
);
101+
}
102+
103+
const workflowRun = workflowRuns[0];
104+
105+
runGh([
106+
"run",
107+
"download",
108+
workflowRun.databaseId.toString(),
109+
"--name",
110+
"vscode-codeql-sourcemaps",
111+
"--dir",
112+
sourceMapsDirectory,
113+
]);
65114
}
66-
67-
const workflowRun = workflowRuns[0];
68-
69-
runGh([
70-
"run",
71-
"download",
72-
workflowRun.databaseId.toString(),
73-
"--name",
74-
"vscode-codeql-sourcemaps",
75-
"--dir",
76-
sourceMapsDirectory,
77-
]);
78115
}
79116

80117
if (stacktrace.includes("at")) {
@@ -172,6 +209,17 @@ function runGhJSON<T>(args: readonly string[]): T {
172209
return JSON.parse(runGh(args));
173210
}
174211

212+
type ReleaseAsset = {
213+
id: string;
214+
name: string;
215+
};
216+
217+
type Release = {
218+
id: string;
219+
name: string;
220+
assets: ReleaseAsset[];
221+
};
222+
175223
type WorkflowRunListItem = {
176224
databaseId: number;
177225
number: number;

extensions/ql-vscode/src/contextual/queryResolver.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { CancellationToken, Uri } from "vscode";
1919
import { ProgressCallback } from "../commandRunner";
2020
import { QueryRunner } from "../queryRunner";
2121
import { redactableError } from "../pure/errors";
22+
import { QLPACK_FILENAMES } from "../pure/ql";
2223

2324
export async function qlpackOfDatabase(
2425
cli: CodeQLCliServer,
@@ -113,7 +114,7 @@ async function resolveContextualQuery(
113114
// Work out the enclosing pack.
114115
const packContents = await cli.packPacklist(query, false);
115116
const packFilePath = packContents.find((p) =>
116-
["codeql-pack.yml", "qlpack.yml"].includes(basename(p)),
117+
QLPACK_FILENAMES.includes(basename(p)),
117118
);
118119
if (packFilePath === undefined) {
119120
// Should not happen; we already resolved this query.

extensions/ql-vscode/src/extension.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -845,6 +845,7 @@ async function activateWithInstalledDistribution(
845845
documentSelector: [
846846
{ language: "ql", scheme: "file" },
847847
{ language: "yaml", scheme: "file", pattern: "**/qlpack.yml" },
848+
{ language: "yaml", scheme: "file", pattern: "**/codeql-pack.yml" },
848849
],
849850
synchronize: {
850851
configurationSection: "codeQL",

extensions/ql-vscode/src/helpers.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { extLogger, OutputChannelLogger } from "./common";
2323
import { QueryMetadata } from "./pure/interface-types";
2424
import { telemetryListener } from "./telemetry";
2525
import { RedactableError } from "./pure/errors";
26+
import { getQlPackPath } from "./pure/ql";
2627

2728
// Shared temporary folder for the extension.
2829
export const tmpDir = dirSync({
@@ -387,17 +388,22 @@ async function findDbschemePack(
387388
): Promise<{ name: string; isLibraryPack: boolean }> {
388389
for (const { packDir, packName } of packs) {
389390
if (packDir !== undefined) {
390-
const qlpack = load(
391-
await readFile(join(packDir, "qlpack.yml"), "utf8"),
392-
) as { dbscheme?: string; library?: boolean };
393-
if (
394-
qlpack.dbscheme !== undefined &&
395-
basename(qlpack.dbscheme) === basename(dbschemePath)
396-
) {
397-
return {
398-
name: packName,
399-
isLibraryPack: qlpack.library === true,
391+
const qlpackPath = await getQlPackPath(packDir);
392+
393+
if (qlpackPath !== undefined) {
394+
const qlpack = load(await readFile(qlpackPath, "utf8")) as {
395+
dbscheme?: string;
396+
library?: boolean;
400397
};
398+
if (
399+
qlpack.dbscheme !== undefined &&
400+
basename(qlpack.dbscheme) === basename(dbschemePath)
401+
) {
402+
return {
403+
name: packName,
404+
isLibraryPack: qlpack.library === true,
405+
};
406+
}
401407
}
402408
}
403409
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { join } from "path";
2+
import { pathExists } from "fs-extra";
3+
4+
export const QLPACK_FILENAMES = ["qlpack.yml", "codeql-pack.yml"];
5+
export const FALLBACK_QLPACK_FILENAME = QLPACK_FILENAMES[0];
6+
7+
export async function getQlPackPath(
8+
packRoot: string,
9+
): Promise<string | undefined> {
10+
for (const filename of QLPACK_FILENAMES) {
11+
const path = join(packRoot, filename);
12+
13+
if (await pathExists(path)) {
14+
return path;
15+
}
16+
}
17+
18+
return undefined;
19+
}

extensions/ql-vscode/src/quick-query.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
} from "./helpers";
2020
import { ProgressCallback, UserCancellationException } from "./commandRunner";
2121
import { getErrorMessage } from "./pure/helpers-pure";
22+
import { FALLBACK_QLPACK_FILENAME, getQlPackPath } from "./pure/ql";
2223

2324
const QUICK_QUERIES_DIR_NAME = "quick-queries";
2425
const QUICK_QUERY_QUERY_NAME = "quick-query.ql";
@@ -112,7 +113,7 @@ export async function displayQuickQuery(
112113
const dbscheme = await getPrimaryDbscheme(datasetFolder);
113114
const qlpack = (await getQlPackForDbscheme(cliServer, dbscheme))
114115
.dbschemePack;
115-
const qlPackFile = join(queriesDir, "qlpack.yml");
116+
const qlPackFile = await getQlPackPath(queriesDir);
116117
const qlFile = join(queriesDir, QUICK_QUERY_QUERY_NAME);
117118
const shouldRewrite = await checkShouldRewrite(qlPackFile, qlpack);
118119

@@ -126,7 +127,7 @@ export async function displayQuickQuery(
126127
},
127128
};
128129
await writeFile(
129-
qlPackFile,
130+
qlPackFile ?? join(queriesDir, FALLBACK_QLPACK_FILENAME),
130131
QLPACK_FILE_HEADER + dump(quickQueryQlpackYaml),
131132
"utf8",
132133
);
@@ -158,7 +159,13 @@ export async function displayQuickQuery(
158159
}
159160
}
160161

161-
async function checkShouldRewrite(qlPackFile: string, newDependency: string) {
162+
async function checkShouldRewrite(
163+
qlPackFile: string | undefined,
164+
newDependency: string,
165+
) {
166+
if (!qlPackFile) {
167+
return true;
168+
}
162169
if (!(await pathExists(qlPackFile))) {
163170
return true;
164171
}

0 commit comments

Comments
 (0)