Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: add job summary to check status #211

Merged
merged 10 commits into from
May 15, 2024
1 change: 1 addition & 0 deletions .github/examples/tf_via_pr_comments.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ jobs:

permissions:
actions: read # Required for workflow query and artifact download.
checks: write # Required for adding summary to check status.
contents: read # Required for repository checkout.
issues: read # Required for getting PR branch from issue comment.
pull-requests: write # Required for commenting on PR.
Expand Down
1 change: 1 addition & 0 deletions .github/examples/tf_via_pr_comments_or_input.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ jobs:

permissions:
actions: read # Required for workflow query and artifact download.
checks: write # Required for adding summary to check status.
contents: read # Required for repository checkout.
issues: read # Required for getting PR branch from issue comment.
pull-requests: write # Required for commenting on PR.
Expand Down
1 change: 1 addition & 0 deletions .github/examples/tf_via_pr_input.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ jobs:

permissions:
actions: read # Required for workflow query and artifact download.
checks: write # Required for adding summary to check status.
contents: read # Required for repository checkout.
id-token: write # Required for assuming AWS role via OIDC provider.
pull-requests: write # Required for commenting on PR.
Expand Down
1 change: 1 addition & 0 deletions .github/examples/tf_via_pr_input_matrix.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ jobs:

permissions:
actions: read # Required for workflow query and artifact download.
checks: write # Required for adding summary to check status.
contents: read # Required for repository checkout.
pull-requests: write # Required for commenting on PR.

Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/tf_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ jobs:

permissions:
actions: read # Required for workflow query and artifact download.
checks: write # Required for adding summary to check status.
contents: read # Required for repository checkout.
issues: read # Required for getting PR branch from issue comment.
pull-requests: write # Required for commenting on PR.
statuses: write # Required for setting commit status from issue comment.

steps:
- name: Checkout repository
Expand Down
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ runs:
retries: 3
script: await require(`${process.env.GITHUB_ACTION_PATH}/scripts/remove_reaction.js`)({ github, context });

# On issue_comment, update commit status with job status before exiting.
# On issue_comment, update commit status with the job status before exiting.
- name: Update commit status
if: ${{ (success() || failure()) && github.event.issue.pull_request }}
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
Expand Down
20 changes: 18 additions & 2 deletions scripts/comment_tf_output.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,25 @@ ${process.env.tf_fmt}
});
const matrix = JSON.parse(process.env.matrix);
const job_name = `${context.job}${matrix ? ` (${Object.values(matrix).join(", ")})` : ""}`;
const job_url = workflow_run.jobs.find((job) => job.name === job_name).html_url;
const check_url = workflow_run.jobs.find((job) => job.name === job_name).html_url;
const check_id = workflow_run.jobs.find((job) => job.name === job_name).id;

// Update the check status with TF output summary.
const update_check_status = await github.rest.checks.update({
check_run_id: check_id,
output: {
summary: comment_summary,
title: comment_summary,
},
owner: context.repo.owner,
repo: context.repo.repo,
});

// Display the: TF command, TF output, and workflow authorip.
const comment_output = `
<details><summary>${comment_summary}</br>

###### ${context.workflow} by @${context.actor} via [${context.eventName}](${job_url}) at ${context.payload.pull_request?.updated_at || context.payload.comment?.updated_at}.</summary>
###### ${context.workflow} by @${context.actor} via [${context.eventName}](${check_url}) at ${context.payload.pull_request?.updated_at || context.payload.comment?.updated_at}.</summary>

\`\`\`hcl
${process.env.tf_output}
Expand All @@ -51,6 +63,10 @@ ${comment_output}

<!-- ${process.env.tf_plan_id} -->`;

// Display the comment body as a job summary.
core.summary.addRaw(comment_body);
core.summary.write();

// Check if the bot has commented on the PR using the TFPLAN identifier.
const { data: list_comments } = await github.rest.issues.listComments({
issue_number: context.issue.number,
Expand Down
Loading