Skip to content

PR Comment - Build Complete #122

PR Comment - Build Complete

PR Comment - Build Complete #122

name: PR Comment - Build Complete
on:
workflow_run:
workflows: ["Build AffinityPluginLoader"]
types:
- completed
jobs:
pr-comment-completed:
name: Post PR Comment with Build Result
runs-on: ubuntu-latest
if: github.event.workflow_run.event == 'pull_request'
permissions:
pull-requests: write
actions: read
steps:
- name: Get PR number from branch
id: pr
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_BRANCH: |-
${{
(github.event.workflow_run.head_repository.owner.login != github.event.workflow_run.repository.owner.login)
&& format('{0}:{1}', github.event.workflow_run.head_repository.owner.login, github.event.workflow_run.head_branch)
|| github.event.workflow_run.head_branch
}}
run: |
PR_NUMBER=$(gh pr view "$PR_BRANCH" --repo ${{ github.repository }} --json number --jq '.number')
echo "number=$PR_NUMBER" >> $GITHUB_OUTPUT
- name: Download commit SHA artifact
uses: actions/download-artifact@v4
with:
name: commit_sha
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Get commit and run info
id: run-info
run: |
echo "short_sha=$(cat commit_sha.txt | cut -c1-7)" >> $GITHUB_OUTPUT
echo "run_id=${{ github.event.workflow_run.id }}" >> $GITHUB_OUTPUT
echo "conclusion=${{ github.event.workflow_run.conclusion }}" >> $GITHUB_OUTPUT
echo "timestamp=$(date -u +'%B %-d, %Y at %H:%M UTC')" >> $GITHUB_OUTPUT
- name: Find existing comment
uses: peter-evans/find-comment@v3
id: find-comment
with:
issue-number: ${{ steps.pr.outputs.number }}
comment-author: "github-actions[bot]"
body-includes: "<!-- affinitypluginloader-build-artifacts -->"
- name: Get last successful build (if current failed)
if: steps.run-info.outputs.conclusion != 'success'
id: last-success
uses: actions/github-script@v7
with:
script: |
const runs = await github.rest.actions.listWorkflowRuns({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: 'build.yml',
branch: 'main',
status: 'success',
per_page: 1
});
if (runs.data.workflow_runs.length > 0) {
const lastRun = runs.data.workflow_runs[0];
return {
run_id: lastRun.id,
commit_sha: lastRun.head_sha.substring(0, 7)
};
}
return null;
result-encoding: json
- name: Create or update PR comment (success)
if: steps.run-info.outputs.conclusion == 'success'
uses: peter-evans/create-or-update-comment@v4
with:
comment-id: ${{ steps.find-comment.outputs.comment-id }}
issue-number: ${{ steps.pr.outputs.number }}
edit-mode: replace
body: |
<!-- affinitypluginloader-build-artifacts -->
## 🚀 Build Artifacts Ready
**Commit:** `${{ steps.run-info.outputs.short_sha }}`
**Build Timestamp:** ${{ steps.run-info.outputs.timestamp }}
**Build Workflow:** [View Run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ steps.run-info.outputs.run_id }})
### 📦 Direct Downloads (via nightly.link):
- **[affinitypluginloader-${{ steps.run-info.outputs.short_sha }}-x64.zip](https://nightly.link/${{ github.repository }}/actions/runs/${{ steps.run-info.outputs.run_id }}/affinitypluginloader-${{ steps.run-info.outputs.short_sha }}-x64.zip)** - Main loader package
- **[apl-winefix-${{ steps.run-info.outputs.short_sha }}-x64.zip](https://nightly.link/${{ github.repository }}/actions/runs/${{ steps.run-info.outputs.run_id }}/apl-winefix-${{ steps.run-info.outputs.short_sha }}-x64.zip)** - WineFix plugin
- **[affinitypluginloader-plus-winefix-${{ steps.run-info.outputs.short_sha }}-x64.tar.xz.zip](https://nightly.link/${{ github.repository }}/actions/runs/${{ steps.run-info.outputs.run_id }}/affinitypluginloader-plus-winefix-${{ steps.run-info.outputs.short_sha }}-x64.tar.xz.zip)** - Combined package (tar.xz)
- **[release-archives-${{ steps.run-info.outputs.short_sha }}.zip](https://nightly.link/${{ github.repository }}/actions/runs/${{ steps.run-info.outputs.run_id }}/release-archives-${{ steps.run-info.outputs.short_sha }}.zip)** - All release archives
- name: Create or update PR comment (failure with previous success)
if: steps.run-info.outputs.conclusion != 'success' && steps.last-success.outputs.result != 'null'
uses: peter-evans/create-or-update-comment@v4
with:
comment-id: ${{ steps.find-comment.outputs.comment-id }}
issue-number: ${{ steps.pr.outputs.number }}
edit-mode: replace
body: |
<!-- affinitypluginloader-build-artifacts -->
## ❌ Build Failed
**Commit:** `${{ steps.run-info.outputs.short_sha }}`
**Build Timestamp:** ${{ steps.run-info.outputs.timestamp }}
**Failed Workflow:** [View Run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ steps.run-info.outputs.run_id }})
The build failed for this commit. Please check the workflow logs for details.
---
### 📦 Last Successful Build (`${{ fromJson(steps.last-success.outputs.result).commit_sha }}`):
- **[affinitypluginloader-${{ fromJson(steps.last-success.outputs.result).commit_sha }}-x64.zip](https://nightly.link/${{ github.repository }}/actions/runs/${{ fromJson(steps.last-success.outputs.result).run_id }}/affinitypluginloader-${{ fromJson(steps.last-success.outputs.result).commit_sha }}-x64.zip)** - Main loader package
- **[apl-winefix-${{ fromJson(steps.last-success.outputs.result).commit_sha }}-x64.zip](https://nightly.link/${{ github.repository }}/actions/runs/${{ fromJson(steps.last-success.outputs.result).run_id }}/apl-winefix-${{ fromJson(steps.last-success.outputs.result).commit_sha }}-x64.zip)** - WineFix plugin
- **[affinitypluginloader-plus-winefix-${{ fromJson(steps.last-success.outputs.result).commit_sha }}-x64.tar.xz.zip](https://nightly.link/${{ github.repository }}/actions/runs/${{ fromJson(steps.last-success.outputs.result).run_id }}/affinitypluginloader-plus-winefix-${{ fromJson(steps.last-success.outputs.result).commit_sha }}-x64.tar.xz.zip)** - Combined package (tar.xz)
- **[release-archives-${{ fromJson(steps.last-success.outputs.result).commit_sha }}.zip](https://nightly.link/${{ github.repository }}/actions/runs/${{ fromJson(steps.last-success.outputs.result).run_id }}/release-archives-${{ fromJson(steps.last-success.outputs.result).commit_sha }}.zip)** - All release archives
- name: Create or update PR comment (failure with no previous success)
if: steps.run-info.outputs.conclusion != 'success' && steps.last-success.outputs.result == 'null'
uses: peter-evans/create-or-update-comment@v4
with:
comment-id: ${{ steps.find-comment.outputs.comment-id }}
issue-number: ${{ steps.pr.outputs.number }}
edit-mode: replace
body: |
<!-- affinitypluginloader-build-artifacts -->
## ❌ Build Failed
**Commit:** `${{ steps.run-info.outputs.short_sha }}`
**Build timestamp:** ${{ steps.run-info.outputs.timestamp }}
**Failed Workflow:** [View Run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ steps.run-info.outputs.run_id }})
The build failed for this commit. Please check the workflow logs for details.
No previous successful builds found for this PR.