mirror of
https://github.com/cline/cline.git
synced 2026-09-19 02:05:44 +08:00
188 lines
6.9 KiB
YAML
188 lines
6.9 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
|
|
|
|
# Disabling due to compatability with test framework and ESM modules
|
|
# - name: Unit Tests
|
|
# run: npm run test:unit
|
|
|
|
# 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 }}
|