Skip to content

Commit 73c867c

Browse files
authored
Merge pull request #3446 from migueldiascosta/upload_test_report_easyblocks
take into account --include-easyblocks-from-pr when uploading test reports
2 parents e741113 + b34f13f commit 73c867c

File tree

4 files changed

+62
-27
lines changed

4 files changed

+62
-27
lines changed

easybuild/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,10 @@ def build_and_install_software(ecs, init_session_state, exit_on_failure=True):
137137
parent_dir = os.path.dirname(test_report_fp)
138138
# parent dir for test report may not be writable at this time, e.g. when --read-only-installdir is used
139139
if os.stat(parent_dir).st_mode & 0o200:
140-
write_file(test_report_fp, test_report_txt)
140+
write_file(test_report_fp, test_report_txt['full'])
141141
else:
142142
adjust_permissions(parent_dir, stat.S_IWUSR, add=True, recursive=False)
143-
write_file(test_report_fp, test_report_txt)
143+
write_file(test_report_fp, test_report_txt['full'])
144144
adjust_permissions(parent_dir, stat.S_IWUSR, add=False, recursive=False)
145145

146146
if not ec_res['success'] and exit_on_failure:

easybuild/tools/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ def mk_full_default_path(name, prefix=DEFAULT_PREFIX):
184184
'group',
185185
'hooks',
186186
'ignore_dirs',
187+
'include_easyblocks_from_pr',
187188
'job_backend_config',
188189
'job_cores',
189190
'job_deps_type',

easybuild/tools/testing.py

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
from easybuild.tools.build_log import EasyBuildError
4747
from easybuild.tools.config import build_option
4848
from easybuild.tools.filetools import find_easyconfigs, mkdir, read_file, write_file
49-
from easybuild.tools.github import GITHUB_EASYCONFIGS_REPO, create_gist, post_comment_in_issue
49+
from easybuild.tools.github import GITHUB_EASYBLOCKS_REPO, GITHUB_EASYCONFIGS_REPO, create_gist, post_comment_in_issue
5050
from easybuild.tools.jenkins import aggregate_xml_in_dirs
5151
from easybuild.tools.parallelbuild import build_easyconfigs_in_parallel
5252
from easybuild.tools.robot import resolve_dependencies
@@ -160,7 +160,7 @@ def create_test_report(msg, ecs_with_res, init_session_state, pr_nr=None, gist_l
160160
"",
161161
])
162162

163-
build_overview = []
163+
build_overview = ["#### Overview of tested easyconfigs (in order)"]
164164
for (ec, ec_res) in ecs_with_res:
165165
test_log = ''
166166
if ec_res.get('success', False):
@@ -189,7 +189,8 @@ def create_test_report(msg, ecs_with_res, init_session_state, pr_nr=None, gist_l
189189
test_log = "(partial log available at %s)" % gist_url
190190

191191
build_overview.append(" * **%s** _%s_ %s" % (test_result, os.path.basename(ec['spec']), test_log))
192-
test_report.extend(["#### Overview of tested easyconfigs (in order)"] + build_overview + [""])
192+
build_overview.append("")
193+
test_report.extend(build_overview)
193194

194195
time_format = "%a, %d %b %Y %H:%M:%S +0000 (UTC)"
195196
start_time = strftime(time_format, init_session_state['time'])
@@ -232,7 +233,7 @@ def create_test_report(msg, ecs_with_res, init_session_state, pr_nr=None, gist_l
232233

233234
test_report.extend(["#### Environment", "```"] + environment + ["```"])
234235

235-
return '\n'.join(test_report)
236+
return {'full': '\n'.join(test_report), 'overview': '\n'.join(build_overview)}
236237

237238

238239
def upload_test_report_as_gist(test_report, descr=None, fn=None):
@@ -248,18 +249,18 @@ def upload_test_report_as_gist(test_report, descr=None, fn=None):
248249
return gist_url
249250

250251

251-
def post_easyconfigs_pr_test_report(pr_nr, test_report, msg, init_session_state, success):
252-
"""Post test report in a gist, and submit comment in easyconfigs PR."""
252+
def post_pr_test_report(pr_nr, repo_type, test_report, msg, init_session_state, success):
253+
"""Post test report in a gist, and submit comment in easyconfigs or easyblocks PR."""
253254

254255
github_user = build_option('github_user')
255256
pr_target_account = build_option('pr_target_account')
256-
pr_target_repo = build_option('pr_target_repo') or GITHUB_EASYCONFIGS_REPO
257+
pr_target_repo = build_option('pr_target_repo') or repo_type
257258

258259
# create gist with test report
259260
descr = "EasyBuild test report for %s/%s PR #%s" % (pr_target_account, pr_target_repo, pr_nr)
260261
timestamp = strftime("%Y%M%d-UTC-%H-%M-%S", gmtime())
261262
fn = 'easybuild_test_report_%s_%s_pr%s_%s.md' % (pr_nr, pr_target_account, pr_target_repo, timestamp)
262-
gist_url = upload_test_report_as_gist(test_report, descr=descr, fn=fn)
263+
gist_url = upload_test_report_as_gist(test_report['full'], descr=descr, fn=fn)
263264

264265
# post comment to report test result
265266
system_info = init_session_state['system_info']
@@ -276,18 +277,31 @@ def post_easyconfigs_pr_test_report(pr_nr, test_report, msg, init_session_state,
276277
'pyver': system_info['python_version'].split(' ')[0],
277278
}
278279

279-
comment_lines = [
280-
"Test report by @%s" % github_user,
281-
('**FAILED**', '**SUCCESS**')[success],
280+
comment_lines = ["Test report by @%s" % github_user]
281+
282+
easyblocks_pr_nr = build_option('include_easyblocks_from_pr')
283+
if easyblocks_pr_nr:
284+
if repo_type == GITHUB_EASYCONFIGS_REPO:
285+
comment_lines.append("Using easyblocks from https://github.com/%s/%s/pull/%s" % (
286+
pr_target_account, GITHUB_EASYBLOCKS_REPO, easyblocks_pr_nr))
287+
elif repo_type == GITHUB_EASYBLOCKS_REPO:
288+
comment_lines.append(test_report['overview'])
289+
else:
290+
raise EasyBuildError("Don't know how to submit test reports to repo %s.", repo_type)
291+
292+
if repo_type == GITHUB_EASYCONFIGS_REPO:
293+
comment_lines.append(('**FAILED**', '**SUCCESS**')[success])
294+
295+
comment_lines.extend([
282296
msg,
283297
short_system_info,
284298
"See %s for a full test report." % gist_url,
285-
]
299+
])
286300
comment = '\n'.join(comment_lines)
287301

288302
post_comment_in_issue(pr_nr, comment, account=pr_target_account, repo=pr_target_repo, github_user=github_user)
289303

290-
msg = "Test report uploaded to %s and mentioned in a comment in easyconfigs PR#%s" % (gist_url, pr_nr)
304+
msg = "Test report uploaded to %s and mentioned in a comment in %s PR#%s" % (gist_url, pr_target_repo, pr_nr)
291305
return msg
292306

293307

@@ -302,25 +316,29 @@ def overall_test_report(ecs_with_res, orig_cnt, success, msg, init_session_state
302316
"""
303317
dump_path = build_option('dump_test_report')
304318
pr_nr = build_option('from_pr')
319+
eb_pr_nr = build_option('include_easyblocks_from_pr')
305320
upload = build_option('upload_test_report')
306321

307322
if upload:
308-
msg = msg + " (%d easyconfigs in this PR)" % orig_cnt
323+
msg = msg + " (%d easyconfigs in total)" % orig_cnt
309324
test_report = create_test_report(msg, ecs_with_res, init_session_state, pr_nr=pr_nr, gist_log=True)
310325
if pr_nr:
311326
# upload test report to gist and issue a comment in the PR to notify
312-
txt = post_easyconfigs_pr_test_report(pr_nr, test_report, msg, init_session_state, success)
327+
txt = post_pr_test_report(pr_nr, GITHUB_EASYCONFIGS_REPO, test_report, msg, init_session_state, success)
328+
elif eb_pr_nr:
329+
# upload test report to gist and issue a comment in the easyblocks PR to notify
330+
txt = post_pr_test_report(eb_pr_nr, GITHUB_EASYBLOCKS_REPO, test_report, msg, init_session_state, success)
313331
else:
314332
# only upload test report as a gist
315-
gist_url = upload_test_report_as_gist(test_report)
333+
gist_url = upload_test_report_as_gist(test_report['full'])
316334
txt = "Test report uploaded to %s" % gist_url
317335
else:
318336
test_report = create_test_report(msg, ecs_with_res, init_session_state)
319337
txt = None
320-
_log.debug("Test report: %s" % test_report)
338+
_log.debug("Test report: %s" % test_report['full'])
321339

322340
if dump_path is not None:
323-
write_file(dump_path, test_report)
341+
write_file(dump_path, test_report['full'])
324342
_log.info("Test report dumped to %s" % dump_path)
325343

326344
return txt

test/framework/github.py

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
from easybuild.tools.configobj import ConfigObj
4444
from easybuild.tools.filetools import read_file, write_file
4545
from easybuild.tools.github import VALID_CLOSE_PR_REASONS
46-
from easybuild.tools.testing import post_easyconfigs_pr_test_report, session_state
46+
from easybuild.tools.testing import post_pr_test_report, session_state
4747
from easybuild.tools.py2vs3 import HTTPError, URLError, ascii_letters
4848
import easybuild.tools.github as gh
4949

@@ -828,25 +828,24 @@ def test_push_branch_to_github(self):
828828
regex = re.compile(pattern)
829829
self.assertTrue(regex.match(stdout.strip()), "Pattern '%s' doesn't match: %s" % (regex.pattern, stdout))
830830

831-
def test_post_easyconfigs_pr_test_report(self):
832-
"""Test for post_easyconfigs_pr_test_report function."""
831+
def test_pr_test_report(self):
832+
"""Test for post_pr_test_report function."""
833833
if self.skip_github_tests:
834-
print("Skipping test_post_easyconfigs_pr_test_report, no GitHub token available?")
834+
print("Skipping test_post_pr_test_report, no GitHub token available?")
835835
return
836836

837837
init_config(build_options={
838838
'dry_run': True,
839839
'github_user': GITHUB_TEST_ACCOUNT,
840840
})
841841

842-
test_report = os.path.join(self.test_prefix, 'test_report.txt')
843-
write_file(test_report, "This is a test report!")
842+
test_report = {'full': "This is a test report!"}
844843

845844
init_session_state = session_state()
846845

847846
self.mock_stderr(True)
848847
self.mock_stdout(True)
849-
post_easyconfigs_pr_test_report('1234', test_report, "OK!", init_session_state, True)
848+
post_pr_test_report('1234', gh.GITHUB_EASYCONFIGS_REPO, test_report, "OK!", init_session_state, True)
850849
stderr, stdout = self.get_stderr(), self.get_stdout()
851850
self.mock_stderr(False)
852851
self.mock_stdout(False)
@@ -861,6 +860,23 @@ def test_post_easyconfigs_pr_test_report(self):
861860
regex = re.compile(pattern, re.M)
862861
self.assertTrue(regex.search(stdout), "Pattern '%s' should be found in: %s" % (regex.pattern, stdout))
863862

863+
self.mock_stderr(True)
864+
self.mock_stdout(True)
865+
post_pr_test_report('1234', gh.GITHUB_EASYBLOCKS_REPO, test_report, "OK!", init_session_state, True)
866+
stderr, stdout = self.get_stderr(), self.get_stdout()
867+
self.mock_stderr(False)
868+
self.mock_stdout(False)
869+
870+
self.assertEqual(stderr, '')
871+
872+
patterns = [
873+
r"^\[DRY RUN\] Adding comment to easybuild-easyblocks issue #1234: 'Test report by @easybuild_test",
874+
r"^See https://gist.github.com/DRY_RUN for a full test report.'",
875+
]
876+
for pattern in patterns:
877+
regex = re.compile(pattern, re.M)
878+
self.assertTrue(regex.search(stdout), "Pattern '%s' should be found in: %s" % (regex.pattern, stdout))
879+
864880

865881
def suite():
866882
""" returns all the testcases in this module """

0 commit comments

Comments
 (0)