-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
restore CI output group folding in github actions (#38167)
* restore CI output group folding in github actions See official docs for details: https://docs.github.com/en/actions/using-workflows/ workflow-commands-for-github-actions#grouping-log-lines * CI fold for both GHA and travis * bugfixes * ci: fix fold: add newline before fold start * remove travis from ci folding * allow multi-level inheritance for ci fold classes
- Loading branch information
1 parent
27c8a70
commit b9dadc2
Showing
1 changed file
with
53 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,65 @@ | ||
import itertools | ||
import os | ||
import typing | ||
|
||
next_block_id = 1 | ||
|
||
|
||
class Fold(object): | ||
class BaseCiCfg: | ||
_block_id_gen = itertools.count(1) | ||
|
||
def __init__(self): | ||
global next_block_id | ||
self.block_id = next_block_id | ||
next_block_id += 1 | ||
|
||
def get_message(self, msg=''): | ||
if os.environ.get('TRAVIS') == 'true': | ||
if msg: | ||
msg += ', ' | ||
msg += "see folded block '%s' above for details" % self.get_block_name() | ||
self.block_id = next(self._block_id_gen) | ||
|
||
@classmethod | ||
def is_ci(cls) -> bool: | ||
raise NotImplementedError("Use BaseCiCfg only as fallback") | ||
|
||
def get_message(self, msg: str = "") -> str: | ||
return msg | ||
|
||
def _get_message_folded(self, msg: str = "") -> str: | ||
if msg: | ||
msg += ", " | ||
msg += "see folded block '%s' above for details" % self.get_block_name() | ||
return msg | ||
|
||
def get_block_name(self): | ||
return 'block%d' % self.block_id | ||
def get_block_name(self) -> str: | ||
return "block%d" % self.block_id | ||
|
||
def __enter__(self): | ||
return self | ||
|
||
def __exit__(self, type, value, traceback): | ||
pass | ||
|
||
|
||
class GithubActionsCiCfg(BaseCiCfg): | ||
@classmethod | ||
def is_ci(cls) -> bool: | ||
return os.environ.get("GITHUB_ACTIONS") == "true" | ||
|
||
def get_message(self, msg=""): | ||
return self._get_message_folded(msg) | ||
|
||
def __enter__(self): | ||
if os.environ.get('TRAVIS') == 'true': | ||
print('travis_fold:start:%s' % self.get_block_name()) | ||
print("\n::group::%s" % self.get_block_name()) | ||
return self | ||
|
||
def __exit__(self, type, value, traceback): | ||
if os.environ.get('TRAVIS') == 'true': | ||
print('travis_fold:end:%s' % self.get_block_name()) | ||
print("\n::endgroup::") | ||
|
||
|
||
# determine CI system, and set as Fold | ||
def _determine_ci_system() -> typing.Type[BaseCiCfg]: | ||
def visitor(cls: typing.Type[BaseCiCfg]) -> typing.Optional[typing.Type[BaseCiCfg]]: | ||
for sub in cls.__subclasses__(): | ||
if sub.is_ci(): | ||
return sub | ||
res = visitor(sub) | ||
if res: | ||
return res | ||
return None | ||
|
||
return visitor(BaseCiCfg) or BaseCiCfg | ||
|
||
|
||
Fold = _determine_ci_system() |