|
| 1 | +name: Check toolkit coverage |
| 2 | +# Runs on every PR to main. Never fails — surfaces gaps as GitHub warnings |
| 3 | +# and a PR comment so authors are informed without being blocked. |
| 4 | +# |
| 5 | +# Checks: |
| 6 | +# 1. API toolkits missing a JSON data file in toolkit-docs-generator/data/toolkits/ |
| 7 | +# 2. JSON data files with no matching API toolkit (stale orphans) |
| 8 | +# 3. API toolkits present in JSON but absent from any sidebar _meta.tsx |
| 9 | + |
| 10 | +on: |
| 11 | + workflow_dispatch: |
| 12 | + pull_request: |
| 13 | + types: [opened, synchronize, reopened] |
| 14 | + branches: |
| 15 | + - main |
| 16 | + |
| 17 | +permissions: |
| 18 | + contents: read |
| 19 | + pull-requests: write |
| 20 | + |
| 21 | +jobs: |
| 22 | + coverage: |
| 23 | + name: Toolkit coverage check |
| 24 | + runs-on: ubuntu-latest |
| 25 | + |
| 26 | + steps: |
| 27 | + - name: Checkout repository |
| 28 | + uses: actions/checkout@v4 |
| 29 | + |
| 30 | + - name: Install pnpm |
| 31 | + uses: pnpm/action-setup@v4 |
| 32 | + |
| 33 | + - name: Setup Node.js |
| 34 | + uses: actions/setup-node@v4 |
| 35 | + with: |
| 36 | + node-version: "22" |
| 37 | + cache: pnpm |
| 38 | + |
| 39 | + - name: Install dependencies |
| 40 | + run: pnpm install |
| 41 | + |
| 42 | + - name: Run toolkit coverage check |
| 43 | + id: coverage |
| 44 | + run: | |
| 45 | + pnpm run check:toolkit-coverage 2>&1 | tee coverage-output.txt |
| 46 | + if grep -q "⚠️ Toolkit coverage warnings" coverage-output.txt; then |
| 47 | + echo "has_warnings=true" >> "$GITHUB_OUTPUT" |
| 48 | + else |
| 49 | + echo "has_warnings=false" >> "$GITHUB_OUTPUT" |
| 50 | + fi |
| 51 | + env: |
| 52 | + ENGINE_API_URL: ${{ secrets.ENGINE_API_URL }} |
| 53 | + ENGINE_API_KEY: ${{ secrets.ENGINE_API_KEY }} |
| 54 | + |
| 55 | + - name: Emit GitHub warning annotations |
| 56 | + if: steps.coverage.outputs.has_warnings == 'true' |
| 57 | + run: | |
| 58 | + # Emit one ::warning:: annotation per gap category so GitHub surfaces |
| 59 | + # a yellow warning badge on the check without marking it as failed. |
| 60 | + if grep -q "📁 In API but missing JSON" coverage-output.txt; then |
| 61 | + missing=$(grep -A 100 "📁 In API but missing JSON" coverage-output.txt \ |
| 62 | + | grep "^ [A-Z]" | sed 's/^ //' | paste -sd ', ') |
| 63 | + echo "::warning::Toolkits in API with no JSON data file: ${missing}" |
| 64 | + fi |
| 65 | +
|
| 66 | + if grep -q "🗑️ JSON files with no matching" coverage-output.txt; then |
| 67 | + stale=$(grep -A 100 "🗑️ JSON files with no matching" coverage-output.txt \ |
| 68 | + | grep "^ [a-z]" | sed 's/^ //' | paste -sd ', ') |
| 69 | + echo "::warning::Stale JSON files (no matching API toolkit): ${stale}" |
| 70 | + fi |
| 71 | +
|
| 72 | + if grep -q "🗂️ In API + JSON but missing from sidebar" coverage-output.txt; then |
| 73 | + sidebar=$(grep -A 100 "🗂️ In API + JSON but missing from sidebar" coverage-output.txt \ |
| 74 | + | grep "^ [A-Z]" | sed 's/^ //' | paste -sd ', ') |
| 75 | + echo "::warning::Toolkits missing from sidebar _meta.tsx: ${sidebar}" |
| 76 | + fi |
| 77 | +
|
| 78 | + - name: Write job summary |
| 79 | + if: always() |
| 80 | + run: | |
| 81 | + if [ "$(cat coverage-output.txt | grep -c '⚠️ Toolkit coverage warnings')" -gt 0 ]; then |
| 82 | + echo "## ⚠️ Toolkit coverage — gaps found" >> "$GITHUB_STEP_SUMMARY" |
| 83 | + else |
| 84 | + echo "## ✅ Toolkit coverage — all clear" >> "$GITHUB_STEP_SUMMARY" |
| 85 | + fi |
| 86 | + echo "" >> "$GITHUB_STEP_SUMMARY" |
| 87 | + echo '```' >> "$GITHUB_STEP_SUMMARY" |
| 88 | + cat coverage-output.txt >> "$GITHUB_STEP_SUMMARY" |
| 89 | + echo '```' >> "$GITHUB_STEP_SUMMARY" |
| 90 | +
|
| 91 | + - name: Post or update PR comment |
| 92 | + if: always() |
| 93 | + uses: actions/github-script@v7 |
| 94 | + with: |
| 95 | + script: | |
| 96 | + const fs = require('fs'); |
| 97 | + const output = fs.readFileSync('coverage-output.txt', 'utf8'); |
| 98 | + const hasWarnings = output.includes('⚠️ Toolkit coverage warnings'); |
| 99 | + const marker = '<!-- toolkit-coverage-check -->'; |
| 100 | +
|
| 101 | + const { data: comments } = await github.rest.issues.listComments({ |
| 102 | + owner: context.repo.owner, |
| 103 | + repo: context.repo.repo, |
| 104 | + issue_number: context.issue.number, |
| 105 | + }); |
| 106 | +
|
| 107 | + const existing = comments.find(c => |
| 108 | + c.user.type === 'Bot' && c.body.includes(marker) |
| 109 | + ); |
| 110 | +
|
| 111 | + if (!hasWarnings) { |
| 112 | + if (existing) { |
| 113 | + await github.rest.issues.deleteComment({ |
| 114 | + owner: context.repo.owner, |
| 115 | + repo: context.repo.repo, |
| 116 | + comment_id: existing.id, |
| 117 | + }); |
| 118 | + } |
| 119 | + return; |
| 120 | + } |
| 121 | +
|
| 122 | + const body = `${marker} |
| 123 | +## ⚠️ Toolkit coverage gaps detected |
| 124 | + |
| 125 | +The coverage check found gaps between the Arcade API and the local toolkit data files. These are **warnings only** — this PR is not blocked from merging. |
| 126 | + |
| 127 | +<details> |
| 128 | +<summary>📋 Full report</summary> |
| 129 | + |
| 130 | +\`\`\` |
| 131 | +${output} |
| 132 | +\`\`\` |
| 133 | + |
| 134 | +</details> |
| 135 | + |
| 136 | +### What each warning means |
| 137 | + |
| 138 | +| Warning | Cause | Fix | |
| 139 | +|---|---|---| |
| 140 | +| **In API but missing JSON** | A toolkit is published in the API but has no docs data file | Run the toolkit docs generator for those toolkits | |
| 141 | +| **Stale JSON files** | A JSON data file exists locally but has no matching toolkit in the API | Delete the file or verify the toolkit is still published | |
| 142 | +| **Missing from sidebar** | A toolkit has JSON but isn't listed in any \`_meta.tsx\` | Run \`npx tsx toolkit-docs-generator/scripts/sync-toolkit-sidebar.ts\` | |
| 143 | + |
| 144 | +--- |
| 145 | +*This comment updates automatically when the PR is pushed. It is removed when all gaps are resolved.*`; |
| 146 | + |
| 147 | + if (existing) { |
| 148 | + await github.rest.issues.updateComment({ |
| 149 | + owner: context.repo.owner, |
| 150 | + repo: context.repo.repo, |
| 151 | + comment_id: existing.id, |
| 152 | + body, |
| 153 | + }); |
| 154 | + } else { |
| 155 | + await github.rest.issues.createComment({ |
| 156 | + owner: context.repo.owner, |
| 157 | + repo: context.repo.repo, |
| 158 | + issue_number: context.issue.number, |
| 159 | + body, |
| 160 | + }); |
| 161 | + } |
0 commit comments