Post data validation comment #319
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 data validation comment | |
| on: | |
| workflow_run: | |
| workflows: ["Verify station data integrity"] | |
| types: [completed] | |
| permissions: | |
| actions: read | |
| pull-requests: write | |
| issues: write | |
| jobs: | |
| comment: | |
| name: Post validation result comment | |
| runs-on: ubuntu-latest | |
| if: github.event.workflow_run.event == 'pull_request' | |
| steps: | |
| - name: Download artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: validation-result | |
| path: /tmp/validation-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/validation-artifacts/pr_number ]; then | |
| PR_NUMBER=$(cat /tmp/validation-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/validation-artifacts/result ]; then | |
| echo "result=$(cat /tmp/validation-artifacts/result)" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "::error::Missing or empty result metadata" | |
| exit 1 | |
| 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: "<!-- data-validator -->" | |
| - name: Post or update validation failure comment | |
| if: steps.meta.outputs.result == 'failure' | |
| 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/validation-artifacts/validation_report.md | |
| edit-mode: replace | |
| - name: Delete comment if validation passed | |
| if: steps.meta.outputs.result == 'success' && 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 }} |