Comment artifacts to PR #81
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Comment artifacts to PR | |
# Triggered by the name of the previous | |
on: | |
workflow_run: | |
workflows: ["Build and release dev apps"] | |
types: [completed] | |
permissions: | |
pull-requests: write | |
jobs: | |
comment: | |
if: github.event.workflow_run.conclusion == 'success' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Get Artifacts Links | |
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" >> "$GITHUB_ENV" | |
LINUX_ARTIFACT_ID=$(gh api "/repos/$OWNER/$REPO/actions/artifacts" --jq ".artifacts.[] | select(.workflow_run.id==$PREVIOUS_JOB_ID) | select(.expired==false) | select(.name==\"linux-app.AppImage\") | .id") | |
WIN_ARTIFACT_ID=$(gh api "/repos/$OWNER/$REPO/actions/artifacts" --jq ".artifacts.[] | select(.workflow_run.id==$PREVIOUS_JOB_ID) | select(.expired==false) | select(.name==\"win-app.exe\") | .id") | |
MACOS_ARTIFACT_ID=$(gh api "/repos/$OWNER/$REPO/actions/artifacts" --jq ".artifacts.[] | select(.workflow_run.id==$PREVIOUS_JOB_ID) | select(.expired==false) | select(.name==\"macos-app.dmg\") | .id") | |
echo "LINUX_ARTIFACT_ID=$LINUX_ARTIFACT_ID" >> "$GITHUB_ENV" | |
echo "WIN_ARTIFACT_ID=$WIN_ARTIFACT_ID" >> "$GITHUB_ENV" | |
echo "MACOS_ARTIFACT_ID=$MACOS_ARTIFACT_ID" >> "$GITHUB_ENV" | |
PR_NUMBER=$(jq -r '.pull_requests[0].number' <<< "$WORKFLOW_RUN_EVENT_OBJ") | |
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" >> "$GITHUB_ENV" | |
- name: Update 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@v2 | |
with: | |
issue-number: ${{ env.PR_NUMBER }} | |
body: |- | |
Automatic builds from https://github.com/${{github.repository_owner}}/${{github.event.repository.name}}/actions/runs/${{ env.PREVIOUS_JOB_ID }}. | |
Commit: ${{ env.HEAD_SHA }} | |
| Name | Platform | Link | | |
|-----------|----------|------| | |
| win-app.exe | Windows | [Link](https://github.com/${{github.repository_owner}}/${{github.event.repository.name}}/actions/runs/${{ env.PREVIOUS_JOB_ID }}/artifacts/${{ env.WIN_ARTIFACT_ID }}) | | |
| macos-app.dmg | MacOS | [Link](https://github.com/${{github.repository_owner}}/${{github.event.repository.name}}/actions/runs/${{ env.PREVIOUS_JOB_ID }}/artifacts/${{ env.MACOS_ARTIFACT_ID }}) | | |
| linux-app.AppImage | Linux | [Link](https://github.com/${{github.repository_owner}}/${{github.event.repository.name}}/actions/runs/${{ env.PREVIOUS_JOB_ID }}/artifacts/${{ env.LINUX_ARTIFACT_ID }}) | |