Merge branch 'main' into redsun82/skip-sarif-upload-tests

This commit is contained in:
Paolo Tranquilli
2025-10-09 11:38:10 +02:00
20 changed files with 434 additions and 161 deletions

View File

@@ -3,6 +3,7 @@ import * as path from "path";
import * as core from "@actions/core";
import * as toolrunner from "@actions/exec/lib/toolrunner";
import { RequestError } from "@octokit/request-error";
import * as yaml from "js-yaml";
import {
@@ -370,7 +371,8 @@ export async function setupCodeQL(
} catch (e) {
const ErrorClass =
e instanceof util.ConfigurationError ||
(e instanceof Error && e.message.includes("ENOSPC")) // out of disk space
(e instanceof Error && e.message.includes("ENOSPC")) || // out of disk space
(e instanceof RequestError && e.status === 429) // rate limited
? util.ConfigurationError
: Error;

View File

@@ -723,7 +723,14 @@ export async function getOverlayDatabaseMode(
buildMode !== BuildMode.None &&
(
await Promise.all(
languages.map(async (l) => await codeql.isTracedLanguage(l)),
languages.map(
async (l) =>
l !== KnownLanguage.go && // Workaround to allow overlay analysis for Go with any build
// mode, since it does not yet support BMN. The Go autobuilder and/or extractor will
// ensure that overlay-base databases are only created for supported Go build setups,
// and that we'll fall back to full databases in other cases.
(await codeql.isTracedLanguage(l)),
),
)
).some(Boolean)
) {

View File

@@ -7,11 +7,14 @@ import { pki } from "node-forge";
import * as actionsUtil from "./actions-util";
import { getApiDetails, getAuthorizationHeaderFor } from "./api-client";
import { Config } from "./config-utils";
import { KnownLanguage } from "./languages";
import { getActionsLogger, Logger } from "./logging";
import {
Credential,
getCredentials,
getDownloadUrl,
parseLanguage,
UPDATEJOB_PROXY,
} from "./start-proxy";
import {
@@ -98,6 +101,7 @@ interface StartProxyStatus extends StatusReportBase {
async function sendSuccessStatusReport(
startedAt: Date,
config: Partial<Config>,
registry_types: string[],
logger: Logger,
) {
@@ -105,7 +109,7 @@ async function sendSuccessStatusReport(
ActionName.StartProxy,
"success",
startedAt,
undefined,
config,
await util.checkDiskUsage(logger),
logger,
);
@@ -125,6 +129,7 @@ async function runWrapper() {
actionsUtil.persistInputs();
const logger = getActionsLogger();
let language: KnownLanguage | undefined;
try {
// Setup logging for the proxy
@@ -133,11 +138,13 @@ async function runWrapper() {
core.saveState("proxy-log-file", proxyLogFilePath);
// Get the configuration options
const languageInput = actionsUtil.getOptionalInput("language");
language = languageInput ? parseLanguage(languageInput) : undefined;
const credentials = getCredentials(
logger,
actionsUtil.getOptionalInput("registry_secrets"),
actionsUtil.getOptionalInput("registries_credentials"),
actionsUtil.getOptionalInput("language"),
language,
);
if (credentials.length === 0) {
@@ -165,6 +172,9 @@ async function runWrapper() {
// Report success if we have reached this point.
await sendSuccessStatusReport(
startedAt,
{
languages: language && [language],
},
proxyConfig.all_credentials.map((c) => c.type),
logger,
);
@@ -178,7 +188,9 @@ async function runWrapper() {
ActionName.StartProxy,
getActionsStatus(error),
startedAt,
undefined,
{
languages: language && [language],
},
await util.checkDiskUsage(logger),
logger,
);

View File

@@ -109,7 +109,7 @@ test("getCredentials filters by language when specified", async (t) => {
getRunnerLogger(true),
undefined,
toEncodedJSON(mixedCredentials),
"java",
KnownLanguage.java,
);
t.is(credentials.length, 1);
t.is(credentials[0].type, "maven_repository");
@@ -120,7 +120,7 @@ test("getCredentials returns all for a language when specified", async (t) => {
getRunnerLogger(true),
undefined,
toEncodedJSON(mixedCredentials),
"go",
KnownLanguage.go,
);
t.is(credentials.length, 2);

View File

@@ -79,9 +79,8 @@ export function getCredentials(
logger: Logger,
registrySecrets: string | undefined,
registriesCredentials: string | undefined,
languageString: string | undefined,
language: KnownLanguage | undefined,
): Credential[] {
const language = languageString ? parseLanguage(languageString) : undefined;
const registryTypeForLanguage = language
? LANGUAGE_TO_REGISTRY_TYPE[language]
: undefined;

View File

@@ -92,6 +92,49 @@ test("createStatusReportBase", async (t) => {
});
});
test("createStatusReportBase - empty configuration", async (t) => {
await withTmpDir(async (tmpDir: string) => {
setupEnvironmentAndStub(tmpDir);
const statusReport = await createStatusReportBase(
ActionName.StartProxy,
"success",
new Date("May 19, 2023 05:19:00"),
{},
{ numAvailableBytes: 100, numTotalBytes: 500 },
getRunnerLogger(false),
);
if (t.truthy(statusReport)) {
t.is(statusReport.action_name, ActionName.StartProxy);
t.is(statusReport.status, "success");
}
});
});
test("createStatusReportBase - partial configuration", async (t) => {
await withTmpDir(async (tmpDir: string) => {
setupEnvironmentAndStub(tmpDir);
const statusReport = await createStatusReportBase(
ActionName.StartProxy,
"success",
new Date("May 19, 2023 05:19:00"),
{
languages: ["go"],
},
{ numAvailableBytes: 100, numTotalBytes: 500 },
getRunnerLogger(false),
);
if (t.truthy(statusReport)) {
t.is(statusReport.action_name, ActionName.StartProxy);
t.is(statusReport.status, "success");
t.is(statusReport.languages, "go");
}
});
});
test("createStatusReportBase_firstParty", async (t) => {
await withTmpDir(async (tmpDir: string) => {
setupEnvironmentAndStub(tmpDir);

View File

@@ -260,7 +260,7 @@ export async function createStatusReportBase(
actionName: ActionName,
status: ActionStatus,
actionStartedAt: Date,
config: Config | undefined,
config: Partial<Config> | undefined,
diskInfo: DiskUsage | undefined,
logger: Logger,
cause?: string,
@@ -299,7 +299,7 @@ export async function createStatusReportBase(
action_ref: actionRef,
action_started_at: actionStartedAt.toISOString(),
action_version: getActionVersion(),
analysis_kinds: config?.analysisKinds.join(","),
analysis_kinds: config?.analysisKinds?.join(","),
analysis_key,
build_mode: config?.buildMode,
commit_oid: commitOid,
@@ -324,7 +324,7 @@ export async function createStatusReportBase(
}
if (config) {
statusReport.languages = config.languages.join(",");
statusReport.languages = config.languages?.join(",");
}
if (diskInfo) {