VUP Bot #284
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: VUP Bot | |
| on: | |
| workflow_run: | |
| workflows: ["PR Build"] | |
| types: | |
| - completed | |
| permissions: | |
| pull-requests: write | |
| contents: read | |
| actions: read | |
| jobs: | |
| report-status: | |
| runs-on: ubuntu-latest | |
| if: ${{ contains(fromJson('["pull_request", "pull_request_target"]'), github.event.workflow_run.event) && github.event.workflow_run.conclusion != 'skipped' }} | |
| steps: | |
| - name: Generate App Token | |
| id: app-token | |
| uses: actions/create-github-app-token@v1 | |
| with: | |
| app-id: ${{ secrets.VUP_BOT_APP_ID }} | |
| private-key: ${{ secrets.VUP_BOT_PRIVATE_KEY }} | |
| - name: Checkout VUP (for scripts) | |
| uses: actions/checkout@v6 | |
| - name: Download Build Reports | |
| uses: actions/download-artifact@v8 | |
| with: | |
| pattern: pr-report-* | |
| merge-multiple: true | |
| path: reports | |
| run-id: ${{ github.event.workflow_run.id }} | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Download PR Metadata | |
| uses: actions/download-artifact@v8 | |
| with: | |
| name: pr-meta | |
| path: pr-meta | |
| run-id: ${{ github.event.workflow_run.id }} | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Resolve PR Number | |
| id: pr | |
| run: | | |
| if [ -f pr-meta/pr_number.txt ]; then | |
| num=$(cat pr-meta/pr_number.txt | tr -d '[:space:]') | |
| fi | |
| if [ -z "$num" ]; then | |
| echo "No PR number found in artifact." >&2 | |
| exit 1 | |
| fi | |
| echo "number=$num" >> "$GITHUB_OUTPUT" | |
| - name: Analyze Results | |
| id: analyze | |
| run: | | |
| RUN_URL="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.event.workflow_run.id }}" | |
| python3 vup/scripts/analyze_pr_report.py \ | |
| --reports-dir reports \ | |
| --run-url "$RUN_URL" \ | |
| --output comment.md | |
| - name: Comment on PR | |
| uses: actions/github-script@v9 | |
| with: | |
| github-token: ${{ steps.app-token.outputs.token }} | |
| script: | | |
| const fs = require('fs'); | |
| const commentBody = fs.readFileSync('comment.md', 'utf8'); | |
| const prNumber = parseInt('${{ steps.pr.outputs.number }}', 10); | |
| await github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: prNumber, | |
| body: commentBody | |
| }); | |
| - name: Manage Labels | |
| uses: actions/github-script@v9 | |
| with: | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| script: | | |
| const prNumber = parseInt('${{ steps.pr.outputs.number }}', 10); | |
| const buildResult = '${{ steps.analyze.outputs.result }}'; | |
| if (buildResult === 'success') { | |
| try { | |
| await github.rest.issues.addLabels({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: prNumber, | |
| labels: ['build-passed'] | |
| }); | |
| } catch (e) { | |
| core.warning(`Could not add build-passed label: ${e}`); | |
| } | |
| } | |
| try { | |
| await github.rest.issues.removeLabel({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: prNumber, | |
| name: 'ok-to-build' | |
| }); | |
| } catch (e) { | |
| core.info('ok-to-build label not present (already removed or never added)'); | |
| } |