|
| 1 | +name: Create PR Comments |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_run: |
| 5 | + workflows: ["Tests"] |
| 6 | + types: [completed] |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: read |
| 10 | + actions: read |
| 11 | + pull-requests: write |
| 12 | + |
| 13 | +jobs: |
| 14 | + pr-comment: |
| 15 | + name: Post Test Result as PR comment |
| 16 | + runs-on: ubuntu-24.04 |
| 17 | + if: github.event.workflow_run.event == 'pull_request' |
| 18 | + |
| 19 | + steps: |
| 20 | + - name: Download CTRF artifact |
| 21 | + uses: dawidd6/action-download-artifact@v8 |
| 22 | + with: |
| 23 | + github_token: ${{ github.token }} |
| 24 | + run_id: ${{ github.event.workflow_run.id }} |
| 25 | + name: ctrf-report |
| 26 | + path: ctrf |
| 27 | + |
| 28 | + - name: Download PR Number Artifact |
| 29 | + uses: dawidd6/action-download-artifact@v8 |
| 30 | + with: |
| 31 | + github_token: ${{ github.token }} |
| 32 | + run_id: ${{ github.event.workflow_run.id }} |
| 33 | + name: pr_number |
| 34 | + path: pr_number |
| 35 | + |
| 36 | + - name: Read PR Number |
| 37 | + run: | |
| 38 | + set -Eeuo pipefail |
| 39 | + FILE='pr_number/pr_number.txt' |
| 40 | +
|
| 41 | + # Ensure file exists |
| 42 | + if [ ! -f "$FILE" ] || [ -L "$FILE" ]; then |
| 43 | + echo "Error: $FILE is missing or is not a regular file." >&2 |
| 44 | + exit 1 |
| 45 | + fi |
| 46 | +
|
| 47 | + # Chec file size |
| 48 | + if [ "$(wc -c < "$FILE" | tr -d ' ')" -gt 200 ]; then |
| 49 | + echo "Error: $FILE is too large." >&2 |
| 50 | + exit 1 |
| 51 | + fi |
| 52 | +
|
| 53 | + # Read first line |
| 54 | + PR_NUMBER="" |
| 55 | + IFS= read -r PR_NUMBER < "$FILE" || true |
| 56 | +
|
| 57 | + # Validate whether it's a number |
| 58 | + if ! [[ "$PR_NUMBER" =~ ^[0-9]{1,10}$ ]]; then |
| 59 | + echo "Error: PR_NUMBER is not a valid integer on the first line." >&2 |
| 60 | + exit 1 |
| 61 | + fi |
| 62 | +
|
| 63 | + printf 'PR_NUMBER=%s\n' "$PR_NUMBER" >> "$GITHUB_ENV" |
| 64 | +
|
| 65 | + - name: Post PR Comment |
| 66 | + uses: ctrf-io/github-test-reporter@v1 |
| 67 | + with: |
| 68 | + report-path: 'ctrf/**/*.json' |
| 69 | + issue: ${{ env.PR_NUMBER }} |
| 70 | + |
| 71 | + summary: true |
| 72 | + pull-request: true |
| 73 | + use-suite-name: true |
| 74 | + update-comment: true |
| 75 | + always-group-by: true |
| 76 | + overwrite-comment: true |
| 77 | + upload-artifact: false |
| 78 | + |
| 79 | + pull-request-report: true |
| 80 | + env: |
| 81 | + GITHUB_TOKEN: ${{ github.token }} |
0 commit comments