Skip to content

Commit

Permalink
Move coverage to nightly and simplify reporting (#15776)
Browse files Browse the repository at this point in the history
* Enable coverage for venv and single workspace tests

* Upload coverage for single workspace

* Try with spawn wrap

* Fix coverage artifact upload

* Try running tests with coverage directly

* Run coverage separately

* Remove start page from coverage

* Add back codecov

* No need to move codecov.yml

* Ensure nightly coverage runs on schedule only

* Nightly should only run coverage

* Address comments

* Remove setting node version env for each job
  • Loading branch information
karthiknadig authored Mar 26, 2021
1 parent 6bb8c69 commit 9b881fc
Show file tree
Hide file tree
Showing 8 changed files with 375 additions and 218 deletions.
3 changes: 0 additions & 3 deletions .github/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,3 @@ comment:
layout: 'diff, files'
behavior: default
require_changes: no

fixes:
- 'path with spaces/::'
133 changes: 13 additions & 120 deletions .github/workflows/insiders.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@ env:
NODE_VERSION: 12.15.0
PYTHON_VERSION: 3.9
MOCHA_REPORTER_JUNIT: true # Use the mocha-multi-reporters and send output to both console (spec) and JUnit (mocha-junit-reporter). Also enables a reporter which exits the process running the tests if it haven't already.
# Key for the cache created at the end of the the 'Cache ./pythonFiles/lib/python' step.
CACHE_PYTHONFILES: cache-pvsc-pythonFiles
ARTIFACT_NAME_VSIX: ms-python-insiders-vsix
VSIX_NAME: ms-python-insiders.vsix
COVERAGE_REPORTS: tests-coverage-reports
TEST_RESULTS_DIRECTORY: .
# Force a path with spaces and to test extension works in these scenarios
# Unicode characters are causing 2.7 failures so skip that for now.
Expand Down Expand Up @@ -100,12 +97,6 @@ jobs:
name: Tests
# The value of runs-on is the OS of the current job (specified in the strategy matrix below) instead of being hardcoded.
runs-on: ${{ matrix.os }}
env:
# Something in Node 12.16.0 breaks the TS debug adapter, and ubuntu-latest bundles Node 12.16.1.
# We can remove this when we switch over to the python-based DA in https://github.com/microsoft/vscode-python/issues/7136.
# See https://github.com/microsoft/ptvsd/issues/2068
# At this point pinning is only needed for consistency. We no longer have TS debug adapter.
NODE_VERSION: 12.15.0
defaults:
run:
working-directory: ${{env.special-working-directory}}
Expand Down Expand Up @@ -170,9 +161,7 @@ jobs:
if: matrix.test-suite == 'debugger' && matrix.python == 2.7

- name: Install functional test requirements
run: |
python -m pip install numpy
python -m pip install --upgrade -r ./build/functional-test-requirements.txt
run: python -m pip install --upgrade -r ./build/functional-test-requirements.txt
if: matrix.test-suite == 'functional'

- name: Prepare pipenv for venv tests
Expand Down Expand Up @@ -247,16 +236,7 @@ jobs:

# Run TypeScript unit tests only for Python 3.X.
- name: Run TypeScript unit tests
run: npm run test:unittests:cover
if: matrix.test-suite == 'ts-unit' && startsWith(matrix.python, 3.)

# Upload unit test coverage reports for later use in the "reports" job.
- name: Upload unit test coverage reports
uses: actions/upload-artifact@v2
with:
name: ${{runner.os}}-${{env.COVERAGE_REPORTS}}
path: ${{ env.special-working-directory }}/.nyc_output
retention-days: 1
run: npm run test:unittests
if: matrix.test-suite == 'ts-unit' && startsWith(matrix.python, 3.)

# Run the Python tests in our codebase.
Expand Down Expand Up @@ -310,16 +290,7 @@ jobs:

# Run TypeScript functional tests
- name: Run TypeScript functional tests
run: npm run test:functional:cover
if: matrix.test-suite == 'functional'

# Upload functional test coverage reports for later use in the "reports" job.
- name: Upload functional test coverage reports
uses: actions/upload-artifact@v2
with:
name: ${{runner.os}}-${{env.COVERAGE_REPORTS}}
path: ${{ env.special-working-directory }}/.nyc_output
retention-days: 1
run: npm run test:functional
if: matrix.test-suite == 'functional'

smoke-tests:
Expand Down Expand Up @@ -444,92 +415,14 @@ jobs:
echo "CI_DISABLE_AUTO_SELECTION=1" >> $GITHUB_ENV
shell: bash

# - name: Run insider tests
# env:
# DISPLAY: 10
# INSTALL_JUPYTER_EXTENSION: true
# INSTALL_PYLANCE_EXTENSION: true
# VSC_PYTHON_CI_TEST_VSC_CHANNEL: insiders
# TEST_FILES_SUFFIX: insiders.test
# CODE_TESTS_WORKSPACE: ./src/testMultiRootWkspc/smokeTests
# uses: GabrielBB/xvfb-action@v1.4
# with:
# run: node --no-force-async-hooks-checks ./out/test/standardTest.js

coverage:
name: Coverage reports upload
runs-on: ubuntu-latest
if: github.repository == 'microsoft/vscode-python'
needs: [tests, smoke-tests]
defaults:
run:
working-directory: ${{env.special-working-directory}}
steps:
# Checkout the repo in the same way as how the tests are run,
# or nyc won't know how to reconcile the reports generated by the tests.
- name: Checkout
uses: actions/checkout@v2
with:
path: ${{env.special-working-directory-relative}}

- name: Install Node
uses: actions/setup-node@v2.1.5
with:
node-version: ${{env.NODE_VERSION}}

- name: Install dependencies (npm ci)
run: npm ci --prefer-offline

# It isn't possible to specify a regex for artifact names, so we have to download each artifact manually.
# The name pattern is ${{runner.os}}-${{env.COVERAGE_REPORTS}}, and possible values for runner.os are `Linux`, `Windows`, or `macOS`.
# See https://help.github.com/en/actions/reference/contexts-and-expression-syntax-for-github-actions#runner-context
- name: Download Ubuntu test coverage artifacts
uses: actions/download-artifact@v2
with:
name: Linux-${{ env.COVERAGE_REPORTS }}
path: ${{env.special-working-directory}}/Linux-${{ env.COVERAGE_REPORTS }}

- name: Extract Ubuntu coverage artifacts to ./nyc_output
run: |
mkdir .nyc_output
mv Linux-${{ env.COVERAGE_REPORTS }}/* .nyc_output
rm -r Linux-${{ env.COVERAGE_REPORTS }}
- name: Generate coverage reports
run: npm run test:cover:report
continue-on-error: true

# The only location supported by the codecov action is the workspace root.
# See https://github.com/codecov/codecov-action#arguments
- name: Move codecov.yml to root
run: |
mkdir $GITHUB_WORKSPACE/.github
mv .github/codecov.yml $GITHUB_WORKSPACE
- name: Upload coverage to codecov
uses: codecov/codecov-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: ${{env.special-working-directory}}/coverage/cobertura-coverage.xml

upload:
name: Upload VSIX to Azure Blob Storage
if: github.repository == 'microsoft/vscode-python'
runs-on: ubuntu-latest
needs: [tests, smoke-tests, build-vsix]
env:
BLOB_CONTAINER_NAME: extension-builds
BLOB_NAME: ms-python-insiders.vsix
steps:
- name: Download VSIX
uses: actions/download-artifact@v2
with:
name: ${{ env.ARTIFACT_NAME_VSIX }}
- name: Azure Login
uses: azure/login@v1
- name: Run insider tests
env:
DISPLAY: 10
INSTALL_JUPYTER_EXTENSION: true
INSTALL_PYLANCE_EXTENSION: true
VSC_PYTHON_CI_TEST_VSC_CHANNEL: insiders
TEST_FILES_SUFFIX: insiders.test
CODE_TESTS_WORKSPACE: ./src/testMultiRootWkspc/smokeTests
uses: GabrielBB/xvfb-action@v1.4
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Upload to Blob Storage
run: az storage blob upload --file ${{ env.VSIX_NAME }} --account-name pvsc --container-name ${{ env.BLOB_CONTAINER_NAME }} --name ${{ env.BLOB_NAME }} --auth-mode login
- name: Get URL to uploaded VSIX
run: az storage blob url --account-name pvsc --container-name ${{ env.BLOB_CONTAINER_NAME }} --name ${{ env.BLOB_NAME }} --auth-mode login
run: node --no-force-async-hooks-checks ./out/test/standardTest.js
188 changes: 188 additions & 0 deletions .github/workflows/nightly-coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
name: Coverage

on:
schedule:
# Run daily at 2:00 AM
- cron: '0 2 * * *'

env:
NODE_VERSION: 12.15.0
PYTHON_VERSION: 3.9
MOCHA_REPORTER_JUNIT: true # Use the mocha-multi-reporters and send output to both console (spec) and JUnit (mocha-junit-reporter). Also enables a reporter which exits the process running the tests if it haven't already.
ARTIFACT_NAME_VSIX: ms-python-insiders-vsix
VSIX_NAME: ms-python-insiders.vsix
TEST_RESULTS_DIRECTORY: .

jobs:
tests:
name: Tests with Coverage
# The value of runs-on is the OS of the current job (specified in the strategy matrix below) instead of being hardcoded.
runs-on: ${{ matrix.os }}

strategy:
fail-fast: false
matrix:
# We're not running CI on macOS for now because it's one less matrix entry to lower the number of runners used,
# macOS runners are expensive, and we assume that Ubuntu is enough to cover the Unix case.
os: [ubuntu-latest, windows-latest]

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Install Node
uses: actions/setup-node@v2.1.5
with:
node-version: ${{env.NODE_VERSION}}

- name: Install dependencies (npm ci)
run: npm ci

- name: Compile
run: npx gulp prePublishNonBundle

- name: Use Python ${{env.PYTHON_VERSION}}
uses: actions/setup-python@v2
with:
python-version: ${{env.PYTHON_VERSION}}

- name: Install Python requirements
run: |
python -m pip --disable-pip-version-check install -t ./pythonFiles/lib/python --no-cache-dir --implementation py --no-deps --upgrade -r requirements.txt --no-user
# We need to have debugpy so that tests relying on it keep passing, but we don't need install_debugpy's logic in the test phase.
python -m pip --disable-pip-version-check install -t ./pythonFiles/lib/python --no-cache-dir --implementation py --no-deps --upgrade --pre debugpy
- name: Install test requirements
run: python -m pip install --upgrade -r build/test-requirements.txt

- name: Install functional test requirements
run: python -m pip install --upgrade -r ./build/functional-test-requirements.txt

- name: Prepare pipenv for venv tests
env:
TEST_FILES_SUFFIX: testvirtualenvs
PYTHON_VIRTUAL_ENVS_LOCATION: './src/tmp/envPaths.json'
shell: pwsh
run: |
python -m pip install pipenv
python -m pipenv run python ./build/ci/addEnvPath.py ${{env.PYTHON_VIRTUAL_ENVS_LOCATION}} pipenvPath
- name: Prepare virtualenv for venv tests
env:
TEST_FILES_SUFFIX: testvirtualenvs
PYTHON_VIRTUAL_ENVS_LOCATION: './src/tmp/envPaths.json'
shell: pwsh
run: |
python -m pip install virtualenv
python -m virtualenv .virtualenv/
if ('${{matrix.os}}' -match 'windows-latest') {
& ".virtualenv/Scripts/python.exe" ./build/ci/addEnvPath.py ${{env.PYTHON_VIRTUAL_ENVS_LOCATION}} virtualEnvPath
} else {
& ".virtualenv/bin/python" ./build/ci/addEnvPath.py ${{env.PYTHON_VIRTUAL_ENVS_LOCATION}} virtualEnvPath
}
- name: Prepare venv for venv tests
env:
TEST_FILES_SUFFIX: testvirtualenvs
PYTHON_VIRTUAL_ENVS_LOCATION: './src/tmp/envPaths.json'
shell: pwsh
run: |
python -m venv .venv
if ('${{matrix.os}}' -match 'windows-latest') {
& ".venv/Scripts/python.exe" ./build/ci/addEnvPath.py ${{env.PYTHON_VIRTUAL_ENVS_LOCATION}} venvPath
} else {
& ".venv/bin/python" ./build/ci/addEnvPath.py ${{env.PYTHON_VIRTUAL_ENVS_LOCATION}} venvPath
}
- name: Prepare conda for venv tests
env:
TEST_FILES_SUFFIX: testvirtualenvs
PYTHON_VIRTUAL_ENVS_LOCATION: './src/tmp/envPaths.json'
shell: pwsh
run: |
# 1. For `terminalActivation.testvirtualenvs.test.ts`
if ('${{matrix.os}}' -match 'windows-latest') {
$condaPythonPath = Join-Path -Path $Env:CONDA -ChildPath python.exe
$condaExecPath = Join-Path -Path $Env:CONDA -ChildPath Scripts | Join-Path -ChildPath conda
} else{
$condaPythonPath = Join-Path -Path $Env:CONDA -ChildPath bin | Join-Path -ChildPath python
$condaExecPath = Join-Path -Path $Env:CONDA -ChildPath bin | Join-Path -ChildPath conda
}
& $condaPythonPath ./build/ci/addEnvPath.py ${{env.PYTHON_VIRTUAL_ENVS_LOCATION}} condaExecPath $condaExecPath
& $condaPythonPath ./build/ci/addEnvPath.py ${{env.PYTHON_VIRTUAL_ENVS_LOCATION}} condaPath
# 2. For `interpreterLocatorService.testvirtualenvs.ts`
& $condaExecPath create -n "test_env1" -y python
& $condaExecPath create -p "./test_env2" -y python
& $condaExecPath create -p "~/test_env3" -y python
- name: Run TypeScript unit tests
run: npm run test:unittests:cover

- name: Run Python unit tests
run: |
python pythonFiles/tests/run_all.py
# The virtual environment based tests use the `testSingleWorkspace` set of tests
# with the environment variable `TEST_FILES_SUFFIX` set to `testvirtualenvs`,
# which is set in the "Prepare environment for venv tests" step.
# We also use a third-party GitHub Action to install xvfb on Linux,
# run tests and then clean up the process once the tests ran.
# See https://github.com/GabrielBB/xvfb-action
- name: Run venv tests
env:
TEST_FILES_SUFFIX: testvirtualenvs
CI_PYTHON_VERSION: ${{env.PYTHON_VERSION}}
CI_DISABLE_AUTO_SELECTION: 1
uses: GabrielBB/xvfb-action@v1.4
with:
run: npm run testSingleWorkspace:cover

- name: Run single-workspace tests
env:
CI_PYTHON_VERSION: ${{env.PYTHON_VERSION}}
CI_DISABLE_AUTO_SELECTION: 1
uses: GabrielBB/xvfb-action@v1.4
with:
run: npm run testSingleWorkspace:cover

# Enable these tests when coverage is setup for multiroot workspace tests
# - name: Run multi-workspace tests
# env:
# CI_PYTHON_VERSION: ${{env.PYTHON_VERSION}}
# CI_DISABLE_AUTO_SELECTION: 1
# uses: GabrielBB/xvfb-action@v1.4
# with:
# run: npm run testMultiWorkspace:cover

# Enable these tests when coverage is setup for debugger tests
# - name: Run debugger tests
# env:
# CI_PYTHON_VERSION: ${{env.PYTHON_VERSION}}
# CI_DISABLE_AUTO_SELECTION: 1
# uses: GabrielBB/xvfb-action@v1.4
# with:
# run: npm run testDebugger:cover

- name: Run TypeScript functional tests
env:
CI_PYTHON_VERSION: ${{env.PYTHON_VERSION}}
CI_DISABLE_AUTO_SELECTION: 1
run: npm run test:functional:cover

- name: Generate coverage reports
run: npm run test:cover:report

- name: Upload HTML report
uses: actions/upload-artifact@v2
with:
name: ${{ runner.os }}-coverage-report-html
path: ./coverage
retention-days: 1

- name: Upload coverage to codecov
uses: codecov/codecov-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: ./coverage/cobertura-coverage.xml
Loading

0 comments on commit 9b881fc

Please sign in to comment.