Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions launchable/commands/gate.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import json
import os
import sys
import uuid
from http import HTTPStatus

import click
Expand Down Expand Up @@ -87,6 +86,10 @@ def _escape_github_actions_command_value(value: str) -> str:
return value.replace('\r', '%0D').replace('\n', '%0A')


def _escape_github_actions_log_line(line: str) -> str:
return line.replace('::', '%3A%3A', 1) if line.startswith('::') else line


def display_as_json(res: Response):
res_json = res.json()
click.echo(json.dumps(res_json, indent=2))
Expand Down Expand Up @@ -115,13 +118,10 @@ def display_as_table(res: Response):
stderr = (test.get("stderr") or "").strip()
if is_github_actions:
safe_test_path = _escape_github_actions_command_value(test_path)
token = uuid.uuid4().hex
click.echo("::group::{}. {}".format(i, safe_test_path))
click.echo("::stop-commands::{}".format(token))
if stderr:
for line in stderr.splitlines():
click.echo(line)
click.echo("::{}::".format(token))
click.echo(_escape_github_actions_log_line(line))
click.echo("::endgroup::")
else:
click.echo("{}. {}".format(i, test_path))
Expand Down
29 changes: 9 additions & 20 deletions tests/commands/test_gate.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ def test_gate_failed_github_actions_format(self):
result = self.cli('gate', '--session', self.session)
self.assert_exit_code(result, 1)
self.assertIn('::group::1. file=src/FooTest.java#testcase=testBar', result.output)
self.assertIn('::stop-commands::', result.output)
self.assertIn('AssertionError: expected true but was false', result.output)
self.assertIn('::endgroup::', result.output)
Comment thread
jothikumar-CB marked this conversation as resolved.

Expand Down Expand Up @@ -199,25 +198,15 @@ def test_gate_github_actions_stderr_with_command_syntax(self):
result = self.cli('gate', '--session', self.session)
self.assert_exit_code(result, 1)

# verify all dangerous commands are sandwiched between stop-commands and resume token
stop_idx = result.output.index('::stop-commands::')
# resume token is the line between stop-commands and ::endgroup::
endgroup_idx = result.output.index('::endgroup::')

error_idx = result.output.index('::error::some error')
warning_idx = result.output.index('::warning::spoofed')
mask_idx = result.output.index('::add-mask::secret-value')
assertion_idx = result.output.index('java.lang.AssertionError')

# all stderr content must be after ::stop-commands:: and before ::endgroup::
self.assertLess(stop_idx, error_idx)
self.assertLess(stop_idx, warning_idx)
self.assertLess(stop_idx, mask_idx)
self.assertLess(stop_idx, assertion_idx)
self.assertLess(error_idx, endgroup_idx)
self.assertLess(warning_idx, endgroup_idx)
self.assertLess(mask_idx, endgroup_idx)
self.assertLess(assertion_idx, endgroup_idx)
# dangerous :: lines are escaped so GHA won't interpret them as commands
self.assertIn('%3A%3Aerror::some error', result.output)
self.assertIn('%3A%3Awarning::spoofed', result.output)
self.assertIn('%3A%3Aadd-mask::secret-value', result.output)
self.assertIn('%3A%3Aset-output name=x::y', result.output)

# normal lines are untouched
self.assertIn('java.lang.AssertionError', result.output)
self.assertIn('::endgroup::', result.output)

@responses.activate
@mock.patch.dict(os.environ, {"LAUNCHABLE_TOKEN": CliTestCase.launchable_token})
Expand Down
Loading