Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI: Have codecov collect on all platforms #1381

Merged
merged 3 commits into from Oct 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Empty file added .coverage_dir/.empty
Empty file.
1 change: 1 addition & 0 deletions .coveragerc
@@ -1,2 +1,3 @@
[run]
omit=*/tests/*
parallel=true
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -26,6 +26,8 @@ MANIFEST
*~
.pytest_cache
.coverage
.coverage_dir
coverage.xml

# Rever
rever/
6 changes: 5 additions & 1 deletion .travis.yml
Expand Up @@ -31,6 +31,7 @@ matrix:
- TOXENV=py37-test-deps
- HDF5_VERSION=1.10.5
- HDF5_DIR=$HDF5_CACHE_DIR/$HDF5_VERSION
- H5PY_ENFORCE_COVERAGE=yes
os: linux-ppc64le

# Builds the API docs
Expand All @@ -56,6 +57,7 @@ matrix:
- TOXENV=py36-test-mindeps-mpi4py
- CC="mpicc"
- HDF5_MPI="ON"
- H5PY_ENFORCE_COVERAGE=yes
addons:
apt:
packages:
Expand All @@ -69,10 +71,12 @@ matrix:
- TOXENV=nightly
- HDF5_VERSION=1.10.5
- HDF5_DIR=$HDF5_CACHE_DIR/$HDF5_VERSION
- H5PY_ENFORCE_COVERAGE=yes

- python: pypy3
env:
- TOXENV=pypy3-test-deps
- H5PY_ENFORCE_COVERAGE=yes
allow_failures:
- python: pypy3
- python: 'nightly'
Expand All @@ -89,4 +93,4 @@ script:
- tox

after_success:
- codecov
- python ci/upload_coverage.py
2 changes: 2 additions & 0 deletions MANIFEST.in
Expand Up @@ -37,6 +37,8 @@ exclude *.yaml
recursive-exclude * __pycache__
recursive-exclude * *.py[co]
exclude .coveragerc
exclude .coverage_dir
recursive-exclude .coverage_dir *
exclude .mailmap
exclude github_deploy_key_h5py_h5py.enc

Expand Down
3 changes: 2 additions & 1 deletion appveyor.yml
Expand Up @@ -2,6 +2,7 @@
environment:
HDF5_VERSION: "1.8.17"
TOX_TESTENV_PASSENV: "HDF5_DIR"
H5PY_ENFORCE_COVERAGE: "YES"

matrix:

Expand Down Expand Up @@ -68,4 +69,4 @@ cache:
- "C:\\hdf5"

on_success:
- "py -3.6 -m codecov"
- "py -3.6 ci\\upload_coverage.py"
11 changes: 11 additions & 0 deletions azure-pipelines.yml
Expand Up @@ -23,6 +23,7 @@ jobs:
py36:
python.version: '3.6'
TOXENV: py36-test-deps,py36-test-mindeps,py36-test-deps-pre,py36-test-mindeps-tables
H5PY_ENFORCE_COVERAGE: yes
py37:
python.version: '3.7'
TOXENV: py37-test-deps,py37-test-mindeps,py37-test-deps-pre,py37-test-deps-tables
Expand All @@ -33,22 +34,26 @@ jobs:
TOX_TESTENV_PASSENV: LANG LC_ALL
LANG: C
LC_ALL: C
H5PY_ENFORCE_COVERAGE: yes
# test against newer HDF5
py36-deps-hdf51103:
python.version: '3.6'
TOXENV: py36-test-deps
HDF5_VERSION: 1.10.3
HDF5_DIR: $(HDF5_CACHE_DIR)/$(HDF5_VERSION)
H5PY_ENFORCE_COVERAGE: yes
py37-deps-hdf51104:
python.version: '3.7'
TOXENV: py37-test-deps
HDF5_VERSION: 1.10.4
HDF5_DIR: $(HDF5_CACHE_DIR)/$(HDF5_VERSION)
H5PY_ENFORCE_COVERAGE: yes
py37-deps-hdf51105:
python.version: '3.7'
TOXENV: py37-test-deps
HDF5_VERSION: 1.10.5
HDF5_DIR: $(HDF5_CACHE_DIR)/$(HDF5_VERSION)
H5PY_ENFORCE_COVERAGE: yes
# do mpi tests
# py36-deps-hdf51105-mpi:
# python.version: '3.6'
Expand Down Expand Up @@ -89,25 +94,29 @@ jobs:
HDF5_VERSION: 1.8.17
HDF5_DIR: $(HDF5_CACHE_DIR)/$(HDF5_VERSION)
HDF5_VSVERSION: "15-64"
H5PY_ENFORCE_COVERAGE: yes
py37-hdf518:
python.version: '3.7'
TOXENV: py37-test-deps,py37-test-mindeps,py37-test-deps-pre
HDF5_VERSION: 1.8.17
HDF5_DIR: $(HDF5_CACHE_DIR)/$(HDF5_VERSION)
HDF5_VSVERSION: "15-64"
H5PY_ENFORCE_COVERAGE: yes
# 64 bit - HDF5 1.10
py36-hdf5110:
python.version: '3.6'
TOXENV: py36-test-deps,py36-test-mindeps,py36-test-deps-pre
HDF5_VERSION: 1.10.1
HDF5_DIR: $(HDF5_CACHE_DIR)/$(HDF5_VERSION)
HDF5_VSVERSION: "15-64"
H5PY_ENFORCE_COVERAGE: yes
py37-hdf5110:
python.version: '3.7'
TOXENV: py37-test-deps,py37-test-mindeps,py37-test-deps-pre
HDF5_VERSION: 1.10.1
HDF5_DIR: $(HDF5_CACHE_DIR)/$(HDF5_VERSION)
HDF5_VSVERSION: "15-64"
H5PY_ENFORCE_COVERAGE: yes
maxParallel: 4

steps:
Expand All @@ -128,9 +137,11 @@ jobs:
py36:
python.version: '3.6'
TOXENV: py36-test-deps,py36-test-mindeps,py36-test-deps-pre
H5PY_ENFORCE_COVERAGE: yes
py37:
python.version: '3.7'
TOXENV: py37-test-deps,py37-test-mindeps,py37-test-deps-pre
H5PY_ENFORCE_COVERAGE: yes
# test against newer HDF5
# py36-deps-hdf51103:
# python.version: '3.6'
Expand Down
7 changes: 5 additions & 2 deletions ci/azure-pipelines-steps.yml
Expand Up @@ -71,6 +71,9 @@ steps:
tox
displayName: 'tox'

- script: |
codecov -t 813fb6da-087d-4b36-a185-5a530cab3455
- task: PythonScript@0
inputs:
scriptSource: 'filePath'
scriptPath: 'ci/upload_coverage.py'
arguments: --codecov-token 813fb6da-087d-4b36-a185-5a530cab3455
displayName: 'codecov'
89 changes: 89 additions & 0 deletions ci/upload_coverage.py
@@ -0,0 +1,89 @@
"""
Helper script to combine coverage (as codecov seems to have problems...).
Written in python to be cross-platform
"""

import argparse
from os import chdir, listdir, environ
from pathlib import Path
import platform
from pprint import pprint
import shlex
from subprocess import run, PIPE
import sys

THIS_FILE = Path(__file__)
GIT_MAIN_DIR = THIS_FILE.parent.parent.resolve()
COVERAGE_DIR = GIT_MAIN_DIR.joinpath('.coverage_dir')
PYVERSION = '{}.{}'.format(sys.version_info[0], sys.version_info[1])


def msg(*args):
print('ERR:', *args, file=sys.stderr)


def pmsg(*args):
pprint(*args, stream=sys.stderr)


def run_with_python(args, **kwargs):
if platform.system() == 'Windows':
exe = ['py', '-' + PYVERSION, '-m']
else:
exe = []
cmd = exe + args
msg("Running:", *cmd)
try:
res = run(cmd, check=True, stdout=PIPE, stderr=PIPE, **kwargs)
except CalledProcessError as e:
msg("STDOUT:")
sys.stdout.buffer.write(e.stdout)
msg("STDERR:")
sys.stderr.buffer.write(e.stdout)
raise
else:
msg("STDOUT:")
sys.stdout.buffer.write(res.stdout)
msg("STDERR:")
sys.stderr.buffer.write(res.stdout)
return res


def send_coverage(*, workdir, coverage_files, codecov_token):
chdir(workdir)
run_with_python(['coverage', 'combine'] + coverage_files)
msg(f"Combined coverage, listing {GIT_MAIN_DIR}")
pmsg(sorted(listdir(GIT_MAIN_DIR)))
run_with_python(['coverage', 'xml', '--ignore-errors'])
msg(f"Created coverage xml, listing {GIT_MAIN_DIR}")
pmsg(sorted(listdir(GIT_MAIN_DIR)))
codecov_args = ["--required"]
if codecov_token is not None:
codecov_args.extend(['-t', codecov_token])
codecov_args.extend(['--file', 'coverage.xml'])
run_with_python(['codecov'] + codecov_args)


def main():
parser = argparse.ArgumentParser()
parser.add_argument("--codecov-token", default=None)
args = parser.parse_args()
msg(f"Working in {GIT_MAIN_DIR}, listing coverage dir {COVERAGE_DIR}")
pmsg(sorted(listdir(COVERAGE_DIR)))
coverage_files = [str(f) for f in COVERAGE_DIR.glob('coverage-*')]
if coverage_files:
send_coverage(
workdir=GIT_MAIN_DIR,
coverage_files=coverage_files,
codecov_token=args.codecov_token,
)
else:
msg("No coverage files found")
if environ.get("H5PY_ENFORCE_COVERAGE") is not None:
raise RuntimeError(
"Coverage required, no coverage found, failing..."
)


if __name__ == '__main__':
main()
5 changes: 5 additions & 0 deletions codecov.yml
@@ -0,0 +1,5 @@
coverage:
status:
project:
default:
threshold: 0.5%
2 changes: 1 addition & 1 deletion tox.ini
Expand Up @@ -35,7 +35,7 @@ changedir =
passenv =
HDF5_DIR
setenv =
COVERAGE_FILE={toxinidir}/.coverage
COVERAGE_FILE={toxinidir}/.coverage_dir/coverage-{envname}
# needed otherwise coverage cannot find the file when reporting

pip_pre =
Expand Down