diff --git a/.github/workflows/ecosystem-batch-repo-check.yml b/.github/workflows/ecosystem-batch-repo-check.yml index dc5fa08559..e9f262af08 100644 --- a/.github/workflows/ecosystem-batch-repo-check.yml +++ b/.github/workflows/ecosystem-batch-repo-check.yml @@ -12,8 +12,8 @@ jobs: - name: Setup variables id: vars run: | - echo "::set-output name=datetime::$(date +'%Y_%m_%d_%H_%M')" - echo "::set-output name=pr_branch_name::batch_checks_$(date +'%Y_%m_%d_%H_%M')" + echo "datetime=$(date +'%Y_%m_%d_%H_%M')" >> "$GITHUB_OUTPUT" + echo "pr_branch_name=batch_checks_$(date +'%Y_%m_%d_%H_%M')" >> "$GITHUB_OUTPUT" - uses: actions/checkout@v3 - name: Set up Python 3.9 uses: actions/setup-python@v4 diff --git a/.github/workflows/ecosystem-main_repos_fetch.yml b/.github/workflows/ecosystem-main_repos_fetch.yml index 4403f4185b..e8b919bab7 100644 --- a/.github/workflows/ecosystem-main_repos_fetch.yml +++ b/.github/workflows/ecosystem-main_repos_fetch.yml @@ -15,8 +15,8 @@ jobs: - name: Setup variables id: vars run: | - echo "::set-output name=datetime::$(date +'%Y_%m_%d_%H_%M')" - echo "::set-output name=pr_branch_name::fetch_tests_for_main_$(date +'%Y_%m_%d_%H_%M')" + echo "datetime=$(date +'%Y_%m_%d_%H_%M')" >> "$GITHUB_OUTPUT" + echo "pr_branch_name=fetch_tests_for_main_$(date +'%Y_%m_%d_%H_%M')" >> "$GITHUB_OUTPUT" - uses: actions/checkout@v3 - name: Set up Python ${{ env.python-version }} uses: actions/setup-python@v4 diff --git a/ecosystem/runners/runner.py b/ecosystem/runners/runner.py index 9444ca5b7e..59acd2d691 100644 --- a/ecosystem/runners/runner.py +++ b/ecosystem/runners/runner.py @@ -163,9 +163,9 @@ def run(self) -> Tuple[str, List[CommandExecutionSummary]]: logs_fail += element.get_fail_logs() set_actions_output( [ - ("DEPRECIATION", "\n".join(logs_depreciation)), - ("ERROR", "\n".join(logs_error)), - ("FAIL", "\n".join(logs_fail)), + ("DEPRECIATION", " ".join(logs_depreciation)), + ("ERROR", " ".join(logs_error)), + ("FAIL", " ".join(logs_fail)), ] ) diff --git a/ecosystem/utils/__init__.py b/ecosystem/utils/__init__.py index 542b29fb9d..c416c61357 100644 --- a/ecosystem/utils/__init__.py +++ b/ecosystem/utils/__init__.py @@ -1,5 +1,6 @@ """Utility functions and classes.""" from .utils import logger +from .utils import set_actions_output from .utils import OneLineExceptionFormatter from .submission_parser import parse_submission_issue diff --git a/ecosystem/utils/utils.py b/ecosystem/utils/utils.py index 189415700d..0e3cfa9364 100644 --- a/ecosystem/utils/utils.py +++ b/ecosystem/utils/utils.py @@ -38,6 +38,8 @@ def set_actions_output(outputs: List[Tuple[str, Union[str, bool, float, int]]]) """ for name, value in outputs: logger.info("Setting output variable %s: %s", name, value) + if value is not None: + assert "\n" not in value, f"Error: Newlines in github output ({value})" if "CI" in os.environ: with open(os.environ["GITHUB_OUTPUT"], "a") as github_env: github_env.write(f"{name}={value}\n") diff --git a/tests/utils/test_utils.py b/tests/utils/test_utils.py index 723e8bd7de..58ae2890ba 100644 --- a/tests/utils/test_utils.py +++ b/tests/utils/test_utils.py @@ -1,9 +1,11 @@ """Tests for manager.""" import os +import io from unittest import TestCase +from contextlib import redirect_stdout from ecosystem.models.repository import Repository -from ecosystem.utils import parse_submission_issue +from ecosystem.utils import parse_submission_issue, set_actions_output class TestUtils(TestCase): @@ -17,7 +19,7 @@ def setUp(self) -> None: self.issue_body = issue_body_file.read() def test_issue_parsing(self): - """ "Tests issue parsing function: + """Tests issue parsing function: Function: -> parse_submission_issue Args: @@ -40,3 +42,28 @@ def test_issue_parsing(self): self.assertEqual( parsed_result.labels, ["tool", "tutorial", "paper implementation"] ) + + def test_set_actions_output(self): + """Test set actions output.""" + # Test ok -> ok + captured_output = io.StringIO() + with redirect_stdout(captured_output): + set_actions_output([("success", "this test is a success case!")]) + output_value = captured_output.getvalue() + self.assertEqual(output_value, "success=this test is a success case!\n") + + # Test ok -> ko + with self.assertRaises(AssertionError): + set_actions_output( + [ + ( + "fail", + """ + this test is a failed case, + why ? + because it's a multi-lines output + and GITHUB_OUTPUT doesn't like that! + """, + ) + ] + )