2023-09-07 05:14:00 +08:00
name : Automated tests - publish results
2023-08-23 22:09:43 +08:00
on :
workflow_run :
workflows :
- Automated tests
types :
- completed
2024-07-16 19:49:17 +08:00
- requested
env :
isCompleted : ${{ github.event.workflow_run.status == 'completed' }}
2023-08-23 22:09:43 +08:00
jobs :
get-pr-data :
runs-on : ubuntu-latest
if : ${{ github.event.workflow_run.event == 'pull_request' }}
outputs :
2024-07-16 19:49:17 +08:00
pr-number : ${{ steps.pr.outputs.result }}
workflow-id : ${{ github.event.workflow_run.id }}
2023-08-23 22:09:43 +08:00
steps :
2024-07-16 19:49:17 +08:00
- name : Find associated pull request
id : pr
uses : actions/github-script@v7
2023-08-23 22:09:43 +08:00
with :
script : |
2024-07-16 19:49:17 +08:00
const response = await github.rest.search.issuesAndPullRequests({
q : 'repo:${{ github.repository }} is:pr sha:${{ github.event.workflow_run.head_sha }}' ,
per_page : 1 ,
})
const items = response.data.items
if (items.length < 1) {
console.error('No PRs found')
return
}
const pullRequestNumber = items[0].number
return pullRequestNumber
2023-08-23 22:09:43 +08:00
comment-pr :
runs-on : ubuntu-latest
permissions :
pull-requests : write
needs : get-pr-data
steps :
- name : Find Comment
2024-07-16 19:50:56 +08:00
uses : peter-evans/find-comment@v3
2023-08-23 22:09:43 +08:00
id : fc
with :
issue-number : ${{ needs.get-pr-data.outputs.pr-number }}
comment-author : "github-actions[bot]"
body-includes : Automated tests Summary
- name : Remove previous comment
if : steps.fc.outputs.comment-id != ''
2024-07-16 19:50:56 +08:00
uses : actions/github-script@v7
2023-08-23 22:09:43 +08:00
with :
script : |
github.rest.issues.deleteComment({
owner : context.repo.owner,
repo : context.repo.repo,
comment_id : ${{ steps.fc.outputs.comment-id }}
})
2024-07-16 19:49:17 +08:00
- name : In progress tests comment
if : ${{ !fromJson(env.isCompleted) }}
uses : peter-evans/create-or-update-comment@v4
with :
issue-number : ${{ needs.get-pr-data.outputs.pr-number }}
body : |
<h1>Automated tests Summary</h1>
<h3><strong>:construction:</strong> Tests are running...</h3>
2023-08-23 22:09:43 +08:00
- name : Passing tests comment
if : ${{ github.event.workflow_run.conclusion == 'success' }}
2024-07-16 19:50:56 +08:00
uses : peter-evans/create-or-update-comment@v4
2023-08-23 22:09:43 +08:00
with :
issue-number : ${{ needs.get-pr-data.outputs.pr-number }}
body : |
<h1>Automated tests Summary</h1>
<h3><strong>:white_check_mark:</strong> All the CI tests have passed!</h3>
- name : Failing tests comment
2024-07-16 19:49:17 +08:00
if : ${{ github.event.workflow_run.conclusion != 'success' && fromJson(env.isCompleted) }}
2024-07-16 19:50:56 +08:00
uses : peter-evans/create-or-update-comment@v4
2023-08-23 22:09:43 +08:00
with :
issue-number : ${{ needs.get-pr-data.outputs.pr-number }}
body : |
<h1> Automated tests Summary</h1>
<h3><strong>:rotating_light:</strong> Test workflow has failed</h3>
___
[ Click here](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ needs.get-pr-data.outputs.workflow-id }}) to check the action test reports