|
| 1 | +name: PR Checks - Post Coverage |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_run: |
| 5 | + workflows: ["PR Pre Checks"] |
| 6 | + types: |
| 7 | + - completed |
| 8 | + workflow_dispatch: |
| 9 | + inputs: |
| 10 | + run_id: |
| 11 | + description: "Workflow run ID to fetch artifacts from" |
| 12 | + required: True |
| 13 | + type: string |
| 14 | + |
| 15 | +permissions: |
| 16 | + actions: read |
| 17 | + contents: read |
| 18 | + pull-requests: write |
| 19 | + |
| 20 | +jobs: |
| 21 | + post-coverage: |
| 22 | + runs-on: ubuntu-latest |
| 23 | + if: > |
| 24 | + github.event_name == 'workflow_dispatch' || |
| 25 | + (github.event.workflow_run.event == 'pull_request' && |
| 26 | + github.event.workflow_run.conclusion == 'success') |
| 27 | +
|
| 28 | + steps: |
| 29 | + - name: Download coverage artifact |
| 30 | + uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 |
| 31 | + with: |
| 32 | + name: coverage-report |
| 33 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 34 | + run-id: ${{ github.event_name == 'workflow_dispatch' && inputs.run_id || github.event.workflow_run.id }} |
| 35 | + |
| 36 | + - name: Download PR metadata |
| 37 | + uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 |
| 38 | + with: |
| 39 | + name: pr-metadata |
| 40 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 41 | + run-id: ${{ github.event_name == 'workflow_dispatch' && inputs.run_id || github.event.workflow_run.id }} |
| 42 | + |
| 43 | + - name: Verify artifact integrity |
| 44 | + run: | |
| 45 | + if [ ! -f pr_metadata/checksums.txt ]; then |
| 46 | + echo "Warning: No checksums file found. Skipping integrity check." |
| 47 | + else |
| 48 | + cd pr_metadata |
| 49 | + if sha256sum -c checksums.txt --quiet; then |
| 50 | + echo "Artifact integrity verified." |
| 51 | + else |
| 52 | + echo "Error: Artifact integrity check failed." |
| 53 | + exit 1 |
| 54 | + fi |
| 55 | + fi |
| 56 | +
|
| 57 | + - name: Read and Validate PR number |
| 58 | + id: pr_number |
| 59 | + env: |
| 60 | + PR_NUMBER: ${{ github.event.workflow_run.pull_requests[0].number }} |
| 61 | + run: | |
| 62 | + if [ -z "$PR_NUMBER" ] || ! [[ "$PR_NUMBER" =~ ^[0-9]+$ ]]; then |
| 63 | + echo "Error: Could not determine PR number from workflow_run payload: $PR_NUMBER" |
| 64 | + exit 1 |
| 65 | + fi |
| 66 | + echo "PR_NUMBER=$PR_NUMBER" >> "$GITHUB_OUTPUT" |
| 67 | + - name: Validate coverage report |
| 68 | + run: | |
| 69 | + if [ ! -f coverage.md ]; then |
| 70 | + echo "Error: coverage.md file not found." |
| 71 | + exit 1 |
| 72 | + fi |
| 73 | + FILE_SIZE=$(stat -c%s coverage.md) |
| 74 | + if [ "$FILE_SIZE" -gt 65536 ]; then |
| 75 | + echo "Error: coverage.md file size exceeds 64KB." |
| 76 | + exit 1 |
| 77 | + fi |
| 78 | +
|
| 79 | + - name: Update PR body with coverage |
| 80 | + env: |
| 81 | + GH_TOKEN: ${{ github.token }} |
| 82 | + PR_NUMBER: ${{ steps.pr_number.outputs.PR_NUMBER }} |
| 83 | + REPOSITORY: ${{ github.repository }} |
| 84 | + run: | |
| 85 | + # Fetch the current PR body |
| 86 | + CURRENT_BODY=$(gh pr view "$PR_NUMBER" --repo "$REPOSITORY" --json body --jq '.body') |
| 87 | +
|
| 88 | + # Strip previous coverage section if it exists |
| 89 | + CLEAN_BODY=$(printf '%s\n' "$CURRENT_BODY" | sed '/<!-- coverage-report -->/,$d') |
| 90 | +
|
| 91 | + # Build New PR body with coverage appended at the bottom |
| 92 | + { |
| 93 | + echo "$CLEAN_BODY" |
| 94 | + echo "<!-- coverage-report -->" |
| 95 | + echo "## Coverage Report" |
| 96 | + echo "" |
| 97 | + cat coverage.md |
| 98 | + } > new_body.md |
| 99 | +
|
| 100 | + gh pr edit "$PR_NUMBER" --repo "$REPOSITORY" --body-file new_body.md |
0 commit comments