|
| 1 | +name: Diagnosis report |
| 2 | + |
| 3 | +# A diagnosis run in the playground files a pre-filled issue (labeled |
| 4 | +# `diagnosis-report`) carrying the markdown report in its body. This workflow |
| 5 | +# turns that issue into a PR that adds/updates the host's report under |
| 6 | +# explorer/diagnosis-reports/. The compatibility matrix is a build artifact |
| 7 | +# regenerated from those reports, so the PR only touches the report file. |
| 8 | + |
| 9 | +on: |
| 10 | + issues: |
| 11 | + types: [labeled] |
| 12 | + |
| 13 | +# Serialize so concurrent submissions never race on a branch push. |
| 14 | +concurrency: |
| 15 | + group: diagnosis-report |
| 16 | + cancel-in-progress: false |
| 17 | + |
| 18 | +permissions: |
| 19 | + contents: write |
| 20 | + pull-requests: write |
| 21 | + issues: write |
| 22 | + |
| 23 | +jobs: |
| 24 | + ingest: |
| 25 | + if: github.event.label.name == 'diagnosis-report' |
| 26 | + runs-on: ubuntu-latest |
| 27 | + steps: |
| 28 | + - uses: actions/checkout@v4 |
| 29 | + |
| 30 | + - name: Build the report PR |
| 31 | + env: |
| 32 | + GH_TOKEN: ${{ github.token }} |
| 33 | + BODY: ${{ github.event.issue.body }} |
| 34 | + ISSUE: ${{ github.event.issue.number }} |
| 35 | + run: | |
| 36 | + set -euo pipefail |
| 37 | +
|
| 38 | + # Host mode from the report title (`## Truapi <mode> Diagnosis`). |
| 39 | + mode=$(printf '%s' "$BODY" \ |
| 40 | + | grep -ioP '##\s+Truapi\s+\K(Web|Desktop|Android|iOS)(?=\s+Diagnosis)' \ |
| 41 | + | head -1 || true) |
| 42 | + if [ -z "$mode" ]; then |
| 43 | + gh issue comment "$ISSUE" --body \ |
| 44 | + "Could not read a host from this report (expected a \`## Truapi <Web|Desktop|Android|iOS> Diagnosis\` heading). Not filing a PR." |
| 45 | + exit 1 |
| 46 | + fi |
| 47 | + host=$(printf '%s' "$mode" | tr '[:upper:]' '[:lower:]') |
| 48 | + branch="diagnosis-report/$host" |
| 49 | + file="explorer/diagnosis-reports/$host.md" |
| 50 | +
|
| 51 | + git fetch origin main |
| 52 | + git switch -C "$branch" origin/main |
| 53 | + printf '%s\n' "$BODY" > "$file" |
| 54 | +
|
| 55 | + git config user.name "github-actions[bot]" |
| 56 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 57 | + if git diff --quiet -- "$file"; then |
| 58 | + gh issue comment "$ISSUE" --body \ |
| 59 | + "This $mode report matches the current \`$file\`; nothing to update." |
| 60 | + gh issue close "$ISSUE" |
| 61 | + exit 0 |
| 62 | + fi |
| 63 | + git add "$file" |
| 64 | + git commit -m "diagnosis: update $host report (from #$ISSUE)" |
| 65 | + git push -f origin "$branch" |
| 66 | +
|
| 67 | + # One open PR per host branch: reuse it while it is open, open a new |
| 68 | + # one once the previous report has merged (a merged/closed PR for the |
| 69 | + # branch must not suppress the next submission). |
| 70 | + url=$(gh pr list --head "$branch" --state open --json url --jq '.[0].url // empty') |
| 71 | + if [ -z "$url" ]; then |
| 72 | + url=$(gh pr create --base main --head "$branch" \ |
| 73 | + --title "diagnosis: $mode host report" \ |
| 74 | + --body "Updates \`$file\` from the diagnosis in #$ISSUE. The compatibility matrix is regenerated from the reports at build time.") |
| 75 | + fi |
| 76 | +
|
| 77 | + gh issue comment "$ISSUE" --body "Filed in $url" |
| 78 | + gh issue close "$ISSUE" |
0 commit comments