|
| 1 | +name: "Are the types wrong?" |
| 2 | +on: [pull_request] |
| 3 | +permissions: |
| 4 | + pull-requests: write |
| 5 | + |
| 6 | +jobs: |
| 7 | + build: |
| 8 | + name: Are the types wrong? |
| 9 | + runs-on: ubuntu-latest |
| 10 | + steps: |
| 11 | + - name: Setup node |
| 12 | + uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0 |
| 13 | + with: |
| 14 | + node-version: 22 |
| 15 | + |
| 16 | + - name: Checkout PR branch |
| 17 | + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 18 | + |
| 19 | + - name: Install and build |
| 20 | + env: |
| 21 | + PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: 1 |
| 22 | + ELECTRON_DISABLE_SANDBOX: 1 |
| 23 | + run: | |
| 24 | + npm ci |
| 25 | + npm run build |
| 26 | +
|
| 27 | + - name: Run ATTW check |
| 28 | + continue-on-error: true |
| 29 | + env: |
| 30 | + PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: 1 |
| 31 | + ELECTRON_DISABLE_SANDBOX: 1 |
| 32 | + run: | |
| 33 | + npm run test:attw || true |
| 34 | +
|
| 35 | + - name: Parse ATTW results and comment |
| 36 | + uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 |
| 37 | + with: |
| 38 | + script: | |
| 39 | + const fs = require('fs'); |
| 40 | + |
| 41 | + // Read and parse the results file |
| 42 | + let results; |
| 43 | + try { |
| 44 | + const content = fs.readFileSync('attw-results.json', 'utf8'); |
| 45 | + // The file contains multiple JSON objects, one per line |
| 46 | + const lines = content.trim().split('\n').filter(line => line.trim()); |
| 47 | + results = lines.map(line => JSON.parse(line)); |
| 48 | + } catch (error) { |
| 49 | + console.log('Error reading attw-results.json:', error.message); |
| 50 | + return; |
| 51 | + } |
| 52 | + |
| 53 | + // Filter for packages with problems |
| 54 | + const packagesWithProblems = results.filter(result => { |
| 55 | + return result.problems && Object.keys(result.problems).length > 0; |
| 56 | + }); |
| 57 | + |
| 58 | + // Build comment body |
| 59 | + let commentBody = '## 📦 Are The Types Wrong? Report\n\n'; |
| 60 | + |
| 61 | + if (packagesWithProblems.length === 0) { |
| 62 | + commentBody += '✅ All packages passed the type check!\n'; |
| 63 | + } else { |
| 64 | + commentBody += `❌ Found issues in ${packagesWithProblems.length} package(s):\n\n`; |
| 65 | + |
| 66 | + for (const result of packagesWithProblems) { |
| 67 | + const packageName = result.analysis.packageName; |
| 68 | + const problemCount = Object.keys(result.problems).length; |
| 69 | + |
| 70 | + commentBody += `### \`${packageName}\`\n\n`; |
| 71 | + commentBody += `**${problemCount} problem(s) detected:**\n\n`; |
| 72 | + |
| 73 | + // Group problems by kind |
| 74 | + const problemsByKind = {}; |
| 75 | + for (const [entrypoint, issues] of Object.entries(result.problems)) { |
| 76 | + for (const issue of issues) { |
| 77 | + const kind = issue.kind; |
| 78 | + if (!problemsByKind[kind]) { |
| 79 | + problemsByKind[kind] = []; |
| 80 | + } |
| 81 | + problemsByKind[kind].push({ entrypoint, issue }); |
| 82 | + } |
| 83 | + } |
| 84 | + |
| 85 | + // Display problems by kind |
| 86 | + for (const [kind, problems] of Object.entries(problemsByKind)) { |
| 87 | + commentBody += `**${kind}** (${problems.length} occurrence(s)):\n`; |
| 88 | + for (const { entrypoint, issue } of problems.slice(0, 5)) { |
| 89 | + commentBody += `- \`${entrypoint}\`: ${issue.message || 'No message'}\n`; |
| 90 | + } |
| 91 | + if (problems.length > 5) { |
| 92 | + commentBody += `- ... and ${problems.length - 5} more\n`; |
| 93 | + } |
| 94 | + commentBody += '\n'; |
| 95 | + } |
| 96 | + } |
| 97 | + } |
| 98 | + |
| 99 | + commentBody += '\n---\n'; |
| 100 | + commentBody += '*This check helps ensure TypeScript types are correctly exported and work across different module systems.*\n'; |
| 101 | + |
| 102 | + // Post or update comment |
| 103 | + const { data: comments } = await github.rest.issues.listComments({ |
| 104 | + owner: context.repo.owner, |
| 105 | + repo: context.repo.repo, |
| 106 | + issue_number: context.issue.number, |
| 107 | + }); |
| 108 | + |
| 109 | + const botComment = comments.find(comment => |
| 110 | + comment.user.type === 'Bot' && |
| 111 | + comment.body.includes('Are The Types Wrong? Report') |
| 112 | + ); |
| 113 | + |
| 114 | + if (botComment) { |
| 115 | + await github.rest.issues.updateComment({ |
| 116 | + owner: context.repo.owner, |
| 117 | + repo: context.repo.repo, |
| 118 | + comment_id: botComment.id, |
| 119 | + body: commentBody |
| 120 | + }); |
| 121 | + } else { |
| 122 | + await github.rest.issues.createComment({ |
| 123 | + owner: context.repo.owner, |
| 124 | + repo: context.repo.repo, |
| 125 | + issue_number: context.issue.number, |
| 126 | + body: commentBody |
| 127 | + }); |
| 128 | + } |
0 commit comments