From 4df06021579ce2908495c74be3484725fb16ccf7 Mon Sep 17 00:00:00 2001 From: emil Date: Thu, 25 Jun 2026 17:12:20 +0000 Subject: [PATCH] DEVX-48: fix: use heredoc syntax for multi-line $GITHUB_ENV values --- src/devx/ci/distribute_files.py | 7 ++++++- tests/unit/test_distribute_files.py | 17 +++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/devx/ci/distribute_files.py b/src/devx/ci/distribute_files.py index 3451967..5b60884 100644 --- a/src/devx/ci/distribute_files.py +++ b/src/devx/ci/distribute_files.py @@ -55,7 +55,12 @@ def _write_github_env(key: str, value: str) -> None: if not gh_env: raise click.ClickException("GITHUB_ENV environment variable is not set") with open(gh_env, "a") as f: # noqa: PTH123 - f.write(f"{key}={value}\n") + if "\n" in value: + # Multi-line values require the heredoc syntax in $GITHUB_ENV. + delimiter = "EOF" + f.write(f"{key}<<{delimiter}\n{value}\n{delimiter}\n") + else: + f.write(f"{key}={value}\n") @click.command() diff --git a/tests/unit/test_distribute_files.py b/tests/unit/test_distribute_files.py index 435c12a..cd959b1 100644 --- a/tests/unit/test_distribute_files.py +++ b/tests/unit/test_distribute_files.py @@ -101,6 +101,23 @@ class TestCli: assert "ASSIGNED_FILES=" in content assert "SKIP=false" in content + def test_github_env_multiline_uses_heredoc(self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None: + gh_file = tmp_path / "env.txt" + monkeypatch.setenv("GITHUB_ENV", str(gh_file)) + for i in range(6): + (tmp_path / f"test_{i}.py").write_text("") + runner = CliRunner() + result = runner.invoke( + main, + ["--pattern", str(tmp_path / "test_*.py"), "--runner-index", "1", "--max-runners", "2", "--github-env"], + ) + assert result.exit_code == 0 + content = gh_file.read_text() + # Multi-line values must use heredoc syntax to avoid corrupting $GITHUB_ENV + assert "ASSIGNED_FILES<= 2 + assert "SKIP=false" in content + def test_skip_if_excess(self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None: gh_file = tmp_path / "env.txt" monkeypatch.setenv("GITHUB_ENV", str(gh_file))