diff --git a/lib/analyze-action-post.js b/lib/analyze-action-post.js index 927d8150b..f2a5fc7b7 100644 --- a/lib/analyze-action-post.js +++ b/lib/analyze-action-post.js @@ -26447,7 +26447,7 @@ var require_package = __commonJS({ 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", - test: "npm run transpile && ava src/**.test.ts --serial --verbose", + test: "npm run transpile && ava src/ --serial --verbose", "test-debug": "npm run test -- --timeout=20m", transpile: "tsc --build --verbose" }, diff --git a/lib/analyze-action.js b/lib/analyze-action.js index 042473336..21150349b 100644 --- a/lib/analyze-action.js +++ b/lib/analyze-action.js @@ -32296,7 +32296,7 @@ var require_package = __commonJS({ 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", - test: "npm run transpile && ava src/**.test.ts --serial --verbose", + test: "npm run transpile && ava src/ --serial --verbose", "test-debug": "npm run test -- --timeout=20m", transpile: "tsc --build --verbose" }, diff --git a/lib/autobuild-action.js b/lib/autobuild-action.js index e03abc413..d442a65d0 100644 --- a/lib/autobuild-action.js +++ b/lib/autobuild-action.js @@ -26447,7 +26447,7 @@ var require_package = __commonJS({ 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", - test: "npm run transpile && ava src/**.test.ts --serial --verbose", + test: "npm run transpile && ava src/ --serial --verbose", "test-debug": "npm run test -- --timeout=20m", transpile: "tsc --build --verbose" }, diff --git a/lib/init-action-post.js b/lib/init-action-post.js index b0f821950..b1ae22586 100644 --- a/lib/init-action-post.js +++ b/lib/init-action-post.js @@ -32296,7 +32296,7 @@ var require_package = __commonJS({ 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", - test: "npm run transpile && ava src/**.test.ts --serial --verbose", + test: "npm run transpile && ava src/ --serial --verbose", "test-debug": "npm run test -- --timeout=20m", transpile: "tsc --build --verbose" }, diff --git a/lib/init-action.js b/lib/init-action.js index 0dff011a8..69082d147 100644 --- a/lib/init-action.js +++ b/lib/init-action.js @@ -32296,7 +32296,7 @@ var require_package = __commonJS({ 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", - test: "npm run transpile && ava src/**.test.ts --serial --verbose", + test: "npm run transpile && ava src/ --serial --verbose", "test-debug": "npm run test -- --timeout=20m", transpile: "tsc --build --verbose" }, @@ -86244,6 +86244,52 @@ function getUnknownLanguagesError(languages) { return `Did not recognize the following languages: ${languages.join(", ")}`; } +// src/feature-flags/properties.ts +var RepositoryPropertyName = /* @__PURE__ */ ((RepositoryPropertyName2) => { + RepositoryPropertyName2["EXTRA_QUERIES"] = "github-codeql-extra-queries"; + return RepositoryPropertyName2; +})(RepositoryPropertyName || {}); +async function loadPropertiesFromApi(logger, repositoryNwo) { + try { + const response = await getApiClient().request( + "GET /repos/:owner/:repo/properties/values", + { + owner: repositoryNwo.owner, + repo: repositoryNwo.repo + } + ); + const remoteProperties = response.data; + if (!Array.isArray(remoteProperties)) { + throw new Error( + `Expected repository properties API to return an array, but got: ${JSON.stringify(response.data)}` + ); + } + const knownProperties = new Set(Object.keys(RepositoryPropertyName)); + const properties = {}; + for (const property of remoteProperties) { + if (property.property_name === void 0) { + throw new Error( + `Expected property object to have a 'property_name', but got: ${JSON.stringify(property)}` + ); + } + if (knownProperties.has(property.property_name)) { + properties[property.property_name] = property.value; + } + } + logger.debug("Loaded the following values for the repository properties:"); + for (const [property, value] of Object.entries(properties).sort( + ([nameA], [nameB]) => nameA.localeCompare(nameB) + )) { + logger.debug(` ${property}: ${value}`); + } + return properties; + } catch (e) { + throw new Error( + `Encountered an error while trying to determine repository properties: ${e}` + ); + } +} + // src/config/db-config.ts function shouldCombine(inputValue) { return !!inputValue?.trim().startsWith("+"); @@ -86336,7 +86382,7 @@ function parsePacksFromInput(rawPacksInput, languages, packsInputCombines) { }, []) }; } -async function calculateAugmentation(rawPacksInput, rawQueriesInput, languages) { +async function calculateAugmentation(rawPacksInput, rawQueriesInput, repositoryProperties, languages) { const packsInputCombines = shouldCombine(rawPacksInput); const packsInput = parsePacksFromInput( rawPacksInput, @@ -86348,11 +86394,18 @@ async function calculateAugmentation(rawPacksInput, rawQueriesInput, languages) rawQueriesInput, queriesInputCombines ); + const repoExtraQueries = repositoryProperties["github-codeql-extra-queries" /* EXTRA_QUERIES */]; + const repoExtraQueriesCombines = shouldCombine(repoExtraQueries); + const repoPropertyQueries = { + combines: repoExtraQueriesCombines, + input: parseQueriesFromInput(repoExtraQueries, repoExtraQueriesCombines) + }; return { packsInputCombines, packsInput: packsInput?.[languages[0]], queriesInput, - queriesInputCombines + queriesInputCombines, + repoPropertyQueries }; } function parseQueriesFromInput(rawQueriesInput, queriesInputCombines) { @@ -87517,6 +87570,7 @@ async function initActionState({ const augmentationProperties = await calculateAugmentation( packsInput, queriesInput, + repositoryProperties, languages ); const { trapCaches, trapCacheDownloadTime } = await downloadCacheWithTime( @@ -88111,51 +88165,6 @@ function flushDiagnostics(config) { unwrittenDiagnostics = []; } -// src/feature-flags/properties.ts -var RepositoryPropertyName = /* @__PURE__ */ ((RepositoryPropertyName2) => { - return RepositoryPropertyName2; -})(RepositoryPropertyName || {}); -async function loadPropertiesFromApi(logger, repositoryNwo) { - try { - const response = await getApiClient().request( - "GET /repos/:owner/:repo/properties/values", - { - owner: repositoryNwo.owner, - repo: repositoryNwo.repo - } - ); - const remoteProperties = response.data; - if (!Array.isArray(remoteProperties)) { - throw new Error( - `Expected repository properties API to return an array, but got: ${JSON.stringify(response.data)}` - ); - } - const knownProperties = new Set(Object.keys(RepositoryPropertyName)); - const properties = {}; - for (const property of remoteProperties) { - if (property.property_name === void 0) { - throw new Error( - `Expected property object to have a 'property_name', but got: ${JSON.stringify(property)}` - ); - } - if (knownProperties.has(property.property_name)) { - properties[property.property_name] = property.value; - } - } - logger.debug("Loaded the following values for the repository properties:"); - for (const [property, value] of Object.entries(properties).sort( - ([nameA], [nameB]) => nameA.localeCompare(nameB) - )) { - logger.debug(` ${property}: ${value}`); - } - return properties; - } catch (e) { - throw new Error( - `Encountered an error while trying to determine repository properties: ${e}` - ); - } -} - // src/init.ts var fs15 = __toESM(require("fs")); var path17 = __toESM(require("path")); diff --git a/lib/resolve-environment-action.js b/lib/resolve-environment-action.js index 731fac08e..447d12c65 100644 --- a/lib/resolve-environment-action.js +++ b/lib/resolve-environment-action.js @@ -26447,7 +26447,7 @@ var require_package = __commonJS({ 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", - test: "npm run transpile && ava src/**.test.ts --serial --verbose", + test: "npm run transpile && ava src/ --serial --verbose", "test-debug": "npm run test -- --timeout=20m", transpile: "tsc --build --verbose" }, diff --git a/lib/start-proxy-action-post.js b/lib/start-proxy-action-post.js index 90304233b..adcfb47e4 100644 --- a/lib/start-proxy-action-post.js +++ b/lib/start-proxy-action-post.js @@ -26447,7 +26447,7 @@ var require_package = __commonJS({ 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", - test: "npm run transpile && ava src/**.test.ts --serial --verbose", + test: "npm run transpile && ava src/ --serial --verbose", "test-debug": "npm run test -- --timeout=20m", transpile: "tsc --build --verbose" }, diff --git a/lib/start-proxy-action.js b/lib/start-proxy-action.js index 474b6d820..7a0475a3a 100644 --- a/lib/start-proxy-action.js +++ b/lib/start-proxy-action.js @@ -44975,7 +44975,7 @@ var require_package = __commonJS({ 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", - test: "npm run transpile && ava src/**.test.ts --serial --verbose", + test: "npm run transpile && ava src/ --serial --verbose", "test-debug": "npm run test -- --timeout=20m", transpile: "tsc --build --verbose" }, diff --git a/lib/upload-lib.js b/lib/upload-lib.js index 4c57a9ddb..fe2660b72 100644 --- a/lib/upload-lib.js +++ b/lib/upload-lib.js @@ -33593,7 +33593,7 @@ var require_package = __commonJS({ 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", - test: "npm run transpile && ava src/**.test.ts --serial --verbose", + test: "npm run transpile && ava src/ --serial --verbose", "test-debug": "npm run test -- --timeout=20m", transpile: "tsc --build --verbose" }, diff --git a/lib/upload-sarif-action-post.js b/lib/upload-sarif-action-post.js index 0a92128f7..65af1249c 100644 --- a/lib/upload-sarif-action-post.js +++ b/lib/upload-sarif-action-post.js @@ -26447,7 +26447,7 @@ var require_package = __commonJS({ 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", - test: "npm run transpile && ava src/**.test.ts --serial --verbose", + test: "npm run transpile && ava src/ --serial --verbose", "test-debug": "npm run test -- --timeout=20m", transpile: "tsc --build --verbose" }, diff --git a/lib/upload-sarif-action.js b/lib/upload-sarif-action.js index a1c04da31..f4a55884c 100644 --- a/lib/upload-sarif-action.js +++ b/lib/upload-sarif-action.js @@ -32296,7 +32296,7 @@ var require_package = __commonJS({ 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", - test: "npm run transpile && ava src/**.test.ts --serial --verbose", + test: "npm run transpile && ava src/ --serial --verbose", "test-debug": "npm run test -- --timeout=20m", transpile: "tsc --build --verbose" }, diff --git a/src/config-utils.ts b/src/config-utils.ts index 7a5205c67..d20cf3bae 100644 --- a/src/config-utils.ts +++ b/src/config-utils.ts @@ -459,6 +459,7 @@ export async function initActionState( const augmentationProperties = await calculateAugmentation( packsInput, queriesInput, + repositoryProperties, languages, ); diff --git a/src/config/db-config.test.ts b/src/config/db-config.test.ts index 78750a29a..a5778088f 100644 --- a/src/config/db-config.test.ts +++ b/src/config/db-config.test.ts @@ -1,5 +1,6 @@ import test, { ExecutionContext } from "ava"; +import { RepositoryProperties } from "../feature-flags/properties"; import { KnownLanguage, Language } from "../languages"; import { prettyPrintPack } from "../util"; @@ -190,11 +191,13 @@ const calculateAugmentationMacro = test.macro({ rawPacksInput: string | undefined, rawQueriesInput: string | undefined, languages: Language[], + repositoryProperties: RepositoryProperties, expectedAugmentationProperties: dbConfig.AugmentationProperties, ) => { const actualAugmentationProperties = await dbConfig.calculateAugmentation( rawPacksInput, rawQueriesInput, + repositoryProperties, languages, ); t.deepEqual(actualAugmentationProperties, expectedAugmentationProperties); @@ -208,6 +211,7 @@ test( undefined, undefined, [KnownLanguage.javascript], + {}, { ...dbConfig.defaultAugmentationProperties, }, @@ -219,6 +223,7 @@ test( undefined, " a, b , c, d", [KnownLanguage.javascript], + {}, { ...dbConfig.defaultAugmentationProperties, queriesInput: [{ uses: "a" }, { uses: "b" }, { uses: "c" }, { uses: "d" }], @@ -231,6 +236,7 @@ test( undefined, " + a, b , c, d ", [KnownLanguage.javascript], + {}, { ...dbConfig.defaultAugmentationProperties, queriesInputCombines: true, @@ -244,6 +250,7 @@ test( " codeql/a , codeql/b , codeql/c , codeql/d ", undefined, [KnownLanguage.javascript], + {}, { ...dbConfig.defaultAugmentationProperties, packsInput: ["codeql/a", "codeql/b", "codeql/c", "codeql/d"], @@ -256,6 +263,7 @@ test( " + codeql/a, codeql/b, codeql/c, codeql/d", undefined, [KnownLanguage.javascript], + {}, { ...dbConfig.defaultAugmentationProperties, packsInputCombines: true, @@ -270,6 +278,7 @@ const calculateAugmentationErrorMacro = test.macro({ rawPacksInput: string | undefined, rawQueriesInput: string | undefined, languages: Language[], + repositoryProperties: RepositoryProperties, expectedError: RegExp | string, ) => { await t.throwsAsync( @@ -277,6 +286,7 @@ const calculateAugmentationErrorMacro = test.macro({ dbConfig.calculateAugmentation( rawPacksInput, rawQueriesInput, + repositoryProperties, languages, ), { message: expectedError }, @@ -291,6 +301,7 @@ test( undefined, " + ", [KnownLanguage.javascript], + {}, /The workflow property "queries" is invalid/, ); @@ -300,6 +311,7 @@ test( " + ", undefined, [KnownLanguage.javascript], + {}, /The workflow property "packs" is invalid/, ); @@ -309,6 +321,7 @@ test( " + a/b, c/d ", undefined, [KnownLanguage.javascript, KnownLanguage.java], + {}, /Cannot specify a 'packs' input in a multi-language analysis/, ); @@ -318,6 +331,7 @@ test( " + a/b, c/d ", undefined, [], + {}, /No languages specified/, ); @@ -327,5 +341,6 @@ test( " a-pack-without-a-scope ", undefined, [KnownLanguage.javascript], + {}, /"a-pack-without-a-scope" is not a valid pack/, ); diff --git a/src/config/db-config.ts b/src/config/db-config.ts index 4524b0cda..00f6eaa0c 100644 --- a/src/config/db-config.ts +++ b/src/config/db-config.ts @@ -3,6 +3,10 @@ import * as path from "path"; import * as semver from "semver"; import * as errorMessages from "../error-messages"; +import { + RepositoryProperties, + RepositoryPropertyName, +} from "../feature-flags/properties"; import { Language } from "../languages"; import { cloneObject, ConfigurationError, prettyPrintPack } from "../util"; @@ -41,6 +45,17 @@ export interface UserConfig { "query-filters"?: QueryFilter[]; } +/** + * Represents additional configuration data from a source other than + * a configuration file. + */ +interface Augmentation { + /** Whether or not the `input` combines with data in the base config. */ + combines: boolean; + /** The additional input data. */ + input?: T; +} + /** * Describes how to augment the user config with inputs from the action. * @@ -71,6 +86,11 @@ export interface AugmentationProperties { * The packs input from the `with` block of the action declaration */ packsInput?: string[]; + + /** + * Extra queries from the corresponding repository property. + */ + repoPropertyQueries: Augmentation; } /** @@ -82,6 +102,10 @@ export const defaultAugmentationProperties: AugmentationProperties = { packsInputCombines: false, packsInput: undefined, queriesInput: undefined, + repoPropertyQueries: { + combines: false, + input: undefined, + }, }; /** @@ -256,6 +280,7 @@ export function parsePacksFromInput( * * @param rawPacksInput The packs input from the action configuration. * @param rawQueriesInput The queries input from the action configuration. + * @param repositoryProperties The dictionary of repository properties. * @param languages The languages that the config file is for. If the packs input * is non-empty, then there must be exactly one language. Otherwise, an * error is thrown. @@ -265,10 +290,10 @@ export function parsePacksFromInput( * @throws An error if the packs input is non-empty and the languages input does * not have exactly one language. */ -// exported for testing. export async function calculateAugmentation( rawPacksInput: string | undefined, rawQueriesInput: string | undefined, + repositoryProperties: RepositoryProperties, languages: Language[], ): Promise { const packsInputCombines = shouldCombine(rawPacksInput); @@ -283,11 +308,20 @@ export async function calculateAugmentation( queriesInputCombines, ); + const repoExtraQueries = + repositoryProperties[RepositoryPropertyName.EXTRA_QUERIES]; + const repoExtraQueriesCombines = shouldCombine(repoExtraQueries); + const repoPropertyQueries = { + combines: repoExtraQueriesCombines, + input: parseQueriesFromInput(repoExtraQueries, repoExtraQueriesCombines), + }; + return { packsInputCombines, packsInput: packsInput?.[languages[0]], queriesInput, queriesInputCombines, + repoPropertyQueries, }; } diff --git a/src/feature-flags/properties.ts b/src/feature-flags/properties.ts index 58ae99ffc..fc0905e55 100644 --- a/src/feature-flags/properties.ts +++ b/src/feature-flags/properties.ts @@ -5,7 +5,9 @@ import { RepositoryNwo } from "../repository"; /** * Enumerates repository property names that have some meaning to us. */ -export enum RepositoryPropertyName {} +export enum RepositoryPropertyName { + EXTRA_QUERIES = "github-codeql-extra-queries", +} /** * A repository property has a name and a value.