|
1 | 1 | name: Post Coverage Comment |
2 | 2 |
|
| 3 | +# This workflow handles posting coverage comments for FORKED PRs. |
| 4 | +# |
| 5 | +# Why a separate workflow? |
| 6 | +# - Forked PRs have restricted GITHUB_TOKEN permissions for security |
| 7 | +# - They cannot write comments directly to the base repository's PRs |
| 8 | +# - workflow_run triggers run in the BASE repository context with full permissions |
| 9 | +# - This allows us to safely post comments on forked PRs |
| 10 | +# |
| 11 | +# How it works: |
| 12 | +# 1. PR Code Coverage workflow uploads coverage data as an artifact (forked PRs only) |
| 13 | +# 2. This workflow triggers when PR Code Coverage completes successfully |
| 14 | +# 3. Downloads the artifact and posts the comment with full write permissions |
| 15 | +# |
| 16 | +# Same-repo PRs post comments directly in pr-code-coverage.yml (faster) |
| 17 | +# Forked PRs use this workflow (required for permissions) |
| 18 | + |
3 | 19 | on: |
4 | 20 | workflow_run: |
5 | 21 | workflows: ["PR Code Coverage"] |
|
21 | 37 | env: |
22 | 38 | GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
23 | 39 | run: | |
24 | | - gh run download ${{ github.event.workflow_run.id }} \ |
| 40 | + # Download artifact with error handling for non-existent artifacts |
| 41 | + if ! gh run download ${{ github.event.workflow_run.id }} \ |
25 | 42 | --repo ${{ github.repository }} \ |
26 | | - --name coverage-comment-data |
| 43 | + --name coverage-comment-data 2>&1; then |
| 44 | + echo "⚠️ No coverage-comment-data artifact found" |
| 45 | + echo "This is expected for same-repo PRs (they post comments directly)" |
| 46 | + echo "Exiting gracefully..." |
| 47 | + exit 0 |
| 48 | + fi |
| 49 | + |
| 50 | + # Verify artifact was downloaded |
| 51 | + if [[ ! -f pr-info.json ]]; then |
| 52 | + echo "⚠️ Artifact downloaded but pr-info.json not found" |
| 53 | + echo "This may indicate an issue with artifact upload" |
| 54 | + exit 1 |
| 55 | + fi |
27 | 56 |
|
28 | 57 | - name: Read coverage data |
29 | 58 | id: coverage |
|
0 commit comments