* add coverage to github workflows * add changeset * continue to run on errors * address comments from ellipsis-dev * add unit tests, confirm passing * remove pyproject.toml approach to deps instalL * use github_output env var * add verbose mode for debugging * verbose was not being captured * std out, not print * remove 1000 line dump... * print every line separately to prevent clipping * build extension before testing * clean up debugging prints * break coverage.py into smaller files * break coverage.py into smaller files * Relative module names not supported * rename coverage to coverage_check to avoid naming collision * rename coverage to coverage_check to avoid naming collision * debugging missing coverage files * output error on coverage report * handling ellipsis-dev comments * see if we need vscode test deps * experimenting to try to get it running * use absolute paths * put everything in root directory * address more comments from ellipsis-dev * import run_command in extraction.py * fix verbose flag * use parent parser * ensure safe command test will allow our commands * make sure we install before coverage * update tests to ensure run --------- Co-authored-by: Dennis Bartlett <bartlett.dc.1@gmail.com>
184 lines
6.7 KiB
YAML
184 lines
6.7 KiB
YAML
name: Tests
|
|
|
|
on:
|
|
workflow_dispatch:
|
|
pull_request:
|
|
branches:
|
|
- main
|
|
workflow_call:
|
|
|
|
# Set default permissions for all jobs
|
|
permissions:
|
|
contents: read # Needed to check out code
|
|
checks: write # Needed to report test results
|
|
pull-requests: write # Needed to add comments/annotations to PRs
|
|
|
|
jobs:
|
|
test:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Setup Node.js environment
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: 20.15.1
|
|
|
|
# Setup Python for coverage script
|
|
- name: Setup Python
|
|
uses: actions/setup-python@v4
|
|
with:
|
|
python-version: "3.10"
|
|
|
|
- name: Install Python dependencies
|
|
run: |
|
|
python -m pip install --upgrade pip
|
|
pip install requests
|
|
|
|
# Cache root dependencies - only reuse if package-lock.json exactly matches
|
|
- name: Cache root dependencies
|
|
uses: actions/cache@v4
|
|
id: root-cache
|
|
with:
|
|
path: node_modules
|
|
key: ${{ runner.os }}-npm-${{ hashFiles('package-lock.json') }}
|
|
|
|
# Cache webview-ui dependencies - only reuse if package-lock.json exactly matches
|
|
- name: Cache webview-ui dependencies
|
|
uses: actions/cache@v4
|
|
id: webview-cache
|
|
with:
|
|
path: webview-ui/node_modules
|
|
key: ${{ runner.os }}-npm-webview-${{ hashFiles('webview-ui/package-lock.json') }}
|
|
|
|
- name: Install root dependencies
|
|
if: steps.root-cache.outputs.cache-hit != 'true'
|
|
run: npm ci
|
|
|
|
- name: Install webview-ui dependencies
|
|
if: steps.webview-cache.outputs.cache-hit != 'true'
|
|
run: cd webview-ui && npm ci
|
|
|
|
- name: Type Check
|
|
run: npm run check-types
|
|
|
|
- name: ESLint Check
|
|
run: npm run lint
|
|
|
|
- name: Prettier / Format Check
|
|
run: npm run format
|
|
|
|
# Build the extension before running tests
|
|
- name: Build Extension
|
|
run: npm run compile
|
|
|
|
# Run extension tests with coverage
|
|
- name: Extension Tests with Coverage
|
|
id: extension_coverage
|
|
continue-on-error: true
|
|
run: |
|
|
xvfb-run -a npm run test:coverage > extension_coverage.txt 2>&1 || true
|
|
PYTHONPATH=.github/scripts python -m coverage_check extract-coverage extension_coverage.txt --type=extension --github-output --verbose
|
|
|
|
# Run webview tests with coverage
|
|
- name: Webview Tests with Coverage
|
|
id: webview_coverage
|
|
continue-on-error: true
|
|
run: |
|
|
cd webview-ui
|
|
# Ensure coverage dependency is installed
|
|
npm install --no-save @vitest/coverage-v8
|
|
npm run test:coverage > webview_coverage.txt 2>&1 || true
|
|
cd ..
|
|
PYTHONPATH=.github/scripts python -m coverage_check extract-coverage webview-ui/webview_coverage.txt --type=webview --github-output --verbose
|
|
|
|
# Save coverage reports as artifacts (workflow-scoped)
|
|
- name: Save Coverage Reports
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: pr-coverage-reports
|
|
path: |
|
|
extension_coverage.txt
|
|
webview-ui/webview_coverage.txt
|
|
retention-period: workflow # Artifacts are automatically deleted when the workflow completes
|
|
|
|
coverage:
|
|
needs: test
|
|
runs-on: ubuntu-latest
|
|
# Only run on PRs to main branch
|
|
if: github.event_name == 'pull_request' && github.base_ref == 'main'
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0 # Fetch all history for accurate comparison
|
|
|
|
# Setup Python for coverage script
|
|
- name: Setup Python
|
|
uses: actions/setup-python@v4
|
|
with:
|
|
python-version: "3.10"
|
|
|
|
- name: Install Python dependencies
|
|
run: |
|
|
python -m pip install --upgrade pip
|
|
pip install requests
|
|
|
|
- name: Setup Node.js environment
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: 20.15.1
|
|
|
|
# Cache root dependencies - only reuse if package-lock.json exactly matches
|
|
- name: Cache root dependencies
|
|
uses: actions/cache@v4
|
|
id: root-cache
|
|
with:
|
|
path: node_modules
|
|
key: ${{ runner.os }}-npm-${{ hashFiles('package-lock.json') }}
|
|
|
|
# Cache webview-ui dependencies - only reuse if package-lock.json exactly matches
|
|
- name: Cache webview-ui dependencies
|
|
uses: actions/cache@v4
|
|
id: webview-cache
|
|
with:
|
|
path: webview-ui/node_modules
|
|
key: ${{ runner.os }}-npm-webview-${{ hashFiles('webview-ui/package-lock.json') }}
|
|
|
|
- name: Install root dependencies
|
|
if: steps.root-cache.outputs.cache-hit != 'true'
|
|
run: npm ci
|
|
|
|
- name: Install webview-ui dependencies
|
|
if: steps.webview-cache.outputs.cache-hit != 'true'
|
|
run: cd webview-ui && npm ci
|
|
|
|
# Build the extension before running tests
|
|
- name: Build Extension
|
|
run: npm run compile
|
|
|
|
# Download coverage artifacts from test job
|
|
- name: Download Coverage Reports
|
|
uses: actions/download-artifact@v4
|
|
with:
|
|
name: pr-coverage-reports
|
|
path: . # Download to root directory to match expected paths
|
|
|
|
# Process coverage workflow
|
|
- name: Process coverage workflow
|
|
id: coverage
|
|
run: |
|
|
# Extract PR number from GITHUB_REF
|
|
PR_NUMBER=$(echo "$GITHUB_REF" | sed -e 's/refs\/pull\///' -e 's/\/merge//')
|
|
|
|
# Run the coverage workflow from root directory
|
|
PYTHONPATH=.github/scripts python -m coverage_check process-workflow \
|
|
--base-branch ${{ github.base_ref }} \
|
|
--pr-number $PR_NUMBER \
|
|
--repo $GITHUB_REPOSITORY \
|
|
--token ${{ secrets.GITHUB_TOKEN }} \
|
|
--verbose
|
|
env:
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|