Skip to content

Commit 7845f12

Browse files
committed
Clean up smoke test output.
1 parent 0aa2ac4 commit 7845f12

File tree

1 file changed

+33
-3
lines changed

1 file changed

+33
-3
lines changed

smoke_test.py

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# stdlib
2+
import os
23
import statistics
34
import sys
45
import tempfile
56
import time
7+
from io import BytesIO
68
from subprocess import Popen
79

810
# 3rd party
@@ -30,6 +32,21 @@ class Templates:
3032
clone_times = []
3133
build_times = []
3234

35+
36+
def is_running_on_actions() -> bool:
37+
"""
38+
Returns :py:obj:`True` if running on GitHub Actions.
39+
"""
40+
# From https://github.com/ymyzk/tox-gh-actions
41+
# Copyright (c) 2019 Yusuke Miyazaki
42+
# MIT Licensed
43+
44+
# See the following document on which environ to use for this purpose.
45+
# https://docs.github.com/en/free-pro-team@latest/actions/reference/environment-variables#default-environment-variables
46+
47+
return os.environ.get("GITHUB_ACTIONS") == "true"
48+
49+
3350
with tempfile.TemporaryDirectory() as tmpdir:
3451
tmpdir_p = PathPlus(tmpdir)
3552

@@ -74,12 +91,18 @@ class Templates:
7491

7592
target_dir = tmpdir_p / f"{username}_{repository}"
7693
url = GITHUB_COM / username / repository
77-
print(f"::group::{username}_{repository}")
94+
if is_running_on_actions():
95+
print(f"::group::{username}_{repository}")
7896
print("\n\n==============================================")
7997
print(f"Cloning {url!s} -> {target_dir!s}")
8098

99+
if is_running_on_actions():
100+
errstream = BytesIO()
101+
else:
102+
errstream = None
103+
81104
start_time = time.time()
82-
porcelain.clone(str(url), target_dir)
105+
porcelain.clone(str(url), target_dir, depth=1, errstream=errstream)
83106
clone_times.append(time.time() - start_time)
84107

85108
with in_directory(target_dir):
@@ -115,9 +138,13 @@ class Templates:
115138
exit_code = check_wheel_process.wait()
116139
ret |= exit_code
117140

118-
print("::endgroup::")
141+
if is_running_on_actions():
142+
print("::endgroup::")
119143

120144
print("\n")
145+
if is_running_on_actions():
146+
print("::group::Summary")
147+
121148
print(
122149
"Average clone time:",
123150
f"{statistics.mean(clone_times)}s,",
@@ -131,4 +158,7 @@ class Templates:
131158
f"(n={len(build_times)})",
132159
)
133160

161+
if is_running_on_actions():
162+
print("::endgroup::")
163+
134164
sys.exit(ret)

0 commit comments

Comments
 (0)