-
Notifications
You must be signed in to change notification settings - Fork 3
184 lines (150 loc) · 6.48 KB
/
Copy pathsdk-coverage.yml
File metadata and controls
184 lines (150 loc) · 6.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
name: SDK Smoke Tests & Coverage Check
on:
pull_request:
paths:
- 'src/sdk/**'
- 'tests/smoketests/object-oriented/**'
workflow_dispatch:
inputs:
environment:
description: 'Target environment'
type: choice
default: dev
options:
- dev
- prod
jobs:
smoke-and-coverage:
runs-on: ubuntu-latest
timeout-minutes: 120
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'yarn'
- name: Install dependencies
run: yarn --frozen-lockfile
- name: Build
run: yarn build
- name: Configure environment
env:
DEV_KEY: ${{ secrets.RUNLOOP_SMOKETEST_DEV_API_KEY }}
PROD_KEY: ${{ secrets.RUNLOOP_SMOKETEST_PROD_API_KEY }}
run: |
if [ "${{ github.event.inputs.environment }}" = "prod" ]; then
echo "RUNLOOP_API_KEY=${PROD_KEY}" >> $GITHUB_ENV
echo "RUNLOOP_BASE_URL=https://api.runloop.ai" >> $GITHUB_ENV
else
echo "RUNLOOP_API_KEY=${DEV_KEY}" >> $GITHUB_ENV
echo "RUNLOOP_BASE_URL=https://api.runloop.pro" >> $GITHUB_ENV
fi
echo "DEBUG=false" >> $GITHUB_ENV
echo "RUN_SMOKETESTS=1" >> $GITHUB_ENV
- name: Run smoke tests with coverage
id: tests
continue-on-error: true
run: yarn test:objects-coverage 2>&1 | tee test-output.log
- name: Upload coverage report
uses: actions/upload-artifact@v4
if: always()
with:
name: coverage-report
path: coverage-objects/
retention-days: 30
- name: Comment results on PR
if: always() && github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const testsPassed = '${{ steps.tests.outcome }}' === 'success';
// Build workflow run URL
const runUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`;
let comment = '';
if (!testsPassed) {
// Try to parse failed tests from the log
let failedTests = '';
try {
const testOutput = fs.readFileSync('test-output.log', 'utf8');
// Extract failed test names using regex
const failedMatches = testOutput.match(/● (.+?)(?:\n|$)/g);
if (failedMatches && failedMatches.length > 0) {
const failedTestList = failedMatches
.map(match => match.replace('● ', '').trim())
.filter(test => test.length > 0)
.slice(0, 10) // Limit to first 10 failures
.map(test => `- ${test}`)
.join('\n');
if (failedTestList) {
failedTests = `\n\n**Failed Tests:**\n${failedTestList}`;
if (failedMatches.length > 10) {
failedTests += `\n- ... and ${failedMatches.length - 10} more`;
}
}
}
} catch (error) {
console.log('Could not read test output:', error.message);
}
comment = `## ❌ Object Smoke Tests Failed
### Test Results
❌ Some smoke tests failed
${failedTests}
**Please fix the failing tests before checking coverage.**
[📋 View full test logs](${runUrl})`;
} else {
let coverageSummary = null;
try {
coverageSummary = JSON.parse(fs.readFileSync('coverage-objects/coverage-summary.json', 'utf8'));
} catch (error) {
console.log('Coverage summary not found:', error.message);
comment = `## ⚠️ Coverage Data Missing
### Test Results
✅ All smoke tests passed
### Coverage Results
⚠️ Coverage data could not be read
[📋 View workflow logs](${runUrl})`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: comment
});
return;
}
const total = coverageSummary.total;
const functions = total.functions.pct;
const lines = total.lines.pct;
const branches = total.branches.pct;
const statements = total.statements.pct;
const coveragePassed = functions === 100;
const allPassed = testsPassed && coveragePassed;
const statusEmoji = allPassed ? '✅' : '⚠️';
comment = `## ${statusEmoji} Object Smoke Tests & Coverage Report
### Test Results
✅ All smoke tests passed
### Coverage Results
| Metric | Coverage | Required | Status |
|--------|----------|----------|--------|
| **Functions** | **${functions}%** | **100%** | ${coveragePassed ? '✅' : '❌'} |
| Lines | ${lines}% | - | ℹ️ |
| Branches | ${branches}% | - | ℹ️ |
| Statements | ${statements}% | - | ℹ️ |
**Coverage Requirement:** 100% function coverage (all public methods must be called in smoke tests)
${coveragePassed
? '✅ All tests passed and all object methods are covered!'
: '⚠️ Some object methods are not covered in smoke tests. Please add tests that call all public methods.'}
<details>
<summary>View detailed coverage report</summary>
Coverage reports are available in the workflow artifacts. Lines/branches/statements coverage is tracked but not required to be 100%.
</details>
[📋 View workflow run](${runUrl})`;
}
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: comment
});