Skip to content

Commit

Permalink
[BUG] Unable to output (#460)
Browse files Browse the repository at this point in the history
* force string for output

* Revert "force string for output"

This reverts commit cabecb9.

* force string output

* use with print

* convert to single line

* not join \n

* 2 depreciation I forget last time

* add assert for set_actions_output
Co-authored-by: Frank Harkins <[email protected]>

* comment changes
  • Loading branch information
mickahell authored Jul 29, 2023
1 parent 7366590 commit ad90b34
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 9 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ecosystem-batch-repo-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ecosystem-main_repos_fetch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions ecosystem/runners/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
]
)

Expand Down
1 change: 1 addition & 0 deletions ecosystem/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions ecosystem/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
31 changes: 29 additions & 2 deletions tests/utils/test_utils.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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:
Expand All @@ -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!
""",
)
]
)

0 comments on commit ad90b34

Please sign in to comment.