Use runInActions for the upload-sarif post-action

This commit is contained in:
Michael B. Gale
2026-10-19 19:41:47 +01:00
parent dca467bb23
commit 2a0f9f0e08
2 changed files with 75 additions and 48 deletions

95
lib/entry-points.js generated
View File

@@ -28816,7 +28816,7 @@ var require_light = __commonJS({
}
return this.Events.trigger("scheduled", { args: this.args, options: this.options });
}
async doExecute(chained, clearGlobalState, run11, free) {
async doExecute(chained, clearGlobalState, run12, free) {
var error3, eventInfo, passed;
if (this.retryCount === 0) {
this._assertStatus("RUNNING");
@@ -28836,10 +28836,10 @@ var require_light = __commonJS({
}
} catch (error1) {
error3 = error1;
return this._onFailure(error3, eventInfo, clearGlobalState, run11, free);
return this._onFailure(error3, eventInfo, clearGlobalState, run12, free);
}
}
doExpire(clearGlobalState, run11, free) {
doExpire(clearGlobalState, run12, free) {
var error3, eventInfo;
if (this._states.jobStatus(this.options.id === "RUNNING")) {
this._states.next(this.options.id);
@@ -28847,9 +28847,9 @@ var require_light = __commonJS({
this._assertStatus("EXECUTING");
eventInfo = { args: this.args, options: this.options, retryCount: this.retryCount };
error3 = new BottleneckError$1(`This job timed out after ${this.options.expiration} ms.`);
return this._onFailure(error3, eventInfo, clearGlobalState, run11, free);
return this._onFailure(error3, eventInfo, clearGlobalState, run12, free);
}
async _onFailure(error3, eventInfo, clearGlobalState, run11, free) {
async _onFailure(error3, eventInfo, clearGlobalState, run12, free) {
var retry2, retryAfter;
if (clearGlobalState()) {
retry2 = await this.Events.trigger("failed", error3, eventInfo);
@@ -28857,7 +28857,7 @@ var require_light = __commonJS({
retryAfter = ~~retry2;
this.Events.trigger("retry", `Retrying ${this.options.id} after ${retryAfter} ms`, eventInfo);
this.retryCount++;
return run11(retryAfter);
return run12(retryAfter);
} else {
this.doDone(eventInfo);
await free(this.options, eventInfo);
@@ -29495,17 +29495,17 @@ var require_light = __commonJS({
}
}
_run(index2, job, wait) {
var clearGlobalState, free, run11;
var clearGlobalState, free, run12;
job.doRun();
clearGlobalState = this._clearGlobalState.bind(this, index2);
run11 = this._run.bind(this, index2, job);
run12 = this._run.bind(this, index2, job);
free = this._free.bind(this, index2, job);
return this._scheduled[index2] = {
timeout: setTimeout(() => {
return job.doExecute(this._limiter, clearGlobalState, run11, free);
return job.doExecute(this._limiter, clearGlobalState, run12, free);
}, wait),
expiration: job.options.expiration != null ? setTimeout(function() {
return job.doExpire(clearGlobalState, run11, free);
return job.doExpire(clearGlobalState, run12, free);
}, wait + job.options.expiration) : void 0,
job
};
@@ -51046,14 +51046,14 @@ var require_crc64 = __commonJS({
missingLibrarySymbols.forEach(missingLibrarySymbol);
var calledRun;
dependenciesFulfilled = function runCaller() {
if (!calledRun) run11();
if (!calledRun) run12();
if (!calledRun) dependenciesFulfilled = runCaller;
};
function stackCheckInit() {
_emscripten_stack_init();
writeStackCookie();
}
function run11(args) {
function run12(args) {
args = args || arguments_;
if (runDependencies > 0) {
return;
@@ -51111,7 +51111,7 @@ var require_crc64 = __commonJS({
Module["preInit"].pop()();
}
}
run11();
run12();
function WrapperObject() {
}
WrapperObject.prototype = Object.create(WrapperObject.prototype);
@@ -114994,8 +114994,8 @@ var require_async = __commonJS({
return callback(null, results);
}
while (readyTasks.length && runningTasks < concurrency) {
var run11 = readyTasks.shift();
run11();
var run12 = readyTasks.shift();
run12();
}
}
function addListener(taskName, fn) {
@@ -179643,9 +179643,9 @@ async function addFingerprints(sarifLog, sourceRoot, logger2) {
`Adding fingerprints to SARIF file. See ${"https://docs.github.com/en/code-security/reference/code-scanning/sarif-support-for-code-scanning#data-for-preventing-duplicated-alerts" /* TRACK_CODE_SCANNING_ALERTS_ACROSS_RUNS */} for more information.`
);
const callbacksByFile = {};
for (const run11 of sarifLog.runs || []) {
const artifacts = run11.artifacts || [];
for (const result of run11.results || []) {
for (const run12 of sarifLog.runs || []) {
const artifacts = run12.artifacts || [];
for (const result of run12.results || []) {
const primaryLocation = (result.locations || [])[0];
if (!primaryLocation?.physicalLocation?.artifactLocation) {
logger2.debug(
@@ -179920,8 +179920,8 @@ var InvalidSarifUploadError = class extends Error {
};
function getToolNames(sarifFile) {
const toolNames = {};
for (const run11 of sarifFile.runs || []) {
const tool = run11.tool || {};
for (const run12 of sarifFile.runs || []) {
const tool = run12.tool || {};
const driver = tool.driver || {};
if (typeof driver.name === "string" && driver.name.length > 0) {
toolNames[driver.name] = true;
@@ -179961,17 +179961,17 @@ function combineSarifFiles(sarifFiles, logger2) {
}
function areAllRunsProducedByCodeQL(sarifLogs) {
return sarifLogs.every((sarifLog) => {
return sarifLog.runs?.every((run11) => run11.tool?.driver?.name === "CodeQL");
return sarifLog.runs?.every((run12) => run12.tool?.driver?.name === "CodeQL");
});
}
function createRunKey(run11) {
function createRunKey(run12) {
return {
name: run11.tool?.driver?.name,
fullName: run11.tool?.driver?.fullName,
version: run11.tool?.driver?.version,
semanticVersion: run11.tool?.driver?.semanticVersion,
guid: run11.tool?.driver?.guid,
automationId: run11.automationDetails?.id
name: run12.tool?.driver?.name,
fullName: run12.tool?.driver?.fullName,
version: run12.tool?.driver?.version,
semanticVersion: run12.tool?.driver?.semanticVersion,
guid: run12.tool?.driver?.guid,
automationId: run12.automationDetails?.id
};
}
function areAllRunsUnique(sarifLogs) {
@@ -179980,8 +179980,8 @@ function areAllRunsUnique(sarifLogs) {
if (sarifLog.runs === void 0) {
continue;
}
for (const run11 of sarifLog.runs) {
const key = JSON.stringify(createRunKey(run11));
for (const run12 of sarifLog.runs) {
const key = JSON.stringify(createRunKey(run12));
if (keys.has(key)) {
return false;
}
@@ -180084,9 +180084,9 @@ async function combineSarifFilesUsingCLI(sarifFiles, gitHubVersion, features, lo
function populateRunAutomationDetails(sarifFile, category, analysis_key, environment) {
const automationID = getAutomationID2(category, analysis_key, environment);
if (automationID !== void 0) {
for (const run11 of sarifFile.runs || []) {
if (run11.automationDetails === void 0) {
run11.automationDetails = {
for (const run12 of sarifFile.runs || []) {
if (run12.automationDetails === void 0) {
run12.automationDetails = {
id: automationID
};
}
@@ -180233,13 +180233,13 @@ function countResultsInSarif(sarifLog) {
if (!Array.isArray(parsedSarif.runs)) {
throw new InvalidSarifUploadError("Invalid SARIF. Missing 'runs' array.");
}
for (const run11 of parsedSarif.runs) {
if (!Array.isArray(run11.results)) {
for (const run12 of parsedSarif.runs) {
if (!Array.isArray(run12.results)) {
throw new InvalidSarifUploadError(
"Invalid SARIF. Missing 'results' array in run."
);
}
numResults += run11.results.length;
numResults += run12.results.length;
}
return numResults;
}
@@ -180566,9 +180566,9 @@ function handleProcessingResultForUnsuccessfulExecution(response, status, logger
}
function validateUniqueCategory(sarifLog, sentinelPrefix) {
const categories = {};
for (const run11 of sarifLog.runs || []) {
const id = run11?.automationDetails?.id;
const tool = run11.tool?.driver?.name;
for (const run12 of sarifLog.runs || []) {
const id = run12?.automationDetails?.id;
const tool = run12.tool?.driver?.name;
const category = `${sanitize(id)}_${sanitize(tool)}`;
categories[category] = { id, tool };
}
@@ -180593,9 +180593,9 @@ function filterAlertsByDiffRange(logger2, sarifLog) {
if (sarifLog.runs === void 0) {
return sarifLog;
}
for (const run11 of sarifLog.runs) {
if (run11.results) {
run11.results = run11.results.filter((result) => {
for (const run12 of sarifLog.runs) {
if (run12.results) {
run12.results = run12.results.filter((result) => {
const locations = [
...(result.locations || []).map((loc) => loc.physicalLocation),
...(result.relatedLocations || []).map((loc) => loc.physicalLocation)
@@ -188555,9 +188555,9 @@ async function runWrapper10() {
// src/upload-sarif-action-post.ts
var core28 = __toESM(require_core());
async function runWrapper11() {
async function run11(action) {
const logger2 = action.logger;
try {
const logger2 = getActionsLogger();
restoreInputs(logger2);
const gitHubVersion = await getGitHubVersion();
checkGitHubVersionInRange(gitHubVersion, logger2);
@@ -188579,6 +188579,13 @@ async function runWrapper11() {
);
}
}
var uploadSarifPostAction = {
name: "upload-sarif-post" /* UploadSarifPost */,
run: run11
};
async function runWrapper11() {
await runInActions(uploadSarifPostAction);
}
// actions:entry-points
async function runAnalyzeAction() {

View File

@@ -5,20 +5,29 @@
*/
import * as core from "@actions/core";
import {
ActionName,
runInActions,
type Action,
type ActionState,
} from "./action-common";
import * as actionsUtil from "./actions-util";
import { getGitHubVersion } from "./api-client";
import * as debugArtifacts from "./debug-artifacts";
import { EnvVar } from "./environment";
import { getActionsLogger, withGroup } from "./logging";
import { withGroup } from "./logging";
import { checkGitHubVersionInRange, getErrorMessage } from "./util";
export async function runWrapper() {
/**
* The main functionality of the `upload-sarif` post-action is implemented by this function.
* This is called once by {@link runInActions} after it is called in {@link runWrapper}.
*/
export async function run(action: ActionState<["Logger"]>) {
// To capture errors appropriately, keep as much code within the try-catch as
// possible, and only use safe functions outside.
const logger = action.logger;
try {
const logger = getActionsLogger();
// Restore inputs from `upload-sarif` Action.
actionsUtil.restoreInputs(logger);
const gitHubVersion = await getGitHubVersion();
@@ -43,3 +52,14 @@ export async function runWrapper() {
);
}
}
/** Defines the `upload-sarif` post-action. */
const uploadSarifPostAction: Action = {
name: ActionName.UploadSarifPost,
run,
};
/** The main entry point for the `upload-sarif` post-action. */
export async function runWrapper() {
await runInActions(uploadSarifPostAction);
}