Post stopping pattern visualization comment #20
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 stopping pattern visualization comment | |
| on: | |
| workflow_run: | |
| workflows: ["Visualize Stopping Patterns"] | |
| types: [completed] | |
| permissions: | |
| actions: read | |
| pull-requests: write | |
| issues: write | |
| jobs: | |
| comment: | |
| name: Post visualization comment | |
| runs-on: ubuntu-latest | |
| if: >- | |
| github.event.workflow_run.conclusion == 'success' && | |
| github.event.workflow_run.event == 'pull_request' | |
| steps: | |
| - name: Download artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: visualization-result | |
| path: /tmp/visualize-artifacts | |
| run-id: ${{ github.event.workflow_run.id }} | |
| github-token: ${{ github.token }} | |
| - name: Read metadata | |
| id: meta | |
| run: | | |
| PR_NUMBER="${{ github.event.workflow_run.pull_requests[0].number }}" | |
| if [ -z "$PR_NUMBER" ] && [ -s /tmp/visualize-artifacts/pr_number ]; then | |
| PR_NUMBER=$(cat /tmp/visualize-artifacts/pr_number) | |
| echo "::warning::pull_requests context empty, using artifact fallback" | |
| fi | |
| if [ -z "$PR_NUMBER" ]; then | |
| echo "::error::Could not determine PR number" | |
| exit 1 | |
| fi | |
| echo "pr_number=$PR_NUMBER" >> "$GITHUB_OUTPUT" | |
| if [ -s /tmp/visualize-artifacts/has_changes ]; then | |
| echo "has_changes=$(cat /tmp/visualize-artifacts/has_changes)" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "::warning::has_changes metadata missing or empty, defaulting to false" | |
| echo "has_changes=false" >> "$GITHUB_OUTPUT" | |
| fi | |
| - name: Find existing comment | |
| uses: peter-evans/find-comment@v3 | |
| id: find_comment | |
| with: | |
| issue-number: ${{ steps.meta.outputs.pr_number }} | |
| comment-author: "github-actions[bot]" | |
| body-includes: "<!-- station-visualizer -->" | |
| - name: Post or update comment | |
| if: steps.meta.outputs.has_changes == 'true' | |
| uses: peter-evans/create-or-update-comment@v4 | |
| with: | |
| issue-number: ${{ steps.meta.outputs.pr_number }} | |
| comment-id: ${{ steps.find_comment.outputs.comment-id }} | |
| body-path: /tmp/visualize-artifacts/visualization_comment.md | |
| edit-mode: replace | |
| - name: Delete comment if no changes | |
| if: steps.meta.outputs.has_changes == 'false' && steps.find_comment.outputs.comment-id != '' | |
| run: gh api repos/${{ github.repository }}/issues/comments/${{ steps.find_comment.outputs.comment-id }} -X DELETE | |
| env: | |
| GH_TOKEN: ${{ github.token }} |