Skip to content

Comment Artifact URL on PR #1

Comment Artifact URL on PR

Comment Artifact URL on PR #1

name: Comment Artifact URL on PR
on:
workflow_run:
types:
- 'completed'
workflows:
- 'Artifact Upload Testnet'
jobs:
comment-on-pr:
if: github.event.workflow_run.conclusion == 'success'
runs-on: ubuntu-latest
steps:
- name: Get Artifact URL & PR Info
env:
GITHUB_TOKEN: ${{ secrets.GH_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"
PREVIOUS_SUITE_ID=$(jq -r '.check_suite_id' <<< "$WORKFLOW_RUN_EVENT_OBJ")
echo "Previous Suite ID: $PREVIOUS_SUITE_ID"
echo "PREVIOUS_SUITE_ID=$PREVIOUS_SUITE_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")
echo "ARTIFACT ID: $ARTIFACT_ID"
echo "ARTIFACT_ID=$ARTIFACT_ID" >> "$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: Update Comment
env:
JOB_PATH: '${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ env.PREVIOUS_JOB_ID }}'
HEAD_SHA: ${{ env.HEAD_SHA }}
SUITES_PATH: '${{ github.server_url }}/${{ github.repository_owner }}/${{ github.event.repository.name }}/suites'
PREVIOUS_SUITE_ID: ${{ env.PREVIOUS_SUITE_ID }}
ARTIFACT_ID: ${{ env.ARTIFACT_ID }}
uses: peter-evans/create-or-update-comment@v2
with:
issue-number: ${{ env.PR_NUMBER }}
body: |-
## Build Preview
[![badge]](${{ env.JOB_PATH }})
You can find files attached to the below linked Workflow Run URL (Logs).
Please note that files only stay for around 90 days!
| Name | Link
| :-------- | :--
| Commit | ${{ env.HEAD_SHA }}
| Logs | ${{ env.JOB_PATH }}
| Network | testnet
| Extension Build | ${{ env.SUITES_PATH }}/${{ env.PREVIOUS_SUITE_ID }}/artifacts/${{ env.ARTIFACT_ID }}
[badge]: https://img.shields.io/badge/Build-Success!-3fb950?logo=github&style=for-the-badge