-
Notifications
You must be signed in to change notification settings - Fork 294
feat: add summary to Action #2469
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
013a7cc
chore: add summary to Action
henryiii 35a6c7a
refactor: new summary table
henryiii 36fc0d2
fix: fixup tests and formatting
henryiii 94f1cb0
fix: pyodide missing some logging
henryiii d3990bd
fix: nicer printout, nicer in-place summary
henryiii 18927e4
fix: use summary for everything
henryiii dc25a28
fix: support only one output wheel from repair
henryiii 1cb91f4
Add new Github summary format
joerick 8e68576
Remove a couple of humanize uses
joerick ed81f3f
Merge remote-tracking branch 'origin/main' into henryiii/chore/GHAsum…
joerick 6a81d70
fix: filter ANSI codes in summary
henryiii 764f8b6
fix: add sha256
henryiii 741429a
fix: nicer wheel/wheels depending on how many are present
henryiii ddf7f18
Merge branch 'main' into henryiii/chore/GHAsummary
henryiii File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,11 +1,24 @@ | ||||||
| import codecs | ||||||
| import contextlib | ||||||
| import dataclasses | ||||||
| import functools | ||||||
| import hashlib | ||||||
| import io | ||||||
| import os | ||||||
| import re | ||||||
| import sys | ||||||
| import textwrap | ||||||
| import time | ||||||
| from typing import IO, AnyStr, Final, Literal | ||||||
| from collections.abc import Generator | ||||||
| from pathlib import Path | ||||||
| from typing import IO, TYPE_CHECKING, AnyStr, Final, Literal | ||||||
|
|
||||||
| from .ci import CIProvider, detect_ci_provider | ||||||
| import humanize | ||||||
|
|
||||||
| from .ci import CIProvider, detect_ci_provider, filter_ansi_codes | ||||||
|
|
||||||
| if TYPE_CHECKING: | ||||||
| from .options import Options | ||||||
|
|
||||||
| FoldPattern = tuple[str, str] | ||||||
| DEFAULT_FOLD_PATTERN: Final[FoldPattern] = ("{name}", "") | ||||||
|
|
@@ -69,6 +82,33 @@ def __init__(self, *, unicode: bool) -> None: | |||||
| self.error = "✕" if unicode else "failed" | ||||||
|
|
||||||
|
|
||||||
| @dataclasses.dataclass(kw_only=True, frozen=True) | ||||||
| class BuildInfo: | ||||||
| identifier: str | ||||||
| filename: Path | None | ||||||
| duration: float | ||||||
|
|
||||||
| @functools.cached_property | ||||||
| def size(self) -> str | None: | ||||||
| if self.filename is None: | ||||||
| return None | ||||||
| return humanize.naturalsize(self.filename.stat().st_size) | ||||||
|
|
||||||
| @functools.cached_property | ||||||
| def sha256(self) -> str | None: | ||||||
| if self.filename is None: | ||||||
| return None | ||||||
| with self.filename.open("rb") as f: | ||||||
| digest = hashlib.file_digest(f, "sha256") | ||||||
| return digest.hexdigest() | ||||||
|
|
||||||
| def __str__(self) -> str: | ||||||
| duration = humanize.naturaldelta(self.duration) | ||||||
| if self.filename: | ||||||
| return f"{self.identifier}: {self.filename.name} {self.size} in {duration}, SHA256={self.sha256}" | ||||||
| return f"{self.identifier}: {duration} (test only)" | ||||||
|
|
||||||
|
|
||||||
| class Logger: | ||||||
| fold_mode: Literal["azure", "github", "travis", "disabled"] | ||||||
| colors_enabled: bool | ||||||
|
|
@@ -77,6 +117,7 @@ class Logger: | |||||
| build_start_time: float | None = None | ||||||
| step_start_time: float | None = None | ||||||
| active_fold_group_name: str | None = None | ||||||
| summary: list[BuildInfo] | ||||||
|
|
||||||
| def __init__(self) -> None: | ||||||
| if sys.platform == "win32" and hasattr(sys.stdout, "reconfigure"): | ||||||
|
|
@@ -88,25 +129,28 @@ def __init__(self) -> None: | |||||
|
|
||||||
| ci_provider = detect_ci_provider() | ||||||
|
|
||||||
| if ci_provider == CIProvider.azure_pipelines: | ||||||
| self.fold_mode = "azure" | ||||||
| self.colors_enabled = True | ||||||
| match ci_provider: | ||||||
| case CIProvider.azure_pipelines: | ||||||
| self.fold_mode = "azure" | ||||||
| self.colors_enabled = True | ||||||
|
|
||||||
| elif ci_provider == CIProvider.github_actions: | ||||||
| self.fold_mode = "github" | ||||||
| self.colors_enabled = True | ||||||
| case CIProvider.github_actions: | ||||||
| self.fold_mode = "github" | ||||||
| self.colors_enabled = True | ||||||
|
|
||||||
| elif ci_provider == CIProvider.travis_ci: | ||||||
| self.fold_mode = "travis" | ||||||
| self.colors_enabled = True | ||||||
| case CIProvider.travis_ci: | ||||||
| self.fold_mode = "travis" | ||||||
| self.colors_enabled = True | ||||||
|
|
||||||
| elif ci_provider == CIProvider.appveyor: | ||||||
| self.fold_mode = "disabled" | ||||||
| self.colors_enabled = True | ||||||
| case CIProvider.appveyor: | ||||||
| self.fold_mode = "disabled" | ||||||
| self.colors_enabled = True | ||||||
|
|
||||||
| else: | ||||||
| self.fold_mode = "disabled" | ||||||
| self.colors_enabled = file_supports_color(sys.stdout) | ||||||
| case _: | ||||||
| self.fold_mode = "disabled" | ||||||
| self.colors_enabled = file_supports_color(sys.stdout) | ||||||
|
|
||||||
| self.summary = [] | ||||||
|
|
||||||
| def build_start(self, identifier: str) -> None: | ||||||
| self.step_end() | ||||||
|
|
@@ -120,19 +164,22 @@ def build_start(self, identifier: str) -> None: | |||||
| self.build_start_time = time.time() | ||||||
| self.active_build_identifier = identifier | ||||||
|
|
||||||
| def build_end(self) -> None: | ||||||
| def build_end(self, filename: Path | None) -> None: | ||||||
| assert self.build_start_time is not None | ||||||
| assert self.active_build_identifier is not None | ||||||
| self.step_end() | ||||||
|
|
||||||
| c = self.colors | ||||||
| s = self.symbols | ||||||
| duration = time.time() - self.build_start_time | ||||||
| duration_str = humanize.naturaldelta(duration, minimum_unit="milliseconds") | ||||||
|
|
||||||
| print() | ||||||
| print( | ||||||
| f"{c.green}{s.done} {c.end}{self.active_build_identifier} finished in {duration:.2f}s" | ||||||
| print(f"{c.green}{s.done} {c.end}{self.active_build_identifier} finished in {duration_str}") | ||||||
| self.summary.append( | ||||||
| BuildInfo(identifier=self.active_build_identifier, filename=filename, duration=duration) | ||||||
| ) | ||||||
|
|
||||||
| self.build_start_time = None | ||||||
| self.active_build_identifier = None | ||||||
|
|
||||||
|
|
@@ -147,6 +194,7 @@ def step_end(self, success: bool = True) -> None: | |||||
| c = self.colors | ||||||
| s = self.symbols | ||||||
| duration = time.time() - self.step_start_time | ||||||
|
|
||||||
| if success: | ||||||
| print(f"{c.green}{s.done} {c.end}{duration:.2f}s".rjust(78)) | ||||||
| else: | ||||||
|
|
@@ -183,6 +231,26 @@ def error(self, error: BaseException | str) -> None: | |||||
| c = self.colors | ||||||
| print(f"cibuildwheel: {c.bright_red}error{c.end}: {error}\n", file=sys.stderr) | ||||||
|
|
||||||
| @contextlib.contextmanager | ||||||
| def print_summary(self, *, options: "Options") -> Generator[None, None, None]: | ||||||
| start = time.time() | ||||||
| yield | ||||||
| duration = time.time() - start | ||||||
| if summary_path := os.environ.get("GITHUB_STEP_SUMMARY"): | ||||||
| github_summary = self._github_step_summary(duration=duration, options=options) | ||||||
| Path(summary_path).write_text(filter_ansi_codes(github_summary), encoding="utf-8") | ||||||
|
|
||||||
| n = len(self.summary) | ||||||
| s = "s" if n > 1 else "" | ||||||
| duration_str = humanize.naturaldelta(duration) | ||||||
| print() | ||||||
| self._start_fold_group(f"{n} wheel{s} produced in {duration_str}") | ||||||
| for build_info in self.summary: | ||||||
| print(" ", build_info) | ||||||
| self._end_fold_group() | ||||||
|
|
||||||
| self.summary = [] | ||||||
|
|
||||||
| @property | ||||||
| def step_active(self) -> bool: | ||||||
| return self.step_start_time is not None | ||||||
|
|
@@ -222,6 +290,72 @@ def _fold_group_identifier(name: str) -> str: | |||||
| # lowercase, shorten | ||||||
| return identifier.lower()[:20] | ||||||
|
|
||||||
| def _github_step_summary(self, duration: float, options: "Options") -> str: | ||||||
| """ | ||||||
| Returns the GitHub step summary, in markdown format. | ||||||
| """ | ||||||
| out = io.StringIO() | ||||||
| options_summary = options.summary( | ||||||
| identifiers=[bi.identifier for bi in self.summary], skip_unset=True | ||||||
| ) | ||||||
| out.write( | ||||||
| textwrap.dedent("""\ | ||||||
| ### 🎡 cibuildwheel | ||||||
|
|
||||||
| <details> | ||||||
| <summary> | ||||||
| Build options | ||||||
| </summary> | ||||||
|
|
||||||
| ```yaml | ||||||
| {options_summary} | ||||||
| ``` | ||||||
|
|
||||||
| </details> | ||||||
|
|
||||||
| """).format(options_summary=options_summary) | ||||||
| ) | ||||||
| n_wheels = len([b for b in self.summary if b.filename]) | ||||||
| wheel_rows = "\n".join( | ||||||
| "<tr>" | ||||||
| f"<td nowrap>{'<samp>' + b.filename.name + '</samp>' if b.filename else '*Build only*'}</td>" | ||||||
| f"<td nowrap>{b.size or 'N/A'}</td>" | ||||||
| f"<td nowrap><samp>{b.identifier}</samp></td>" | ||||||
| f"<td nowrap>{humanize.naturaldelta(b.duration)}</td>" | ||||||
| f"<td nowrap><samp>{b.sha256 or 'N/A'}</samp></td>" | ||||||
| "</tr>" | ||||||
| for b in self.summary | ||||||
| ) | ||||||
| out.write( | ||||||
| textwrap.dedent("""\ | ||||||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can use
Suggested change
|
||||||
| <table> | ||||||
| <thead> | ||||||
| <tr> | ||||||
| <th align="left">Wheel</th> | ||||||
| <th align="left">Size</th> | ||||||
| <th align="left">Build identifier</th> | ||||||
| <th align="left">Time</th> | ||||||
| <th align="left">SHA256</th> | ||||||
| </tr> | ||||||
| </thead> | ||||||
| <tbody> | ||||||
| {wheel_rows} | ||||||
| </tbody> | ||||||
| </table> | ||||||
| <div align="right"><sup>{n} wheel{s} created in {duration_str}</sup></div> | ||||||
| """).format( | ||||||
| wheel_rows=wheel_rows, | ||||||
| n=n_wheels, | ||||||
| duration_str=humanize.naturaldelta(duration), | ||||||
| s="s" if n_wheels > 1 else "", | ||||||
| ) | ||||||
| ) | ||||||
|
|
||||||
| out.write("\n") | ||||||
| out.write("---") | ||||||
| out.write("\n") | ||||||
| return out.getvalue() | ||||||
|
|
||||||
| @property | ||||||
| def colors(self) -> Colors: | ||||||
| return Colors(enabled=self.colors_enabled) | ||||||
|
|
||||||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.