Skip to content

Commit

Permalink
Clean up smoke test output.
Browse files Browse the repository at this point in the history
  • Loading branch information
domdfcoding committed Nov 5, 2020
1 parent 0aa2ac4 commit 7845f12
Showing 1 changed file with 33 additions and 3 deletions.
36 changes: 33 additions & 3 deletions smoke_test.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# stdlib
import os
import statistics
import sys
import tempfile
import time
from io import BytesIO
from subprocess import Popen

# 3rd party
Expand Down Expand Up @@ -30,6 +32,21 @@ class Templates:
clone_times = []
build_times = []


def is_running_on_actions() -> bool:
"""
Returns :py:obj:`True` if running on GitHub Actions.
"""
# From https://github.com/ymyzk/tox-gh-actions
# Copyright (c) 2019 Yusuke Miyazaki
# MIT Licensed

# See the following document on which environ to use for this purpose.
# https://docs.github.com/en/free-pro-team@latest/actions/reference/environment-variables#default-environment-variables

return os.environ.get("GITHUB_ACTIONS") == "true"


with tempfile.TemporaryDirectory() as tmpdir:
tmpdir_p = PathPlus(tmpdir)

Expand Down Expand Up @@ -74,12 +91,18 @@ class Templates:

target_dir = tmpdir_p / f"{username}_{repository}"
url = GITHUB_COM / username / repository
print(f"::group::{username}_{repository}")
if is_running_on_actions():
print(f"::group::{username}_{repository}")
print("\n\n==============================================")
print(f"Cloning {url!s} -> {target_dir!s}")

if is_running_on_actions():
errstream = BytesIO()
else:
errstream = None

start_time = time.time()
porcelain.clone(str(url), target_dir)
porcelain.clone(str(url), target_dir, depth=1, errstream=errstream)
clone_times.append(time.time() - start_time)

with in_directory(target_dir):
Expand Down Expand Up @@ -115,9 +138,13 @@ class Templates:
exit_code = check_wheel_process.wait()
ret |= exit_code

print("::endgroup::")
if is_running_on_actions():
print("::endgroup::")

print("\n")
if is_running_on_actions():
print("::group::Summary")

print(
"Average clone time:",
f"{statistics.mean(clone_times)}s,",
Expand All @@ -131,4 +158,7 @@ class Templates:
f"(n={len(build_times)})",
)

if is_running_on_actions():
print("::endgroup::")

sys.exit(ret)

0 comments on commit 7845f12

Please sign in to comment.