Skip to content

Comment on Pull request #373

Comment on Pull request

Comment on Pull request #373

Workflow file for this run

name: Comment on Pull request
on:
workflow_run:
types:
- completed
workflows:
- 'SIT CI Linux'
permissions:
pull-requests: write
jobs:
comment:
if: github.event.workflow_run.conclusion == 'success'
runs-on: ubuntu-latest
steps:
- name: Find associated pull request
id: pr
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7
with:
script: |
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
console.info("Pull request number is", pullRequestNumber)
return pullRequestNumber
- name: Get Artifact ID
env:
GITHUB_TOKEN: ${{ github.token }}
WORKFLOW_RUN_EVENT_OBJ: ${{ toJSON(github.event.workflow_run) }}
run: |
PREVIOUS_JOB_ID=$(jq -r '.id' <<< "$WORKFLOW_RUN_EVENT_OBJ")
echo "Previous Job ID: $PREVIOUS_JOB_ID"
echo "PREVIOUS_JOB_ID=$PREVIOUS_JOB_ID" >> "$GITHUB_ENV"
SUITE_ID=$(jq -r '.check_suite_id' <<< "$WORKFLOW_RUN_EVENT_OBJ")
echo "Previous Suite ID: $SUITE_ID"
echo "SUITE_ID=$SUITE_ID" >> "$GITHUB_ENV"
ARTIFACT_ID=$(gh api "/repos/${{ github.repository }}/actions/artifacts" \
--jq ".artifacts.[] |
select(.workflow_run.id==${PREVIOUS_JOB_ID}) |
select(.expired==false) |
.id")
echo "Artifact ID: $ARTIFACT_ID"
echo "ARTIFACT_ID=$ARTIFACT_ID" >> "$GITHUB_ENV"
- name: Find Comment
id: find-comment
continue-on-error: true
uses: peter-evans/find-comment@v2
with:
issue-number: ${{ steps.pr.outputs.result }}
comment-author: 'github-actions[bot]'
- name: Create Comment
if: steps.find-comment.outputs.comment-id == ''
env:
JOB_PATH: "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ env.PREVIOUS_JOB_ID }}"
ARTIFACT_URL: "https://github.com/${{ github.repository }}/suites/${{ env.SUITE_ID }}/artifacts/${{ env.ARTIFACT_ID }}"
uses: peter-evans/create-or-update-comment@v3
with:
issue-number: ${{ steps.pr.outputs.result }}
body: |-
![badge]
Build Successful! You can find a link to the downloadable artifact below.
| Name | Link |
| -------- | ----------------------- |
| Commit | ${{ github.event.workflow_run.head_sha }} |
| Logs | ${{ env.JOB_PATH }} |
| Download | ${{ env.ARTIFACT_URL }} |
[badge]: https://img.shields.io/badge/Build_Success!-0d1117?style=for-the-badge&labelColor=3fb950&logo=data:image/svg%2bxml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNCAyNCIgd2lkdGg9IjI0IiBoZWlnaHQ9IjI0IiBmaWxsPSIjZmZmZmZmIj48cGF0aCBkPSJNMjEuMDMgNS43MmEuNzUuNzUgMCAwIDEgMCAxLjA2bC0xMS41IDExLjVhLjc0Ny43NDcgMCAwIDEtMS4wNzItLjAxMmwtNS41LTUuNzVhLjc1Ljc1IDAgMSAxIDEuMDg0LTEuMDM2bDQuOTcgNS4xOTVMMTkuOTcgNS43MmEuNzUuNzUgMCAwIDEgMS4wNiAwWiI+PC9wYXRoPjwvc3ZnPg==
- name: Update Comment
if: steps.find-comment.outputs.comment-id != ''
env:
JOB_PATH: "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ env.PREVIOUS_JOB_ID }}"
ARTIFACT_URL: "https://github.com/${{ github.repository }}/suites/${{ env.SUITE_ID }}/artifacts/${{ env.ARTIFACT_ID }}"
uses: actions/github-script@v7
with:
script: |
const commentId = ${{ steps.find-comment.outputs.comment-id }};
const issueNumber = ${{ steps.pr.outputs.result }};
const body = `
![badge]
Build Successful! You can find a link to the downloadable artifact below.
| Name | Link |
| -------- | ----------------------- |
| Commit | ${{ github.event.workflow_run.head_sha }} |
| Logs | ${{ env.JOB_PATH }} |
| Download | ${{ env.ARTIFACT_URL }} |
[badge]: https://img.shields.io/badge/Build_Success!-0d1117?style=for-the-badge&labelColor=3fb950&logo=data:image/svg%2bxml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNCAyNCIgd2lkdGg9IjI0IiBoZWlnaHQ9IjI0IiBmaWxsPSIjZmZmZmZmIj48cGF0aCBkPSJNMjEuMDMgNS43MmEuNzUuNzUgMCAwIDEgMCAxLjA2bC0xMS41IDExLjVhLjc0Ny43NDcgMCAwIDEtMS4wNzItLjAxMmwtNS41LTUuNzVhLjc1Ljc1IDAgMSAxIDEuMDg0LTEuMDM2bDQuOTcgNS4xOTVMMTkuOTcgNS43MmEuNzUuNzUgMCAwIDEgMS4wNiAwWiI+PC9wYXRoPjwvc3ZnPg==`;
github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: commentId,
body: body
});