Add debugging to confirm.

This commit is contained in:
Michael J Mulligan 2021-04-06 22:59:58 +01:00
parent ff77f2c863
commit 3ed0aa3e0a
3 changed files with 60 additions and 32 deletions

View file

@ -6835,37 +6835,46 @@ const logLintIssues = (issues) => {
}); });
}; };
function resolveCheckRunId() { function resolveCheckRunId() {
var _a;
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
let jobId = -1; 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 { try {
core.info(`Attempting to resolve current GitHub Job`); core.info(`Attempting to resolve current GitHub Job (${ctx.runId})`);
const ctx = github.context;
const octokit = github.getOctokit(core.getInput(`github-token`, { required: true })); const octokit = github.getOctokit(core.getInput(`github-token`, { required: true }));
const { data: workflowResponse } = yield octokit.actions 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) => { .catch((e) => {
throw `Unable to fetch Workflow Job List: ${e}`; throw `Unable to fetch Workflow Job List: ${e}`;
}); });
if (workflowResponse.jobs.length > 0) { if (workflowResponse.jobs.length > 0) {
core.info(`resolveCheckRunId() Found ${workflowResponse.jobs.length} Jobs:\n` + util_1.inspect(workflowResponse.jobs));
if (workflowResponse.jobs.length > 1) { 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) { if (workflowResponse.jobs.length > 1) {
const searchToken = uuid_1.v4(); const searchToken = uuid_1.v4();
core.info(`::warning::[ignore] Resolving GitHub Job with Search Token: ${searchToken}`); core.info(`::warning::[ignore] Resolving GitHub Job with Search Token: ${searchToken}`);
for (const job of workflowResponse.jobs) { for (const job of workflowResponse.jobs) {
try { 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; jobId = job.id;
break; break;
} }
} }
catch (e) { 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]) { else if (workflowResponse.jobs[0]) {
jobId = workflowResponse.jobs[0].id; jobId = workflowResponse.jobs[0].id;
@ -6884,7 +6893,7 @@ function resolveCheckRunId() {
} }
} }
else { else {
core.info(`::debug::Not in GitHub Action Context, Skipping Job Resolution`); core.info(`Not in GitHub Action Context, Skipping Job Resolution`);
} }
return jobId; return jobId;
}); });

27
dist/run/index.js vendored
View file

@ -6845,37 +6845,46 @@ const logLintIssues = (issues) => {
}); });
}; };
function resolveCheckRunId() { function resolveCheckRunId() {
var _a;
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
let jobId = -1; 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 { try {
core.info(`Attempting to resolve current GitHub Job`); core.info(`Attempting to resolve current GitHub Job (${ctx.runId})`);
const ctx = github.context;
const octokit = github.getOctokit(core.getInput(`github-token`, { required: true })); const octokit = github.getOctokit(core.getInput(`github-token`, { required: true }));
const { data: workflowResponse } = yield octokit.actions 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) => { .catch((e) => {
throw `Unable to fetch Workflow Job List: ${e}`; throw `Unable to fetch Workflow Job List: ${e}`;
}); });
if (workflowResponse.jobs.length > 0) { if (workflowResponse.jobs.length > 0) {
core.info(`resolveCheckRunId() Found ${workflowResponse.jobs.length} Jobs:\n` + util_1.inspect(workflowResponse.jobs));
if (workflowResponse.jobs.length > 1) { 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) { if (workflowResponse.jobs.length > 1) {
const searchToken = uuid_1.v4(); const searchToken = uuid_1.v4();
core.info(`::warning::[ignore] Resolving GitHub Job with Search Token: ${searchToken}`); core.info(`::warning::[ignore] Resolving GitHub Job with Search Token: ${searchToken}`);
for (const job of workflowResponse.jobs) { for (const job of workflowResponse.jobs) {
try { 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; jobId = job.id;
break; break;
} }
} }
catch (e) { 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]) { else if (workflowResponse.jobs[0]) {
jobId = workflowResponse.jobs[0].id; jobId = workflowResponse.jobs[0].id;
@ -6894,7 +6903,7 @@ function resolveCheckRunId() {
} }
} }
else { else {
core.info(`::debug::Not in GitHub Action Context, Skipping Job Resolution`); core.info(`Not in GitHub Action Context, Skipping Job Resolution`);
} }
return jobId; return jobId;
}); });

View file

@ -5,7 +5,7 @@ import { exec, ExecOptions } from "child_process"
import * as fs from "fs" import * as fs from "fs"
import * as path from "path" import * as path from "path"
import { dir } from "tmp" import { dir } from "tmp"
import { promisify } from "util" import { inspect, promisify } from "util"
import { v4 as uuidv4 } from "uuid" import { v4 as uuidv4 } from "uuid"
import { restoreCache, saveCache } from "./cache" import { restoreCache, saveCache } from "./cache"
@ -241,45 +241,55 @@ const logLintIssues = (issues: LintIssue[]): void => {
async function resolveCheckRunId(): Promise<number> { async function resolveCheckRunId(): Promise<number> {
let jobId = -1 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 { try {
core.info(`Attempting to resolve current GitHub Job`) core.info(`Attempting to resolve current GitHub Job (${ctx.runId})`)
const ctx = github.context
const octokit = github.getOctokit(core.getInput(`github-token`, { required: true })) const octokit = github.getOctokit(core.getInput(`github-token`, { required: true }))
const { data: workflowResponse } = await octokit.actions const { data: workflowResponse } = await octokit.actions
.listJobsForWorkflowRun({ .listJobsForWorkflowRun({
...ctx.repo, ...ctx.repo,
run_id: parseInt(process.env.GITHUB_RUN_ID), run_id: ctx.runId,
}) })
.catch((e: string) => { .catch((e: string) => {
throw `Unable to fetch Workflow Job List: ${e}` throw `Unable to fetch Workflow Job List: ${e}`
}) })
if (workflowResponse.jobs.length > 0) { if (workflowResponse.jobs.length > 0) {
core.info(`resolveCheckRunId() Found ${workflowResponse.jobs.length} Jobs:\n` + inspect(workflowResponse.jobs))
if (workflowResponse.jobs.length > 1) { 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) { if (workflowResponse.jobs.length > 1) {
const searchToken = uuidv4() const searchToken = uuidv4()
core.info(`::warning::[ignore] Resolving GitHub Job with Search Token: ${searchToken}`) core.info(`::warning::[ignore] Resolving GitHub Job with Search Token: ${searchToken}`)
for (const job of workflowResponse.jobs) { for (const job of workflowResponse.jobs) {
try { 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 ( if (
( annotations.findIndex((annotation) => {
await octokit.checks.listAnnotations({ core.info(`resolveCheckRunId() Looking for Search Token (${searchToken}) in message: ${annotation.message}`)
...ctx.repo, return annotation.message.includes(searchToken)
check_run_id: job.id, }) !== -1
})
).data.findIndex((annotation) => annotation.message.includes(searchToken)) !== -1
) { ) {
core.info(`resolveCheckRunId() Found Search Token (${searchToken}) in Job ${job.id}`)
jobId = job.id jobId = job.id
break break
} }
} catch (e) { } 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]) { } else if (workflowResponse.jobs[0]) {
jobId = workflowResponse.jobs[0].id jobId = workflowResponse.jobs[0].id
} else { } else {
@ -293,7 +303,7 @@ async function resolveCheckRunId(): Promise<number> {
core.info(`::error::Unable to resolve GitHub Job: ${e}`) core.info(`::error::Unable to resolve GitHub Job: ${e}`)
} }
} else { } else {
core.info(`::debug::Not in GitHub Action Context, Skipping Job Resolution`) core.info(`Not in GitHub Action Context, Skipping Job Resolution`)
} }
return jobId return jobId