Skip to content

Commit

Permalink
feat: use action to update comment with check ressults
Browse files Browse the repository at this point in the history
use edumserrano/find-create-or-update-comment to update existing comment
instead of creating new when checks are run.
  • Loading branch information
bateau84 committed Aug 24, 2023
1 parent 187856d commit 7a4b2ae
Showing 1 changed file with 16 additions and 20 deletions.
36 changes: 16 additions & 20 deletions .github/workflows/workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -248,27 +248,23 @@ jobs:
echo "exit_code=${?}" >> $GITHUB_OUTPUT
continue-on-error: true

- name: Post results as comment
uses: actions/github-script@v6
if: github.event.pull_request && github.actor != 'dependabot[bot]' && inputs.status-comment-enabled
- name: Post/update results as comment
uses: edumserrano/[email protected]
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const bool_emoji = (v) => Boolean(v) ? '✔️' : '❌';
const data = {
url: 'https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}',
fmt: bool_emoji(${{ steps.fmt.outputs.exit_code == '0' }}),
init: bool_emoji(${{ steps.init.outputs.exit_code == '0' }}),
validate: bool_emoji(${{ steps.validate.outputs.exit_code == '0' }}),
status: Boolean(${{ steps.fmt.outputs.exit_code == '0' && steps.init.outputs.exit_code == '0' && steps.validate.outputs.exit_code == '0' }})
}
const body = `format: ${data.fmt} | init: ${data.init} | validate: ${data.validate}\n[check](${data.url}) ${data.status ? 'succeeded' : 'failed'}:\n\n${{ inputs.status-comment-message }}`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: body,
});
issue-number: ${{ github.event.pull_request.number }}
body-includes: '<!-- terraform-test-results -->'
comment-author: 'github-actions[bot]'
body: |
<!-- terraform-test-results -->
format: ${{ steps.fmt.outputs.exit_code == '0' ? '✔️' : '❌' }}
init: ${{ steps.inti.outputs.exit_code == '0' ? '✔️' : '❌' }}
validate: ${{ steps.validate.outputs.exit_code == '0' ? '✔️' : '❌' }}
[check](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}) ${steps.fmt.outputs.exit_code == '0' ? 'succeeded' : 'failed'}
${{ inputs.status-comment-message }}
edit-mode: replace

- name: Determine job exit status
shell: python
Expand Down

0 comments on commit 7a4b2ae

Please sign in to comment.