Skip to content

Commit

Permalink
fix: wrap action summary steps in try/catch (#25)
Browse files Browse the repository at this point in the history
Action summary steps (uploading results artifact, adding job summary and
comment on PR) should not fail the action.
  • Loading branch information
dariuszkuc authored Mar 7, 2023
1 parent ce0887b commit 3142e57
Showing 1 changed file with 26 additions and 13 deletions.
39 changes: 26 additions & 13 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import debug from 'debug';
import { create } from '@actions/artifact';
import { getBooleanInput, getInput, setFailed, summary } from '@actions/core';
import { getBooleanInput, getInput, setFailed, summary, warning } from '@actions/core';
import { context, getOctokit } from '@actions/github';
import {
compatibilityTest,
Expand Down Expand Up @@ -35,27 +35,37 @@ async function main(): Promise<void> {
};
try {
const successful = await compatibilityTest(runtimeConfig);
if (!successful) {
setFailed('Some compatibility tests did not complete successfully.');
}
} catch (e) {
let message;
if (e instanceof Error) {
message = e.message;
} else {
message = String(e);
}
setFailed(message);
}

// add empty log to separate logged results
console.log('');
// add empty log to separate logged results
console.log('');
try {
const results = readFileSync('results.md', 'utf-8');

const artifactPromise = uploadCompatibilityResultsArtifact();
const jobSummaryPromise = commentOnJobSummary(results);
const commentPromise = commentOnThePr(results);

await Promise.all([artifactPromise, jobSummaryPromise, commentPromise]);
if (!successful) {
setFailed('Some compatibility tests did not complete successfully.');
}
} catch (error) {
let message;
if (error instanceof Error) {
message = error.message;
} catch (e) {
let message: string | Error;
if (e instanceof Error) {
message = e;
} else {
message = String(error);
message = String(e);
}
setFailed(message);
warning(message);
}
}

Expand All @@ -68,7 +78,7 @@ async function uploadCompatibilityResultsArtifact() {
const files = ['results.md'];
const workingDirectory = resolve(process.cwd());
const options = {
continueOnError: false,
continueOnError: true,
};
await artifactClient.uploadArtifact(
artifactName,
Expand All @@ -79,6 +89,9 @@ async function uploadCompatibilityResultsArtifact() {
}

async function commentOnJobSummary(results: string) {
logWithTimestamp(
'***********************\ncreating job summary\n***********************',
);
await summary
.addHeading('Apollo Federation Subgraph Compatibility Results')
.addCodeBlock(results)
Expand Down

0 comments on commit 3142e57

Please sign in to comment.