Post build report comment #58
This file contains hidden or 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: Post build report comment | |
| # Runs from the default branch with a write token, so the build artifact link | |
| # and size report generated by pull requests from forks can still be posted. | |
| # This workflow must never check out or execute the pull request's code. | |
| on: | |
| workflow_run: | |
| workflows: ["Build BlueSCSI firmware"] | |
| types: [completed] | |
| permissions: | |
| actions: read | |
| pull-requests: write | |
| jobs: | |
| size_comment: | |
| name: Post build comment on PR | |
| runs-on: ubuntu-latest | |
| if: github.event.workflow_run.event == 'pull_request' | |
| steps: | |
| - name: Download size report | |
| id: download | |
| uses: actions/download-artifact@v8 | |
| continue-on-error: true | |
| with: | |
| name: size-report | |
| run-id: ${{ github.event.workflow_run.id }} | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| # workflow_run.pull_requests is empty for forks, so resolve the number | |
| # from the head SHA rather than trusting anything in the artifact. | |
| - name: Resolve PR number | |
| id: pr | |
| if: steps.download.outcome == 'success' | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| HEAD_SHA: ${{ github.event.workflow_run.head_sha }} | |
| run: | | |
| number=$(gh api "repos/${GITHUB_REPOSITORY}/commits/${HEAD_SHA}/pulls" --jq '.[0].number // empty') | |
| echo "number=${number}" >> "$GITHUB_OUTPUT" | |
| # The firmware zip / UF2s built for this PR. | |
| - name: Build comment body | |
| if: steps.pr.outputs.number != '' | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| RUN_ID: ${{ github.event.workflow_run.id }} | |
| HEAD_SHA: ${{ github.event.workflow_run.head_sha }} | |
| run: | | |
| # Never let a failed lookup take the size report down with it. | |
| artifact_id=$(gh api "repos/${GITHUB_REPOSITORY}/actions/runs/${RUN_ID}/artifacts" \ | |
| --jq '[.artifacts[] | select(.name == "BlueSCSI binaries" and .expired == false)][0].id // empty' || true) | |
| { | |
| if [ -n "$artifact_id" ]; then | |
| url="https://github.com/${GITHUB_REPOSITORY}/actions/runs/${RUN_ID}/artifacts/${artifact_id}" | |
| echo "### Test this PR" | |
| echo | |
| echo "Flash the firmware built from \`${HEAD_SHA:0:7}\`: [**BlueSCSI binaries.zip**](${url})" | |
| echo "- see [Updating Firmware](https://github.com/BlueSCSI/BlueSCSI-v2/wiki/Updating-Firmware) for how to flash it." | |
| echo | |
| echo "<sub>Must be signed in to GitHub. Build expires after 90 days.</sub>" | |
| echo | |
| fi | |
| cat size-report.md | |
| } > pr-comment.md | |
| - name: Post build comment on PR | |
| if: steps.pr.outputs.number != '' | |
| uses: marocchino/sticky-pull-request-comment@v3 | |
| with: | |
| header: bluescsi-size-report | |
| number: ${{ steps.pr.outputs.number }} | |
| path: pr-comment.md | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |