mirror of
https://github.com/github/codeql-action.git
synced 2026-10-30 09:37:15 +00:00
Experiment with checking job cancellation
This commit is contained in:
50
lib/init-action-post.js
generated
50
lib/init-action-post.js
generated
@@ -132907,12 +132907,62 @@ function getFinalJobStatus() {
|
||||
}
|
||||
|
||||
// src/init-action-post.ts
|
||||
async function testCancellationDetection() {
|
||||
const logger = getActionsLogger();
|
||||
try {
|
||||
const apiClient = getApiClient();
|
||||
const runId = getWorkflowRunID();
|
||||
const attemptNumber = getWorkflowRunAttempt();
|
||||
const jobName = process.env["GITHUB_JOB"] || "";
|
||||
const repositoryNwo = getRepositoryNwo();
|
||||
logger.info(
|
||||
`[Cancellation Test] Querying jobs API for run ${runId}, attempt ${attemptNumber}, job "${jobName}"`
|
||||
);
|
||||
const response = await apiClient.rest.actions.listJobsForWorkflowRunAttempt(
|
||||
{
|
||||
owner: repositoryNwo.owner,
|
||||
repo: repositoryNwo.repo,
|
||||
run_id: runId,
|
||||
attempt_number: attemptNumber
|
||||
}
|
||||
);
|
||||
const currentJob = response.data.jobs.find((j) => j.name === jobName);
|
||||
if (currentJob) {
|
||||
logger.info(
|
||||
`[Cancellation Test] Current job status: ${currentJob.status}, conclusion: ${currentJob.conclusion}`
|
||||
);
|
||||
for (const step of currentJob.steps || []) {
|
||||
logger.info(
|
||||
`[Cancellation Test] Step "${step.name}": status=${step.status}, conclusion=${step.conclusion}`
|
||||
);
|
||||
}
|
||||
const hasCancelledStep = currentJob.steps?.some(
|
||||
(step) => step.conclusion === "cancelled"
|
||||
);
|
||||
logger.info(
|
||||
`[Cancellation Test] Has cancelled step: ${hasCancelledStep}`
|
||||
);
|
||||
} else {
|
||||
logger.warning(
|
||||
`[Cancellation Test] Could not find job with name "${jobName}" in API response`
|
||||
);
|
||||
logger.info(
|
||||
`[Cancellation Test] Available jobs: ${response.data.jobs.map((j) => j.name).join(", ")}`
|
||||
);
|
||||
}
|
||||
} catch (error3) {
|
||||
logger.warning(
|
||||
`[Cancellation Test] Failed to query API: ${error3 instanceof Error ? error3.message : String(error3)}`
|
||||
);
|
||||
}
|
||||
}
|
||||
async function run2(startedAt) {
|
||||
const logger = getActionsLogger();
|
||||
let config;
|
||||
let uploadFailedSarifResult;
|
||||
let dependencyCachingUsage;
|
||||
try {
|
||||
await testCancellationDetection();
|
||||
restoreInputs();
|
||||
const gitHubVersion = await getGitHubVersion();
|
||||
checkGitHubVersionInRange(gitHubVersion, logger);
|
||||
|
||||
Reference in New Issue
Block a user