Skip to content
Open
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
15 changes: 14 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ inputs:
Job names that are allowed to be skipped and not affect the
outcome, as a comma-separated list or serialized as a JSON string
required: false
action-summary-output:
default: >-
all
description: >-
Behavior to use for publishing outcome to the Github action summary page

Available Options:
all - results shown in both stderr and action status.
none - results shown only in stderr.
quiet-on-success - matrix success only shown only in stderr, all other
output follows same behavior as 'all'.
required: false

outputs:
failure:
Expand Down Expand Up @@ -62,6 +74,7 @@ runs:
"$(cat << EOM
${{ inputs.jobs }}
EOM
)"
)" \
"${{ inputs.action-summary-output }}"
shell: bash
...
35 changes: 34 additions & 1 deletion src/normalize_needed_jobs_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

_T = _t.TypeVar('_T')
FILE_APPEND_MODE = 'a'
ACTION_SUMMARY_OUTPUT_OPTIONS = ['all', 'none', 'quiet-on-success']


class ActionJobInputType(_t.TypedDict): # noqa: D101
Expand All @@ -21,6 +22,7 @@ class ActionInputsType(_t.TypedDict): # noqa: D101
allowed_failures: list[str]
allowed_skips: list[str]
jobs: dict[str, ActionJobInputType]
action_summary_output: str


def write_lines_to_streams( # noqa: D103
Expand Down Expand Up @@ -77,6 +79,7 @@ def parse_inputs(
raw_allowed_failures: str,
raw_allowed_skips: str,
raw_jobs: str,
raw_action_summary: str,
) -> ActionInputsType:
"""Normalize the action inputs by turning them into data."""
allowed_failures_input = drop_empty_from_list(
Expand All @@ -90,6 +93,7 @@ def parse_inputs(
'allowed_failures': allowed_failures_input,
'allowed_skips': allowed_skips_input,
'jobs': _t.cast('dict[str, ActionJobInputType]', json.loads(raw_jobs)),
'action_summary_output': raw_action_summary
}


Expand All @@ -99,6 +103,7 @@ def log_decision_details(
jobs_allowed_to_be_skipped: _t.Iterable[str],
allowed_to_fail_jobs_succeeded: bool,
allowed_to_be_skipped_jobs_succeeded: bool,
action_summary_output: str,
jobs: dict[str, ActionJobInputType],
summary_file_streams: _t.Iterable[_t.TextIO],
) -> None:
Expand Down Expand Up @@ -151,7 +156,14 @@ def log_decision_details(
),
}

write_lines_to_streams(markdown_summary_lines, summary_file_streams)
if action_summary_output == 'none' or (
job_matrix_succeeded and action_summary_output == 'quiet-on-success'
):
configured_streams = [_t.cast('_t.TextIO', sys.stderr)]
else:
configured_streams = summary_file_streams

write_lines_to_streams(markdown_summary_lines, configured_streams)


def main(argv: list[str]) -> int:
Expand All @@ -160,6 +172,7 @@ def main(argv: list[str]) -> int:
raw_allowed_failures=argv[1],
raw_allowed_skips=argv[2],
raw_jobs=argv[3],
raw_action_summary=argv[4],
)
summary_file_path = pathlib.Path(os.environ['GITHUB_STEP_SUMMARY'])

Expand All @@ -183,6 +196,25 @@ def main(argv: list[str]) -> int:
)
return 1

action_summary_output = inputs['action_summary_output']

if action_summary_output not in ACTION_SUMMARY_OUTPUT_OPTIONS:
with summary_file_path.open( # type: ignore[misc]
mode=FILE_APPEND_MODE,
) as summary_file:
write_lines_to_streams(
(
'# ❌ Invalid action-summary-output: '
f'{action_summary_output}, '
f'Expected: {ACTION_SUMMARY_OUTPUT_OPTIONS}',
),
(
_t.cast('_t.TextIO', sys.stderr),
_t.cast('_t.TextIO', summary_file),
),
)
return 1

job_matrix_succeeded = all(
job['result'] == 'success'
for name, job in jobs.items()
Expand Down Expand Up @@ -215,6 +247,7 @@ def main(argv: list[str]) -> int:
jobs_allowed_to_be_skipped,
allowed_to_fail_jobs_succeeded,
allowed_to_be_skipped_jobs_succeeded,
action_summary_output,
jobs,
summary_file_streams=(
sys.stderr,
Expand Down
Loading