8000 CI Adds coverage to docker jobs on Azure (#26027) · Veghit/scikit-learn@05fdbae · GitHub
[go: up one dir, main page]

Skip to content

Commit 05fdbae

Browse files
thomasjpfanjjerphanogrisel
authored andcommitted
CI Adds coverage to docker jobs on Azure (scikit-learn#26027)
Co-authored-by: Julien Jerphanion <git@jjerphan.xyz> Co-authored-by: Olivier Grisel <olivier.grisel@ensta.org>
1 parent 9caf936 commit 05fdbae

11 files changed

+101
-34
lines changed

azure-pipelines.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ jobs:
232232
debian_atlas_32bit:
233233
DOCKER_CONTAINER: 'i386/debian:11.2'
234234
DISTRIB: 'debian-32'
235+
COVERAGE: "true"
235236
LOCK_FILE: './build_tools/azure/debian_atlas_32bit_lock.txt'
236237
# disable pytest xdist due to unknown bug with 32-bit container
237238
PYTEST_XDIST_VERSION: 'none'
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# Defines the show_installed_libraries and activate_environment functions.
6+
source build_tools/shared.sh
7+
8+
activate_environment
9+
10+
# Combine all coverage files generated by subprocesses workers such
11+
# such as pytest-xdist and joblib/loky:
12+
pushd $TEST_DIR
13+
coverage combine --append
14+
popd
15+
16+
# Copy the combined coverage file to the root of the repository:
17+
cp $TEST_DIR/.coverage $BUILD_REPOSITORY_LOCALPATH

build_tools/azure/debian_atlas_32bit_lock.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#
77
attrs==22.2.0
88
# via pytest
9+
coverage==7.2.2
10+
# via pytest-cov
911
cython==0.29.33
1012
# via -r build_tools/azure/debian_atlas_32bit_requirements.txt
1113
joblib==1.1.1
@@ -19,6 +21,10 @@ pluggy==0.13.1
1921
py==1.11.0
2022
# via pytest
2123
pytest==5.3.1
24+
# via
25+
# -r build_tools/azure/debian_atlas_32bit_requirements.txt
26+
# pytest-cov
27+
pytest-cov==2.9.0
2228
# via -r build_tools/azure/debian_atlas_32bit_requirements.txt
2329
threadpoolctl==2.2.0
2430
# via -r build_tools/azure/debian_atlas_32bit_requirements.txt

build_tools/azure/debian_atlas_32bit_requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ cython
55
joblib==1.1.1 # min
66
threadpoolctl==2.2.0
77
pytest==5.3.1 # min
8+
pytest-cov==2.9.0 # min

build_tools/azure/posix-docker.yml

Lines changed: 15 additions & 0 deletions
< 6D40 col width="44"/>
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,17 @@ jobs:
5656
- script: >
5757
docker container run --rm
5858
--volume $TEST_DIR:/temp_dir
59+
--volume $BUILD_REPOSITORY_LOCALPATH:/repo_localpath
5960
--volume $PWD:/io
6061
--volume $CCACHE_DIR:/ccache
6162
-w /io
6263
--detach
6364
--name skcontainer
65+
-e BUILD_SOURCESDIRECTORY=/io
6466
-e TEST_DIR=/temp_dir
6567
-e CCACHE_DIR=/ccache
68+
-e BUILD_REPOSITORY_LOCALPATH=/repo_localpath
69+
-e COVERAGE
6670
-e DISTRIB
6771
-e LOCK_FILE
6872
-e JUNITXML
@@ -82,6 +86,11 @@ jobs:
8286
- script: >
8387
docker exec skcontainer ./build_tools/azure/test_script.sh
8488
displayName: 'Test Library'
89+
- script: >
90+
docker exec skcontainer ./build_tools/azure/combine_coverage_reports.sh
91+
condition: and(succeeded(), eq(variables['COVERAGE'], 'true'),
92+
eq(variables['SELECTED_TESTS'], ''))
93+
displayName: 'Combine coverage'
8594
- task: PublishTestResults@2
8695
inputs:
8796
testResultsFiles: '$(TEST_DIR)/$(JUNITXML)'
@@ -116,3 +125,9 @@ jobs:
116125
JUNIT_FILE: $(TEST_DIR)/$(JUNITXML)
117126
condition: and(succeededOrFailed(), eq(variables['CREATE_ISSUE_ON_TRACKER'], 'true'),
118127
eq(variables['Build.Reason'], 'Schedule'))
128+
- bash: bash build_tools/azure/upload_codecov.sh
129+
condition: and(succeeded(), eq(variables['COVERAGE'], 'true'),
130+
eq(variables['SELECTED_TESTS'], ''))
131+
displayName: 'Upload To Codecov'
132+
env:
133+
CODECOV_TOKEN: $(CODECOV_TOKEN)

build_tools/azure/posix.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ jobs:
6767
condition: and(succeeded(),
6868
eq(variables['CHECK_PYTEST_SOFT_DEPENDENCY'], 'true'),
6969
eq(variables['SELECTED_TESTS'], ''))
70+
- script: |
71+
build_tools/azure/combine_coverage_reports.sh
72+
condition: and(succeeded(), eq(variables['COVERAGE'], 'true'),
73+
eq(variables['SELECTED_TESTS'], ''))
74+
displayName: 'Combine coverage'
7075
- task: PublishTestResults@2
7176
inputs:
7277
testResultsFiles: '$(TEST_DIR)/$(JUNITXML)'

build_tools/azure/test_script.sh

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,10 @@
22

33
set -e
44

5-
# defines the show_installed_libraries function
5+
# Defines the show_installed_libraries and activate_environment functions.
66
source build_tools/shared.sh
77

8-
if [[ "$DISTRIB" =~ ^conda.* ]]; then
9-
source activate $VIRTUALENV
10-
elif [[ "$DISTRIB" == "ubuntu" || "$DISTRIB" == "debian-32" || "$DISTRIB" == "pip-nogil" ]]; then
11-
source $VIRTUALENV/bin/activate
12-
fi
8+
activate_environment
139

1410
if [[ "$BUILD_REASON" == "Schedule" ]]; then
1511
# Enable global random seed randomization to discover seed-sensitive tests

build_tools/azure/upload_codecov.sh

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,48 @@
22

33
set -e
44

5-
# called when COVERAGE=="true" and DISTRIB=="conda"
6-
export PATH=$HOME/miniconda3/bin:$PATH
7-
source activate $VIRTUALENV
8-
9-
# Need to run codecov from a git checkout, so we copy .coverage
10-
# from TEST_DIR where pytest has been run
11-
pushd $TEST_DIR
12-
coverage combine --append
13-
popd
14-
cp $TEST_DIR/.coverage $BUILD_REPOSITORY_LOCALPATH
15-
165
# When we update the codecov uploader version, we need to update the checksums.
176
# The checksum for each codecov binary is available at
187
# https://uploader.codecov.io e.g. for linux
19-
# https://uploader.codecov.io/v0.4.0/linux/codecov.SHA256SUM. In principle we
20-
# need to check the signatures with the codecov gpg key as well, see
8+
# https://uploader.codecov.io/v0.4.1/linux/codecov.SHA256SUM.
9+
10+
# Instead of hardcoding a specific version and signature in this script, it
11+
# would be possible to use the "latest" symlink URL but then we need to
12+
# download both the codecov.SHA256SUM files each time and check the signatures
13+
# with the codecov gpg key as well, see:
2114
# https://docs.codecov.com/docs/codecov-uploader#integrity-checking-the-uploader
22-
# for more details
23-
CODECOV_UPLOADER_VERSION=0.4.0
15+
# However this approach would yield a larger number of downloads from
16+
# codecov.io and keybase.io, therefore increasing the risk of running into
17+
# network failures.
18+
CODECOV_UPLOADER_VERSION=0.4.1
2419
CODECOV_BASE_URL="https://uploader.codecov.io/v$CODECOV_UPLOADER_VERSION"
20+
21+
22+
# Check that the git repo is located at the expected location:
23+
if [[ ! -d "$BUILD_REPOSITORY_LOCALPATH/.git" ]]; then
24+
echo "Could not find the git checkout at $BUILD_REPOSITORY_LOCALPATH"
25+
exit 1
26+
fi
27+
# Check that the combined coverage file exists at the expected location:
28+
if [[ ! -f "$BUILD_REPOSITORY_LOCALPATH/.coverage" ]]; then
29+
echo "Could not find the combined coverage file at $BUILD_REPOSITORY_LOCALPATH/.coverage"
30+
exit 1
31+
fi
2532
if [[ $OSTYPE == *"linux"* ]]; then
2633
curl -Os "$CODECOV_BASE_URL/linux/codecov"
27-
SHA256SUM="671cf0d89d1c149f57e1a9a31f3fb567ab4209e4d5829f13ff7b8c104db7131f codecov"
34+
SHA256SUM="32cb14b5f3aaacd67f4c1ff55d82f037d3cd10c8e7b69c051f27391d2e66e15c codecov"
2835
echo "$SHA256SUM" | shasum -a256 -c
2936
chmod +x codecov
30-
./codecov -t ${CODECOV_TOKEN} --rootDir $BUILD_REPOSITORY_LOCALPATH
37+
./codecov -t ${CODECOV_TOKEN} -R $BUILD_REPOSITORY_LOCALPATH -f .coverage -Z
3138
elif [[ $OSTYPE == *"darwin"* ]]; then
3239
curl -Os "$CODECOV_BASE_URL/macos/codecov"
33-
SHA256SUM="7549819f0fe115e113ec3538e259d748e87d84f68afa5deadc798967ec716b8d codecov"
40+
SHA256SUM="4ab0f06f06e9c4d25464f155b0aff36bfc1e8dbcdb19bfffd586beed1269f3af codecov"
3441
echo "$SHA256SUM" | shasum -a256 -c
3542
chmod +x codecov
36-
./codecov -t ${CODECOV_TOKEN} --rootDir $BUILD_REPOSITORY_LOCALPATH
43+
./codecov -t ${CODECOV_TOKEN} -R $BUILD_REPOSITORY_LOCALPATH -f .coverage -Z
3744
else
3845
curl -Os "$CODECOV_BASE_URL/windows/codecov.exe"
39-
SHA256SUM="15fb34be4eb9949ad4e964a0e21c4efc79657de05b2c799e041d7293dccf60eb codecov.exe"
46+
SHA256SUM="e0cda212aeaebe695509ce8fa2d608760ff70bc932003f544f1ad368ac5450a8 codecov.exe"
4047
echo "$SHA256SUM" | sha256sum -c
41-
./codecov.exe -t ${CODECOV_TOKEN} --rootDir $BUILD_REPOSITORY_LOCALPATH
48+
./codecov.exe -t ${CODECOV_TOKEN} -R $BUILD_REPOSITORY_LOCALPATH -f .coverage -Z
4249
fi

build_tools/azure/windows.yml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,10 @@ jobs:
4141
displayName: 'Install'
4242
- bash: ./build_tools/azure/test_script.sh
4343
displayName: 'Test Library'
44-
- bash: ./build_tools/azure/upload_codecov.sh
45-
condition: and(succeeded(),
46-
eq(variables['COVERAGE'], 'true'),
44+
- bash: ./build_tools/azure/combine_coverage_reports.sh
45+
condition: and(succeeded(), eq(variables['COVERAGE'], 'true'),
4746
eq(variables['SELECTED_TESTS'], ''))
48-
displayName: 'Upload To Codecov'
49-
env:
50-
CODECOV_TOKEN: $(CODECOV_TOKEN)
47+
displayName: 'Combine coverage'
5148
- task: PublishTestResults@2
5249
inputs:
5350
testResultsFiles: '$(TEST_DIR)/$(JUNITXML)'
@@ -78,3 +75,10 @@ jobs:
7875
JUNIT_FILE: $(TEST_DIR)/$(JUNITXML)
7976
condition: and(succeededOrFailed(), eq(variables['CREATE_ISSUE_ON_TRACKER'], 'true'),
8077
eq(variables['Build.Reason'], 'Schedule'))
78+
- bash: ./build_tools/azure/upload_codecov.sh
79+
condition: and(succeeded(),
80+
eq(variables['COVERAGE'], 'true'),
81+
eq(variables['SELECTED_TESTS'], ''))
82+
displayName: 'Upload To Codecov'
83+
env:
84+
CODECOV_TOKEN: $(CODECOV_TOKEN)

build_tools/shared.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,11 @@ show_installed_libraries(){
2525
python -m pip list
2626
fi
2727
}
28+
29+
activate_environment() {
30+
if [[ "$DISTRIB" =~ ^conda.* ]]; then
31+
source activate $VIRTUALENV
32+
elif [[ "$DISTRIB" == "ubuntu" || "$DISTRIB" == "debian-32" || "$DISTRIB" == "pip-nogil" ]]; then
33+
source $VIRTUALENV/bin/activate
34+
fi
35+
}

0 commit comments

Comments
 (0)
0