From 8b9c4d47488158f8661f7c028808b8fcee11ee7d Mon Sep 17 00:00:00 2001 From: Igor Davydenko Date: Tue, 20 Dec 2022 20:47:06 +0100 Subject: [PATCH] refactor(ci)!: Change output at GitHub Actions To not use `::set-output ...` echoing into stdout in favor of writing to file from `GITHUB_OUTPUT` env var. Fixes: #185 --- src/badabump/cli/output.py | 9 +++++---- tests/conftest.py | 20 +++++++++++++++++--- tests/test_ci_cli.py | 29 +++++++++++++++++------------ tests/test_cli.py | 9 ++++++--- tests/test_cli_output.py | 16 +++++++++++----- 5 files changed, 56 insertions(+), 27 deletions(-) diff --git a/src/badabump/cli/output.py b/src/badabump/cli/output.py index ed57729..646e538 100644 --- a/src/badabump/cli/output.py +++ b/src/badabump/cli/output.py @@ -1,9 +1,9 @@ +import os from difflib import ndiff from typing import Union EMPTY = "-" -VALUE_ESCAPE_MAPPING = (("%", "%25"), ("\n", "%0A"), ("\r", "%0D")) def diff(current_content: str, next_content: str) -> str: @@ -33,6 +33,7 @@ def echo_value( def github_actions_output(name: str, value: str) -> None: - for symbol, code in VALUE_ESCAPE_MAPPING: - value = value.replace(symbol, code) - print(f"::set-output name={name}::{value}") + with open(os.environ["GITHUB_OUTPUT"], "a+") as github_output_handler: + github_output_handler.write(f"{name}< None: subprocess.check_call(["git", "add", "."], cwd=path) @@ -20,7 +26,7 @@ def factory(path: Path, commit: str) -> None: return factory -@pytest.fixture() +@pytest.fixture(scope="function") def create_git_repository(tmpdir, create_git_commit, create_git_tag): def factory(*commits: CommitTuple, tag: TagTuple = None) -> Git: path = Path(tmpdir) @@ -39,7 +45,7 @@ def factory(*commits: CommitTuple, tag: TagTuple = None) -> Git: return factory -@pytest.fixture() +@pytest.fixture(scope="function") def create_git_tag(): def factory(path: Path, tag: str, message: str) -> None: subprocess.check_call( @@ -47,3 +53,11 @@ def factory(path: Path, tag: str, message: str) -> None: ) return factory + + +@pytest.fixture(scope="function") +def github_output_path(tmp_path) -> Path: + path = Path(tmp_path) / "github-output.txt" + if not path.exists(): + path.write_text("") + return path diff --git a/tests/test_ci_cli.py b/tests/test_ci_cli.py index 7aace7e..46d26f7 100644 --- a/tests/test_ci_cli.py +++ b/tests/test_ci_cli.py @@ -45,20 +45,23 @@ def test_invalid_subcommand(): @pytest.mark.parametrize("ref", (("v20.1.0", "refs/tags/v20.1.0"))) -def test_prepare_release(capsys, prepare_repository_for_release, ref): +def test_prepare_release( + capsys, github_output_path, prepare_repository_for_release, ref +): path = prepare_repository_for_release() assert main(["-C", str(path), "prepare_release", ref]) == 0 captured = capsys.readouterr() + assert captured.out == "" assert captured.err == "" - assert "::set-output name=tag_name::v20.1.0" - assert "::set-output name=is_pre_release::false" in captured.out - assert "::set-output name=release_name::20.1.0 Release" in captured.out + github_output = github_output_path.read_text() + assert "tag_name<