Build Order Analysis Comment #52
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: Build Order Analysis Comment | |
| on: | |
| workflow_run: | |
| workflows: [Build Order Analysis] | |
| types: | |
| - completed | |
| permissions: | |
| contents: read | |
| pull-requests: write | |
| actions: read | |
| jobs: | |
| comment: | |
| name: Post Build Order Analysis Results | |
| runs-on: ubuntu-latest | |
| if: github.event.workflow_run.conclusion != 'skipped' | |
| steps: | |
| - name: Download artifacts | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| mkdir -p artifacts && cd artifacts | |
| artifacts_url="${{ github.event.workflow_run.artifacts_url }}" | |
| gh api --paginate "$artifacts_url" -q '.artifacts[] | [.name, .archive_download_url] | @tsv' | while read artifact | |
| do | |
| IFS=$'\t' read name url <<< "$artifact" | |
| if [ "$name" != "build-order-analysis" ]; then | |
| continue | |
| fi | |
| gh api $url > "$name.zip" | |
| unzip -d "$name" "$name.zip" | |
| done | |
| ls -alR | |
| - name: Check for artifacts | |
| id: artifact_check | |
| run: | | |
| if [ -e artifacts/build-order-analysis/event.json ] && [ -e artifacts/build-order-analysis/comment.md ]; then | |
| echo "artifacts_found=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "artifacts_found=false" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Post comment to PR | |
| if: steps.artifact_check.outputs.artifacts_found == 'true' | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const fs = require('fs'); | |
| // Read the PR event and comment content | |
| const event = JSON.parse(fs.readFileSync('artifacts/build-order-analysis/event.json', 'utf8')); | |
| const commentBody = fs.readFileSync('artifacts/build-order-analysis/comment.md', 'utf8'); | |
| // Check if this originated from a pull request | |
| if (!event.pull_request) { | |
| console.log('Not a pull request event, skipping comment'); | |
| return; | |
| } | |
| const { owner, repo } = context.repo; | |
| const prNumber = event.pull_request.number; | |
| console.log(`Posting comment to PR #${prNumber}`); | |
| // Look for existing build order analysis comment | |
| const comments = await github.rest.issues.listComments({ | |
| owner, | |
| repo, | |
| issue_number: prNumber, | |
| }); | |
| const existingComment = comments.data.find(comment => | |
| comment.body.includes('## 📊 Build Order Analysis Results') && | |
| comment.user.type === 'Bot' | |
| ); | |
| if (existingComment) { | |
| // Update existing comment | |
| await github.rest.issues.updateComment({ | |
| owner, | |
| repo, | |
| comment_id: existingComment.id, | |
| body: commentBody | |
| }); | |
| console.log(`Updated existing comment ${existingComment.id}`); | |
| } else { | |
| // Create new comment | |
| await github.rest.issues.createComment({ | |
| owner, | |
| repo, | |
| issue_number: prNumber, | |
| body: commentBody | |
| }); | |
| console.log('Created new comment'); | |
| } |