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