Merge pull request #2572 from github/dbartol/actions-analysis

Add support for `actions` language
This commit is contained in:
Dave Bartolomeo 2024-11-01 14:16:04 -04:00 committed by GitHub
commit cbe1897960
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 46 additions and 14 deletions

View file

@ -64,6 +64,12 @@ export interface RegistryConfigNoCredentials {
// List of globs that determine which packs are associated with this registry.
packages: string[] | string;
// Kind of registry, either "github" or "docker". Default is "docker".
// "docker" refers specifically to the GitHub Container Registry, which is the usual way of sharing CodeQL packs.
// "github" refers to packs published as content in a GitHub repository. This kind of registry is used in scenarios
// where GHCR is not available, such as certain GHES environments.
kind?: "github" | "docker";
}
interface ExcludeQueryFilter {
@ -880,8 +886,8 @@ export function parseRegistriesWithoutCredentials(
registriesInput?: string,
): RegistryConfigNoCredentials[] | undefined {
return parseRegistries(registriesInput)?.map((r) => {
const { url, packages } = r;
return { url, packages };
const { url, packages, kind } = r;
return { url, packages, kind };
});
}
@ -1048,6 +1054,7 @@ function createRegistriesBlock(registries: RegistryConfigWithCredentials[]): {
// ensure the url ends with a slash to avoid a bug in the CLI 2.10.4
url: !registry?.url.endsWith("/") ? `${registry.url}/` : registry.url,
packages: registry.packages,
kind: registry.kind,
}));
const qlconfig = {
registries: safeRegistries,

View file

@ -1,5 +1,6 @@
// All the languages supported by CodeQL
export enum Language {
actions = "actions",
csharp = "csharp",
cpp = "cpp",
go = "go",

View file

@ -4,6 +4,7 @@ import path from "path";
import * as core from "@actions/core";
import test from "ava";
import * as yaml from "js-yaml";
import * as sinon from "sinon";
import * as api from "./api-client";
@ -144,7 +145,7 @@ test("getExtraOptionsEnvParam() succeeds on valid JSON with invalid options (for
process.env.CODEQL_ACTION_EXTRA_OPTIONS = origExtraOptions;
});
test("getExtraOptionsEnvParam() succeeds on valid options", (t) => {
test("getExtraOptionsEnvParam() succeeds on valid JSON options", (t) => {
const origExtraOptions = process.env.CODEQL_ACTION_EXTRA_OPTIONS;
const options = { database: { init: ["--debug"] } };
@ -155,10 +156,21 @@ test("getExtraOptionsEnvParam() succeeds on valid options", (t) => {
process.env.CODEQL_ACTION_EXTRA_OPTIONS = origExtraOptions;
});
test("getExtraOptionsEnvParam() succeeds on valid YAML options", (t) => {
const origExtraOptions = process.env.CODEQL_ACTION_EXTRA_OPTIONS;
const options = { database: { init: ["--debug"] } };
process.env.CODEQL_ACTION_EXTRA_OPTIONS = yaml.dump(options);
t.deepEqual(util.getExtraOptionsEnvParam(), { ...options });
process.env.CODEQL_ACTION_EXTRA_OPTIONS = origExtraOptions;
});
test("getExtraOptionsEnvParam() fails on invalid JSON", (t) => {
const origExtraOptions = process.env.CODEQL_ACTION_EXTRA_OPTIONS;
process.env.CODEQL_ACTION_EXTRA_OPTIONS = "{{invalid-json}}";
process.env.CODEQL_ACTION_EXTRA_OPTIONS = "{{invalid-json}";
t.throws(util.getExtraOptionsEnvParam);
process.env.CODEQL_ACTION_EXTRA_OPTIONS = origExtraOptions;

View file

@ -8,6 +8,7 @@ import * as exec from "@actions/exec/lib/exec";
import checkDiskSpace from "check-disk-space";
import del from "del";
import getFolderSize from "get-folder-size";
import * as yaml from "js-yaml";
import * as semver from "semver";
import * as apiCompatibility from "./api-compatibility.json";
@ -121,7 +122,7 @@ export function getExtraOptionsEnvParam(): object {
return {};
}
try {
return JSON.parse(raw) as object;
return yaml.load(raw) as object;
} catch (unwrappedError) {
const error = wrapError(unwrappedError);
throw new ConfigurationError(