Skip to content

Commit

Permalink
Remove codecov upload logic (now it's in gh action)
Browse files Browse the repository at this point in the history
  • Loading branch information
wil93 committed Dec 17, 2022
1 parent 3dd70aa commit fc280d8
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 114 deletions.
16 changes: 5 additions & 11 deletions cmstestsuite/RunFunctionalTests.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# Copyright © 2013-2018 Stefano Maggiolo <s.maggiolo@gmail.com>
# Copyright © 2014 Luca Versari <veluca93@gmail.com>
# Copyright © 2016 Luca Wehrstedt <luca.wehrstedt@gmail.com>
# Copyright © 2022 William Di Luigi <williamdiluigi@gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
Expand All @@ -28,8 +29,7 @@
from cms import utf8_decoder
from cmstestsuite import CONFIG
from cmstestsuite.Tests import ALL_TESTS
from cmstestsuite.coverage import clear_coverage, combine_coverage, \
send_coverage_to_codecov
from cmstestsuite.coverage import clear_coverage, combine_coverage
from cmstestsuite.profiling import \
PROFILER_KERNPROF, PROFILER_NONE, PROFILER_YAPPI
from cmstestsuite.testrunner import TestRunner
Expand Down Expand Up @@ -168,19 +168,16 @@ def main():
parser.add_argument(
"-v", "--verbose", action="count", default=0,
help="print debug information (use multiple times for more)")
parser.add_argument(
"--codecov", action="store_true",
help="send coverage results to Codecov (requires --coverage)")
g = parser.add_mutually_exclusive_group()
g.add_argument(
"--coverage", action="store", type=utf8_decoder,
help="path to the XML coverage report file (if not specified, coverage is not computed)")
help="path to the XML coverage report file (if not specified, "
"coverage is not computed)")
g.add_argument(
"--profiler", choices=[PROFILER_YAPPI, PROFILER_KERNPROF],
default=PROFILER_NONE, help="set profiler")

args = parser.parse_args()
if args.codecov and not args.coverage:
parser.error("--codecov requires --coverage")

CONFIG["VERBOSITY"] = args.verbose
CONFIG["COVERAGE"] = args.coverage
Expand Down Expand Up @@ -239,9 +236,6 @@ def main():
runner.log_elapsed_time()
combine_coverage()

if args.codecov:
send_coverage_to_codecov("functionaltests")

logger.info("Executed: %s", tests)
logger.info("Failed: %s", len(failures))
if not failures:
Expand Down
14 changes: 4 additions & 10 deletions cmstestsuite/RunUnitTests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# Contest Management System - http://cms-dev.github.io/
# Copyright © 2013-2018 Stefano Maggiolo <s.maggiolo@gmail.com>
# Copyright © 2016 Luca Wehrstedt <luca.wehrstedt@gmail.com>
# Copyright © 2022 William Di Luigi <williamdiluigi@gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
Expand All @@ -28,7 +29,7 @@
from cms import utf8_decoder
from cmstestsuite import CONFIG, TestException, sh
from cmstestsuite.coverage import clear_coverage, combine_coverage, \
coverage_cmdline, send_coverage_to_codecov
coverage_cmdline
from cmstestsuite.profiling import \
PROFILER_KERNPROF, PROFILER_NONE, PROFILER_YAPPI, profiling_cmdline

Expand Down Expand Up @@ -144,13 +145,11 @@ def main():
"-r", "--retry-failed", action="store_true",
help="only run failed tests from the previous run (stored in %s)" %
FAILED_UNITTEST_FILENAME)
parser.add_argument(
"--codecov", action="store_true",
help="send coverage results to Codecov (requires --coverage)")
g = parser.add_mutually_exclusive_group()
g.add_argument(
"--coverage", action="store", type=utf8_decoder,
help="path to the XML coverage report file (if not specified, coverage is not computed)")
help="path to the XML coverage report file (if not specified, "
"coverage is not computed)")
g.add_argument(
"--profiler", choices=[PROFILER_YAPPI, PROFILER_KERNPROF],
default=PROFILER_NONE, help="set profiler")
Expand All @@ -164,8 +163,6 @@ def main():
help="unused")

args = parser.parse_args()
if args.codecov and not args.coverage:
parser.error("--codecov requires --coverage")

CONFIG["VERBOSITY"] = args.verbose
CONFIG["COVERAGE"] = args.coverage
Expand Down Expand Up @@ -227,9 +224,6 @@ def test_match(t):
end_time = datetime.datetime.now()
print("Time elapsed: %s" % (end_time - start_time))

if args.codecov:
send_coverage_to_codecov("unittests")

if passed:
return 0
else:
Expand Down
94 changes: 1 addition & 93 deletions cmstestsuite/coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# Copyright © 2013-2018 Stefano Maggiolo <s.maggiolo@gmail.com>
# Copyright © 2013-2016 Luca Wehrstedt <luca.wehrstedt@gmail.com>
# Copyright © 2014 Luca Versari <veluca93@gmail.com>
# Copyright © 2014 William Di Luigi <williamdiluigi@gmail.com>
# Copyright © 2014-2022 William Di Luigi <williamdiluigi@gmail.com>
# Copyright © 2016 Peyman Jabbarzade Ganje <peyman.jabarzade@gmail.com>
# Copyright © 2017 Luca Chiodini <luca@chiodini.org>
# Copyright © 2021 Andrey Vihrov <andrey.vihrov@gmail.com>
Expand All @@ -23,12 +23,8 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import os
import logging
import requests
import subprocess
import sys
from urllib.parse import urlparse

from cmstestsuite import CONFIG, sh

Expand Down Expand Up @@ -71,91 +67,3 @@ def combine_coverage():
logger.info("Combining coverage results.")
sh([sys.executable, "-m", "coverage", "combine"])
sh([sys.executable, "-m", "coverage", "xml", "-o", coverage_file])


# Cache directory for subsequent runs.
_CODECOV_DIR = os.path.join("cache", "cmstestsuite", "codecov")


def _download_file(url, out):
"""Download and save a binary file.
url (str): file to download.
out (str): output file name.
"""
r = requests.get(url, stream=True)
r.raise_for_status()
with open(out, "wb") as f:
for chunk in r.iter_content(chunk_size=4096):
f.write(chunk)


def _import_pgp_key(gpg_home, keyring, fingerprint):
"""Import a PGP key from public keyservers.
gpg_home (str): GnuPG home directory.
keyring (str): Keyring file to use.
fingerprint (str): PGP key fingerprint.
"""

keyservers = [ "hkps://keyserver.ubuntu.com", "hkps://pgp.mit.edu" ]

for keyserver in keyservers:
logger.info("Importing PGP key %s from %s." %
(fingerprint[-8:], urlparse(keyserver).netloc))
try:
subprocess.check_call(["gpg", "--homedir", gpg_home, "--keyring",
keyring, "--no-default-keyring",
"--keyserver", keyserver,
"--recv-keys", fingerprint])
return
except subprocess.CalledProcessError:
logger.warning("PGP key import failed.", exc_info=True)

raise Exception("No usable keyservers left.")


def _get_codecov_uploader():
"""Fetch and return the Codecov uploader.
return (str): path to the stored uploader.
"""
base_url = "https://uploader.codecov.io/latest/linux/"
executable = "codecov"
shasum = "codecov.SHA256SUM"
sigfile = "codecov.SHA256SUM.sig"

gpg_home = os.path.realpath(os.path.join(_CODECOV_DIR, "gnupg"))
# Codecov Uploader (Codecov Uploader Verification Key)
# <security@codecov.io>
fingerprint = "27034E7FDB850E0BBC2C62FF806BB28AED779869"

if not os.access(os.path.join(_CODECOV_DIR, executable), os.X_OK):
os.makedirs(gpg_home, mode=0o700)
_import_pgp_key(gpg_home, "trustedkeys.gpg", fingerprint)

logger.info("Fetching Codecov uploader.")
for name in [executable, shasum, sigfile]:
_download_file(base_url + name, os.path.join(_CODECOV_DIR, name))

logger.info("Checking Codecov uploader integrity.")
subprocess.check_call(["gpgv", "--homedir", gpg_home, sigfile, shasum],
cwd=_CODECOV_DIR)
subprocess.check_call(["sha256sum", "-c", shasum], cwd=_CODECOV_DIR)

os.chmod(os.path.join(_CODECOV_DIR, executable), 0o755)

return os.path.join(_CODECOV_DIR, executable)


def send_coverage_to_codecov(flag):
"""Send the coverage report to Codecov with the given flag."""
coverage_file = CONFIG.get('COVERAGE', None)

if coverage_file:
logger.info("Sending coverage results to codecov for flag %s." % flag)
uploader = _get_codecov_uploader()
subprocess.check_call([uploader, "-F", flag, "-f", coverage_file])
1 change: 1 addition & 0 deletions cmstestsuite/testrunner.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# Contest Management System - http://cms-dev.github.io/
# Copyright © 2015-2018 Stefano Maggiolo <s.maggiolo@gmail.com>
# Copyright © 2016 Amir Keivan Mohtashami <akmohtashami97@gmail.com>
# Copyright © 2022 William Di Luigi <williamdiluigi@gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
Expand Down

0 comments on commit fc280d8

Please sign in to comment.