Skip to content

Commit

Permalink
Print "::endgroup::" when finished processing all dependencies
Browse files Browse the repository at this point in the history
Otherwise the next commands will be grouped under the last group.
  • Loading branch information
nicoddemus committed Feb 29, 2024
1 parent 639ef22 commit 6f9a1b2
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 29 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
1.3.1 (2024-02-29)
------------------

* Fix grouping under GitHub actions: print without colors, otherwise the ``::group::`` instructions are not processed.
* When running under GitHub actions, print the ``::endgroup::`` prefix when finishing processing.


1.3.0 (2024-02-28)
------------------

Expand Down
19 changes: 11 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
Deps
====
# Deps

[![link](https://img.shields.io/conda/vn/conda-forge/deps.svg)](https://anaconda.org/conda-forge/deps)
[![link](https://github.com/ESSS/deps/workflows/build/badge.svg)](https://github.com/ESSS/deps/actions)
Expand All @@ -11,8 +10,7 @@ It is meant to be used along with `conda devenv`: https://github.com/ESSS/conda-
it reads the contents of the `includes` sections of `environment.devenv.yml`, which contains
the relative paths of the dependencies where commands should be executed.

Examples
=========
# Examples

`deps inv codegen` will run `inv codegen` on the projects and its dependencies sequentially, respecting dependencies.

Expand All @@ -22,8 +20,14 @@ but respecting dependencies (so, it'll only run in parallel commands after their
`deps inv codegen -j 16 --jobs-unordered` will run `inv codegen` on the projects and its dependencies
with full-paralelization, without respecting any particular order.

Usage
=====
## GitHub Actions

Since version `1.3.1`, `deps` will automatically print `::group::` and `::endgroup::` markers when running in GitHub actions, which makes for better experience when visualizing the logs.

It detects this by the presence of the `GITHUB_WORKSPACE` environment variable.


# Usage

Program to list development dependencies of `conda-devenv` projects, or to execute a command for each dependency:

Expand Down Expand Up @@ -135,7 +139,6 @@ Options Description:

Show this message and exit.

License
========
# License

Free software: MIT license
2 changes: 2 additions & 0 deletions source/python/deps/_tests/test_deps_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ def test_execution_on_project_dir(cli_runner, project_tree, monkeypatch, on_gith
"deps: return code: 0",
]
)
if on_github:
matcher.fnmatch_lines("::endgroup::")


def test_here_flag(cli_runner, project_tree, monkeypatch):
Expand Down
50 changes: 29 additions & 21 deletions source/python/deps/deps_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,12 +523,8 @@ def execute_command_in_dependencies(
error_messages = []
initial = [x.name for x in dependencies]
buffer_output = False
if "GITHUB_WORKSPACE" in os.environ:
prefix = "::group::"
output_separator = "\n"
else:
prefix = ""
output_separator = "\n" + "=" * MAX_LINE_LENGTH
on_github = "GITHUB_WORKSPACE" in os.environ
output_separator = "" if on_github else "\n" + "=" * MAX_LINE_LENGTH

if jobs > 1:
buffer_output = True
Expand Down Expand Up @@ -595,24 +591,30 @@ def calculate_next_batch(dependencies):

# Checks before execution.
if dep.ignored:
click.secho(
prefix + dep.name,
fg="blue",
bold=True,
color=_click_echo_color,
nl=False,
)
if on_github:
click.secho(f"::group::{dep.name}", nl=False)
else:
click.secho(
dep.name,
fg="blue",
bold=True,
color=_click_echo_color,
nl=False,
)
click.secho(" ignored", fg="yellow", color=_click_echo_color)
continue

if dep.skipped:
click.secho(
prefix + dep.name,
fg="blue",
bold=True,
color=_click_echo_color,
nl=False,
)
if on_github:
click.secho(f"::group::{dep.name}", nl=False)
else:
click.secho(
dep.name,
fg="blue",
bold=True,
color=_click_echo_color,
nl=False,
)
click.secho(" skipped", fg="magenta", color=_click_echo_color)
continue

Expand All @@ -627,7 +629,10 @@ def calculate_next_batch(dependencies):

if len(deps) == 1 or first:
msg = "%s (%d/%d)" % (print_str, progress, total_progress)
click.secho(prefix + msg, fg="blue", bold=True, color=_click_echo_color)
if on_github:
click.secho(f"::group::{msg}")
else:
click.secho(msg, fg="blue", bold=True, color=_click_echo_color)
if verbose or dry_run:
command_to_print = " ".join(
arg.replace(" ", "\\ ") for arg in formatted_command
Expand Down Expand Up @@ -713,6 +718,9 @@ def calculate_next_batch(dependencies):
for msg in error_messages:
echo_error(msg)

if on_github:
click.secho("::endgroup::")

return exit_codes


Expand Down

0 comments on commit 6f9a1b2

Please sign in to comment.