Skip to content

CICD Comment

CICD Comment #10

Workflow file for this run

name: CICD Comment
on:
workflow_run:
workflows:
- CICD Build
types:
- completed
jobs:
comment:
if: ${{ github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'pull_request' }}
runs-on: ubuntu-22.04
steps:
- name: Get Artifact URL and PR Info
env:
GITHUB_TOKEN: ${{ github.token }}
OWNER: ${{ github.repository_owner }}
REPO: ${{ github.event.repository.name }}
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"
ARTIFACT_ID=$(gh api "/repos/$OWNER/$REPO/actions/artifacts" --jq ".artifacts.[] |
select(.workflow_run.id==${PREVIOUS_JOB_ID}) |
select(.expired==false) |
.id")
ARTIFACT_URL="https://github.com/${{ github.repository }}/suites/${{ github.event.workflow_run.check_suite_id }}/artifacts/${ARTIFACT_ID}"
echo "ARTIFACT URL: $ARTIFACT_URL"
echo "ARTIFACT_URL=$ARTIFACT_URL" >> "$GITHUB_ENV"
PR_NUMBER=$(jq -r '.pull_requests[0].number' <<< "$WORKFLOW_RUN_EVENT_OBJ")
echo "PR Number: $PR_NUMBER"
echo "PR_NUMBER=$PR_NUMBER" >> "$GITHUB_ENV"
HEAD_SHA=$(jq -r '.pull_requests[0].head.sha' <<< "$WORKFLOW_RUN_EVENT_OBJ")
echo "Head sha: $HEAD_SHA"
echo "HEAD_SHA=$HEAD_SHA" >> "$GITHUB_ENV"
- name: Find Comment
uses: peter-evans/find-comment@v2
id: fc
with:
issue-number: ${{ env.PR_NUMBER }}
body-includes: '**Artifacts**'
- name: Comment
env:
JOB_PATH: "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ env.PREVIOUS_JOB_ID }}"
HEAD_SHA: ${{ env.HEAD_SHA }}
uses: peter-evans/create-or-update-comment@v3
with:
issue-number: ${{ env.PR_NUMBER }}
comment-id: ${{ steps.fc.outputs.comment-id }}
edit-mode: replace
body: |-
**Artifacts**
_Please note that files only stay around for a few days._
| Name | Link |
| --------- | --- |
| Commit | ${{ env.HEAD_SHA }} |
| Logs | ${{ env.JOB_PATH }} |
| Files | ${{ env.ARTIFACT_URL }} |