/
vshmidt
/
streamlit
Обзор
Документация
Войти
/
vshmidt
/
streamlit
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
.github/workflows/js-tests.yml
260 строк
9 KB
Lukas Masuch
Increase coverage change threshold to 0.05% (#13821)
04 фев 2026, 19:02
Не верифицирован
04 фев 2026, 19:02
86edbeb
Код
Авторство
О чём код?
name: Javascript Unit Tests on: push: branches: - "develop" pull_request: types: [opened, synchronize, reopened] # Allows workflow to be called from other workflows workflow_call: inputs: ref: required: true type: string # Avoid duplicate workflows on same branch concurrency: group: ${{ github.workflow }}-${{ github.ref }}-javascript cancel-in-progress: true jobs: js-unit-tests: runs-on: ubuntu-latest defaults: run: shell: bash steps: - name: Checkout Streamlit code uses: actions/checkout@v6 with: ref: ${{ inputs.ref }} persist-credentials: false submodules: "recursive" fetch-depth: 2 - name: Set Python version vars uses: ./.github/actions/build_info - name: Setup virtual env uses: ./.github/actions/make_init with: python_version: ${{ env.PYTHON_MAX_VERSION }} - name: Ensure frontend yarn.lock is deduped run: ./scripts/check_yarn_dedupe.sh frontend - name: Build @streamlit/lib run: cd frontend/ ; yarn workspaces foreach --recursive --topological --from @streamlit/lib run build; - name: Audit frontend licenses run: ./scripts/audit_frontend_licenses.py - name: Run frontend-typesync run: make frontend-typesync - name: Run type checks run: make frontend-types - name: Run linters run: make frontend-lint - name: Validate NOTICES run: | # Run `make update-notices`. If it results in changes, warn the user and fail. make update-notices git_status=$(git status --porcelain -- NOTICES) if [[ -n $git_status ]]; then echo "::error::The NOTICES file is out of date! Please run \`make update-notices\` and commit the result." echo "::group::git diff NOTICES" git diff NOTICES echo "::endgroup::" exit 1 else echo "NOTICES is up to date." fi - name: Run frontend tests run: make frontend-tests - name: Upload coverage json-summary uses: actions/upload-artifact@v6 with: name: vitest_coverage_json path: frontend/coverage/coverage-summary.json - name: Upload coverage HTML report uses: actions/upload-artifact@v6 with: name: vitest_coverage_html path: frontend/coverage retention-days: 30 components-lib-tests: runs-on: ubuntu-latest defaults: run: shell: bash steps: - name: Checkout Streamlit code uses: actions/checkout@v6 with: ref: ${{ inputs.ref }} persist-credentials: false submodules: "recursive" fetch-depth: 2 - name: Enable Corepack run: corepack enable - name: Setup Node uses: actions/setup-node@v6 with: node-version-file: ".nvmrc" cache: "yarn" cache-dependency-path: "component-lib/yarn.lock" - name: Install node dependencies working-directory: component-lib run: yarn install - name: Run frontend tests working-directory: component-lib run: yarn test - name: Build package working-directory: component-lib run: yarn build js-coverage-comment: needs: - js-unit-tests runs-on: ubuntu-latest permissions: # Required for downloading artifacts actions: read # Required for creating/updating PR comments pull-requests: write if: github.event_name == 'pull_request' steps: - name: Checkout Streamlit code uses: actions/checkout@v6 with: ref: ${{ inputs.ref }} persist-credentials: false submodules: "recursive" - name: Download coverage JSON uses: actions/download-artifact@v7 with: name: vitest_coverage_json path: /tmp/current_coverage - name: Get latest develop run ID id: get-latest-run uses: actions/github-script@v8 with: script: | const { data: runs } = await github.rest.actions.listWorkflowRuns({ owner: context.repo.owner, repo: context.repo.repo, workflow_id: 'js-tests.yml', branch: 'develop', status: 'success', per_page: 1 }); if (runs.workflow_runs.length === 0) { throw new Error('No successful workflow runs found on develop branch'); } core.setOutput('run_id', runs.workflow_runs[0].id); - name: Download develop coverage uses: actions/download-artifact@v7 with: repository: streamlit/streamlit run-id: ${{ steps.get-latest-run.outputs.run_id }} name: vitest_coverage_json path: /tmp/develop_coverage # Needs a token to download the artifact from another # workflow run: github-token: ${{ secrets.GITHUB_TOKEN }} - name: Check coverage changes and comment uses: actions/github-script@v8 with: script: | const COVERAGE_CHANGE_THRESHOLD = 0.05; // 0.05% const fs = require('fs'); try { // Read current coverage from the downloaded artifact const currentCoverageData = JSON.parse(fs.readFileSync('/tmp/current_coverage/coverage-summary.json', 'utf8')); // Read develop coverage from downloaded artifact const developCoverageData = JSON.parse(fs.readFileSync('/tmp/develop_coverage/coverage-summary.json', 'utf8')); // Calculate total coverage (focusing on lines as specified) const currentTotal = currentCoverageData.total.lines.pct; const developTotal = developCoverageData.total.lines.pct; // Calculate percentage difference const diffPercent = currentTotal - developTotal; const absDiffPercent = Math.abs(diffPercent); console.log(`Current frontend coverage: ${currentTotal.toFixed(4)}%`); console.log(`Develop frontend coverage: ${developTotal.toFixed(4)}%`); console.log(`Coverage difference: ${diffPercent.toFixed(4)}%`); const changeType = diffPercent > 0 ? 'increased' : 'decreased'; const emoji = diffPercent > 0 ? '📈' : '📉'; // Get current coverage details const currentLines = currentCoverageData.total.lines; const developLines = developCoverageData.total.lines; const commentBody = `### ${emoji} Frontend coverage change detected The frontend unit test (vitest) coverage has **${changeType} by ${Math.abs(diffPercent).toFixed(4)}%** - Current PR: ${currentTotal.toFixed(4)}% (${currentLines.total} lines, ${currentLines.total - currentLines.covered} missed) - Latest develop: ${developTotal.toFixed(4)}% (${developLines.total} lines, ${developLines.total - developLines.covered} missed) ${absDiffPercent >= COVERAGE_CHANGE_THRESHOLD ? (diffPercent > 0 ? '🎉 Great job on improving test coverage!' : '💡 Consider adding more unit tests to maintain or improve coverage.' ) : '✅ Coverage change is within normal range.' } 📊 [View detailed coverage comparison](https://issues.streamlit.app/Test_Coverage_(Frontend)?pr=${context.issue.number})`; // Unique identifier for our comment const commentIdentifier = '<!-- STREAMLIT-JAVASCRIPT-COVERAGE-CHECK -->'; const fullCommentBody = `${commentIdentifier}\n${commentBody}`; // Get all comments on the PR const { data: comments } = await github.rest.issues.listComments({ owner: context.repo.owner, repo: context.repo.repo, issue_number: context.issue.number, }); // Look for our previous coverage comment const coverageComment = comments.find(comment => comment.body.includes(commentIdentifier)); if (coverageComment) { // Update existing comment await github.rest.issues.updateComment({ owner: context.repo.owner, repo: context.repo.repo, comment_id: coverageComment.id, body: fullCommentBody }); console.log('Updated existing coverage comment'); } else if (absDiffPercent >= COVERAGE_CHANGE_THRESHOLD) { // Only create new comment for significant changes await github.rest.issues.createComment({ owner: context.repo.owner, repo: context.repo.repo, issue_number: context.issue.number, body: fullCommentBody }); console.log('Created new coverage comment'); } else { console.log('Coverage change is not significant and no existing comment found, skipping comment'); } } catch (error) { console.error(`Error checking coverage changes: ${error.message}`); }