|
62 | 62 | fail_ci_if_error: false |
63 | 63 | verbose: true |
64 | 64 |
|
65 | | - - name: Coverage Report Comment |
66 | | - uses: actions/github-script@v7 |
67 | | - if: github.event_name == 'pull_request' |
68 | | - with: |
69 | | - script: | |
70 | | - const fs = require('fs'); |
71 | | - |
72 | | - // Read Go coverage |
73 | | - let goCoverageText = 'Not available'; |
74 | | - try { |
75 | | - const coverageOutput = await exec.exec('go', ['tool', 'cover', '-func=coverage.out'], { |
76 | | - silent: true, |
77 | | - listeners: { |
78 | | - stdout: (data) => { goCoverageText = data.toString(); } |
79 | | - } |
80 | | - }); |
81 | | - } catch (e) { |
82 | | - console.log('Go coverage parsing failed:', e); |
83 | | - } |
84 | | - |
85 | | - // Extract Go coverage percentage |
86 | | - const goMatch = goCoverageText.match(/total:\s+\(statements\)\s+([\d.]+)%/); |
87 | | - const goCoverage = goMatch ? goMatch[1] + '%' : 'Parse failed'; |
88 | | - |
89 | | - // Read Frontend coverage |
90 | | - let frontendCoverage = 'Not available'; |
91 | | - try { |
92 | | - if (fs.existsSync('./frontend/coverage/coverage-summary.json')) { |
93 | | - const summary = JSON.parse(fs.readFileSync('./frontend/coverage/coverage-summary.json', 'utf8')); |
94 | | - frontendCoverage = summary.total.statements.pct + '%'; |
95 | | - } |
96 | | - } catch (e) { |
97 | | - console.log('Frontend coverage parsing failed:', e); |
98 | | - } |
99 | | - |
100 | | - const comment = `## 📊 Test Coverage Report |
101 | | - |
102 | | - | Component | Coverage | |
103 | | - |-----------|----------| |
104 | | - | 🔧 Go Backend | ${goCoverage} | |
105 | | - | ⚛️ Frontend | ${frontendCoverage} | |
106 | | - |
107 | | - Coverage reports are also uploaded to [Codecov](https://codecov.io/gh/daniel-sullivan/babel-bridge/pull/${context.issue.number}) for detailed analysis. |
108 | | - |
109 | | - --- |
110 | | - *Coverage generated by GitHub Actions*`; |
111 | | - |
112 | | - // Find and update existing comment or create new one |
113 | | - const comments = await github.rest.issues.listComments({ |
114 | | - owner: context.repo.owner, |
115 | | - repo: context.repo.repo, |
116 | | - issue_number: context.issue.number, |
117 | | - }); |
118 | | - |
119 | | - const existingComment = comments.data.find(c => c.body.includes('📊 Test Coverage Report')); |
120 | | - |
121 | | - if (existingComment) { |
122 | | - await github.rest.issues.updateComment({ |
123 | | - owner: context.repo.owner, |
124 | | - repo: context.repo.repo, |
125 | | - comment_id: existingComment.id, |
126 | | - body: comment |
127 | | - }); |
128 | | - } else { |
129 | | - await github.rest.issues.createComment({ |
130 | | - owner: context.repo.owner, |
131 | | - repo: context.repo.repo, |
132 | | - issue_number: context.issue.number, |
133 | | - body: comment |
134 | | - }); |
135 | | - } |
136 | 65 |
|
0 commit comments