Skip to content
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

Grouping of log lines emitted by chartpress when running inside a GitHub workflow #130

Open
consideRatio opened this issue Jul 17, 2021 · 0 comments
Labels
enhancement New feature or request

Comments

@consideRatio
Copy link
Member

Proposed change

GitHub Actions provide some features to help tools present nicer logs, one of those features are groups (of lines). This is described in the GitHub Workflow Commands reference.

This is how it can look when a single build step built loads of docker files with loads of logs in each. It was somewhat readable still thanks to the grouping. But, with chartpress currently, we don't have such grouping.

image

Implementation idea

We wrap work to be done for example, to build or push an image, inside a with _gwc_group(f"Building {image}"): scope using the example code below. Note that it checks for if GITHUB_ACTIONS is set or not, that is the indication that we are inside a GitHub actions runner.

import json
from contextlib import contextmanager


def _gwc(command_name, command_value="", **params):
    if not os.environ.get("GITHUB_ACTIONS"):
        return
    # Assume non-string values are meant to be dumped as JSON
    if not isinstance(command_value, str):
        command_value = json.dumps(command_value)
        print(f"dumped json: {command_value}")
    if params:
        comma_sep_params = ",".join([f"{k}={v}" for k, v in params.items()])
        print(f"::{command_name} {comma_sep_params}::{command_value}")
    else:
        print(f"::{command_name}::{command_value}")


@contextmanager
def _gwc_group(group_name):
    """
    Entering the context prints the group command, and exiting the context
    prints the endgroup command.<<
    """
    try:
        yield _gwc("group", group_name)
    finally:
        _gwc("endgroup", group_name)
@consideRatio consideRatio added the enhancement New feature or request label Jul 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant