From 3ed0aa3e0a8ecfa6acf0ce1a8724b904027989b0 Mon Sep 17 00:00:00 2001 From: Michael J Mulligan Date: Tue, 6 Apr 2021 22:59:58 +0100 Subject: [PATCH] Add debugging to confirm. --- dist/post_run/index.js | 27 ++++++++++++++++++--------- dist/run/index.js | 27 ++++++++++++++++++--------- src/run.ts | 38 ++++++++++++++++++++++++-------------- 3 files changed, 60 insertions(+), 32 deletions(-) diff --git a/dist/post_run/index.js b/dist/post_run/index.js index d9a9bae..cc95829 100644 --- a/dist/post_run/index.js +++ b/dist/post_run/index.js @@ -6835,37 +6835,46 @@ const logLintIssues = (issues) => { }); }; function resolveCheckRunId() { - var _a; return __awaiter(this, void 0, void 0, function* () { let jobId = -1; - if (process.env.GITHUB_ACTIONS === `true` && process.env.GITHUB_RUN_ID) { + const ctx = github.context; + if (process.env.GITHUB_ACTIONS === `true` && ctx.runId) { try { - core.info(`Attempting to resolve current GitHub Job`); - const ctx = github.context; + core.info(`Attempting to resolve current GitHub Job (${ctx.runId})`); const octokit = github.getOctokit(core.getInput(`github-token`, { required: true })); const { data: workflowResponse } = yield octokit.actions - .listJobsForWorkflowRun(Object.assign(Object.assign({}, ctx.repo), { run_id: parseInt(process.env.GITHUB_RUN_ID) })) + .listJobsForWorkflowRun(Object.assign(Object.assign({}, ctx.repo), { run_id: ctx.runId })) .catch((e) => { throw `Unable to fetch Workflow Job List: ${e}`; }); if (workflowResponse.jobs.length > 0) { + core.info(`resolveCheckRunId() Found ${workflowResponse.jobs.length} Jobs:\n` + util_1.inspect(workflowResponse.jobs)); if (workflowResponse.jobs.length > 1) { - workflowResponse.jobs = (_a = workflowResponse.jobs.filter((run) => run.name.includes(ctx.job))) !== null && _a !== void 0 ? _a : workflowResponse.jobs; + const jobs = workflowResponse.jobs.filter((run) => run.name.includes(ctx.job)); + core.info(`resolveCheckRunId() Found ${jobs.length} Jobs whose name includes '${ctx.job}'`); + workflowResponse.jobs = jobs.length ? jobs : workflowResponse.jobs; } if (workflowResponse.jobs.length > 1) { const searchToken = uuid_1.v4(); core.info(`::warning::[ignore] Resolving GitHub Job with Search Token: ${searchToken}`); for (const job of workflowResponse.jobs) { try { - if ((yield octokit.checks.listAnnotations(Object.assign(Object.assign({}, ctx.repo), { check_run_id: job.id }))).data.findIndex((annotation) => annotation.message.includes(searchToken)) !== -1) { + const { data: annotations } = yield octokit.checks.listAnnotations(Object.assign(Object.assign({}, ctx.repo), { check_run_id: job.id })); + core.info(`resolveCheckRunId() Found ${annotations.length} Annotations for Job '${job.id}':\n` + util_1.inspect(annotations)); + if (annotations.findIndex((annotation) => { + core.info(`resolveCheckRunId() Looking for Search Token (${searchToken}) in message: ${annotation.message}`); + return annotation.message.includes(searchToken); + }) !== -1) { + core.info(`resolveCheckRunId() Found Search Token (${searchToken}) in Job ${job.id}`); jobId = job.id; break; } } catch (e) { - core.info(`::debug::Error Fetching Job ${job.id}: ${e}`); + core.info(`resolveCheckRunId() Error Fetching Job ${job.id}: ${e}`); } } + core.info(`resolveCheckRunId() Finished looking for Search Token`); } else if (workflowResponse.jobs[0]) { jobId = workflowResponse.jobs[0].id; @@ -6884,7 +6893,7 @@ function resolveCheckRunId() { } } else { - core.info(`::debug::Not in GitHub Action Context, Skipping Job Resolution`); + core.info(`Not in GitHub Action Context, Skipping Job Resolution`); } return jobId; }); diff --git a/dist/run/index.js b/dist/run/index.js index 5dbfed6..4de3d51 100644 --- a/dist/run/index.js +++ b/dist/run/index.js @@ -6845,37 +6845,46 @@ const logLintIssues = (issues) => { }); }; function resolveCheckRunId() { - var _a; return __awaiter(this, void 0, void 0, function* () { let jobId = -1; - if (process.env.GITHUB_ACTIONS === `true` && process.env.GITHUB_RUN_ID) { + const ctx = github.context; + if (process.env.GITHUB_ACTIONS === `true` && ctx.runId) { try { - core.info(`Attempting to resolve current GitHub Job`); - const ctx = github.context; + core.info(`Attempting to resolve current GitHub Job (${ctx.runId})`); const octokit = github.getOctokit(core.getInput(`github-token`, { required: true })); const { data: workflowResponse } = yield octokit.actions - .listJobsForWorkflowRun(Object.assign(Object.assign({}, ctx.repo), { run_id: parseInt(process.env.GITHUB_RUN_ID) })) + .listJobsForWorkflowRun(Object.assign(Object.assign({}, ctx.repo), { run_id: ctx.runId })) .catch((e) => { throw `Unable to fetch Workflow Job List: ${e}`; }); if (workflowResponse.jobs.length > 0) { + core.info(`resolveCheckRunId() Found ${workflowResponse.jobs.length} Jobs:\n` + util_1.inspect(workflowResponse.jobs)); if (workflowResponse.jobs.length > 1) { - workflowResponse.jobs = (_a = workflowResponse.jobs.filter((run) => run.name.includes(ctx.job))) !== null && _a !== void 0 ? _a : workflowResponse.jobs; + const jobs = workflowResponse.jobs.filter((run) => run.name.includes(ctx.job)); + core.info(`resolveCheckRunId() Found ${jobs.length} Jobs whose name includes '${ctx.job}'`); + workflowResponse.jobs = jobs.length ? jobs : workflowResponse.jobs; } if (workflowResponse.jobs.length > 1) { const searchToken = uuid_1.v4(); core.info(`::warning::[ignore] Resolving GitHub Job with Search Token: ${searchToken}`); for (const job of workflowResponse.jobs) { try { - if ((yield octokit.checks.listAnnotations(Object.assign(Object.assign({}, ctx.repo), { check_run_id: job.id }))).data.findIndex((annotation) => annotation.message.includes(searchToken)) !== -1) { + const { data: annotations } = yield octokit.checks.listAnnotations(Object.assign(Object.assign({}, ctx.repo), { check_run_id: job.id })); + core.info(`resolveCheckRunId() Found ${annotations.length} Annotations for Job '${job.id}':\n` + util_1.inspect(annotations)); + if (annotations.findIndex((annotation) => { + core.info(`resolveCheckRunId() Looking for Search Token (${searchToken}) in message: ${annotation.message}`); + return annotation.message.includes(searchToken); + }) !== -1) { + core.info(`resolveCheckRunId() Found Search Token (${searchToken}) in Job ${job.id}`); jobId = job.id; break; } } catch (e) { - core.info(`::debug::Error Fetching Job ${job.id}: ${e}`); + core.info(`resolveCheckRunId() Error Fetching Job ${job.id}: ${e}`); } } + core.info(`resolveCheckRunId() Finished looking for Search Token`); } else if (workflowResponse.jobs[0]) { jobId = workflowResponse.jobs[0].id; @@ -6894,7 +6903,7 @@ function resolveCheckRunId() { } } else { - core.info(`::debug::Not in GitHub Action Context, Skipping Job Resolution`); + core.info(`Not in GitHub Action Context, Skipping Job Resolution`); } return jobId; }); diff --git a/src/run.ts b/src/run.ts index d42a4fd..89129a2 100644 --- a/src/run.ts +++ b/src/run.ts @@ -5,7 +5,7 @@ import { exec, ExecOptions } from "child_process" import * as fs from "fs" import * as path from "path" import { dir } from "tmp" -import { promisify } from "util" +import { inspect, promisify } from "util" import { v4 as uuidv4 } from "uuid" import { restoreCache, saveCache } from "./cache" @@ -241,45 +241,55 @@ const logLintIssues = (issues: LintIssue[]): void => { async function resolveCheckRunId(): Promise { let jobId = -1 + const ctx = github.context - if (process.env.GITHUB_ACTIONS === `true` && process.env.GITHUB_RUN_ID) { + if (process.env.GITHUB_ACTIONS === `true` && ctx.runId) { try { - core.info(`Attempting to resolve current GitHub Job`) - const ctx = github.context + core.info(`Attempting to resolve current GitHub Job (${ctx.runId})`) const octokit = github.getOctokit(core.getInput(`github-token`, { required: true })) const { data: workflowResponse } = await octokit.actions .listJobsForWorkflowRun({ ...ctx.repo, - run_id: parseInt(process.env.GITHUB_RUN_ID), + run_id: ctx.runId, }) .catch((e: string) => { throw `Unable to fetch Workflow Job List: ${e}` }) if (workflowResponse.jobs.length > 0) { + core.info(`resolveCheckRunId() Found ${workflowResponse.jobs.length} Jobs:\n` + inspect(workflowResponse.jobs)) if (workflowResponse.jobs.length > 1) { - workflowResponse.jobs = workflowResponse.jobs.filter((run) => run.name.includes(ctx.job)) ?? workflowResponse.jobs + const jobs = workflowResponse.jobs.filter((run) => run.name.includes(ctx.job)) + core.info(`resolveCheckRunId() Found ${jobs.length} Jobs whose name includes '${ctx.job}'`) + workflowResponse.jobs = jobs.length ? jobs : workflowResponse.jobs } if (workflowResponse.jobs.length > 1) { const searchToken = uuidv4() core.info(`::warning::[ignore] Resolving GitHub Job with Search Token: ${searchToken}`) for (const job of workflowResponse.jobs) { try { + const { data: annotations } = await octokit.checks.listAnnotations({ + ...ctx.repo, + check_run_id: job.id, + }) + + core.info(`resolveCheckRunId() Found ${annotations.length} Annotations for Job '${job.id}':\n` + inspect(annotations)) + if ( - ( - await octokit.checks.listAnnotations({ - ...ctx.repo, - check_run_id: job.id, - }) - ).data.findIndex((annotation) => annotation.message.includes(searchToken)) !== -1 + annotations.findIndex((annotation) => { + core.info(`resolveCheckRunId() Looking for Search Token (${searchToken}) in message: ${annotation.message}`) + return annotation.message.includes(searchToken) + }) !== -1 ) { + core.info(`resolveCheckRunId() Found Search Token (${searchToken}) in Job ${job.id}`) jobId = job.id break } } catch (e) { - core.info(`::debug::Error Fetching Job ${job.id}: ${e}`) + core.info(`resolveCheckRunId() Error Fetching Job ${job.id}: ${e}`) } } + core.info(`resolveCheckRunId() Finished looking for Search Token`) } else if (workflowResponse.jobs[0]) { jobId = workflowResponse.jobs[0].id } else { @@ -293,7 +303,7 @@ async function resolveCheckRunId(): Promise { core.info(`::error::Unable to resolve GitHub Job: ${e}`) } } else { - core.info(`::debug::Not in GitHub Action Context, Skipping Job Resolution`) + core.info(`Not in GitHub Action Context, Skipping Job Resolution`) } return jobId