Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ build/
eslint.sarif
# for local incremental compilation
tsconfig.tsbuildinfo
# esbuild metadata file
meta.json
7 changes: 5 additions & 2 deletions build.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { copyFile, rm } from "node:fs/promises";
import { copyFile, rm, writeFile } from "node:fs/promises";
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";

Expand Down Expand Up @@ -74,7 +74,10 @@ const context = await esbuild.context({
define: {
__CODEQL_ACTION_VERSION__: JSON.stringify(pkg.version),
},
metafile: true,
});

await context.rebuild();
const result = await context.rebuild();
await writeFile("meta.json", JSON.stringify(result.metafile));

await context.dispose();
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"description": "CodeQL action",
"scripts": {
"_build_comment": "echo 'Run the full build so we typecheck the project and can reuse the transpiled files in npm test'",
"build": "./scripts/check-node-modules.sh && npm run transpile && node build.mjs",
"build": "./scripts/check-node-modules.sh && npm run transpile && node build.mjs && npx tsx ./pr-checks/bundle-metadata.ts",
"lint": "eslint --report-unused-disable-directives --max-warnings=0 .",
"lint-ci": "SARIF_ESLINT_IGNORE_SUPPRESSED=true eslint --report-unused-disable-directives --max-warnings=0 . --format @microsoft/eslint-formatter-sarif --output-file=eslint.sarif",
"lint-fix": "eslint --report-unused-disable-directives --max-warnings=0 . --fix",
Expand Down
13 changes: 13 additions & 0 deletions pr-checks/api-client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import * as githubUtils from "@actions/github/lib/utils";
import { type Octokit } from "@octokit/core";
import { type PaginateInterface } from "@octokit/plugin-paginate-rest";
import { type Api } from "@octokit/plugin-rest-endpoint-methods";

/** The type of the Octokit client. */
export type ApiClient = Octokit & Api & { paginate: PaginateInterface };

/** Constructs an `ApiClient` using `token` for authentication. */
export function getApiClient(token: string): ApiClient {
const opts = githubUtils.getOctokitOptions(token);
return new githubUtils.GitHub(opts);
}
31 changes: 31 additions & 0 deletions pr-checks/bundle-metadata.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env npx tsx

import * as fs from "node:fs/promises";

import { BUNDLE_METADATA_FILE } from "./config";

interface Output {
bytes: number;
}

interface Metadata {
outputs: Output[];
}

async function main() {
const fileContents = await fs.readFile(BUNDLE_METADATA_FILE);
const metadata = JSON.parse(String(fileContents)) as Metadata;

for (const [outputFile, outputData] of Object.entries(
metadata.outputs,
).reverse()) {
console.info(
`${outputFile}: ${(outputData.bytes / (1024 * 1024)).toFixed(2)}MB`,
);
}
}

// Only call `main` if this script was run directly.
if (require.main === module) {
void main();
}
3 changes: 3 additions & 0 deletions pr-checks/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ export const PR_CHECKS_DIR = __dirname;

/** The path of the file configuring which checks shouldn't be required. */
export const PR_CHECK_EXCLUDED_FILE = path.join(PR_CHECKS_DIR, "excluded.yml");

/** The path to the esbuild metadata file. */
export const BUNDLE_METADATA_FILE = path.join(PR_CHECKS_DIR, "..", "meta.json");
14 changes: 1 addition & 13 deletions pr-checks/sync-checks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,9 @@
import * as fs from "fs";
import { parseArgs } from "node:util";

import * as githubUtils from "@actions/github/lib/utils";
import { type Octokit } from "@octokit/core";
import { type PaginateInterface } from "@octokit/plugin-paginate-rest";
import { type Api } from "@octokit/plugin-rest-endpoint-methods";
import * as yaml from "yaml";

import { type ApiClient, getApiClient } from "./api-client";
import {
OLDEST_SUPPORTED_MAJOR_VERSION,
PR_CHECK_EXCLUDED_FILE,
Expand Down Expand Up @@ -49,15 +46,6 @@ function loadExclusions(): Exclusions {
) as Exclusions;
}

/** The type of the Octokit client. */
type ApiClient = Octokit & Api & { paginate: PaginateInterface };

/** Constructs an `ApiClient` using `token` for authentication. */
function getApiClient(token: string): ApiClient {
const opts = githubUtils.getOctokitOptions(token);
return new githubUtils.GitHub(opts);
}

/**
* Represents information about a check run. We track the `app_id` that generated the check,
* because the API will require it in addition to the name in the future.
Expand Down
Loading