Skip to content

Commit

Permalink
Redirect composite action through dynamic action
Browse files Browse the repository at this point in the history
  • Loading branch information
EnricoMi committed Feb 23, 2024
1 parent afd456f commit e2238b9
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 110 deletions.
116 changes: 7 additions & 109 deletions composite/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -152,115 +152,20 @@ inputs:
outputs:
json:
description: "Test results as JSON"
value: ${{ steps.linux.outputs.json || steps.macos.outputs.json || steps.windows.outputs.json }}
value: ${{ steps.run.outputs.json }}

runs:
using: 'composite'
steps:
- name: Check OS
# env.RUNNER_OS is not available in if condition of steps
run: echo "OS=$RUNNER_OS" >> "$GITHUB_ENV"
run: |
mkdir .enricomi.publish-unit-test-result.proxy
$GITHUB_ACTION_PATH/proxy.sh > .enricomi.publish-unit-test-result.proxy/action.yml
shell: bash

- name: Run on Linux
id: linux
if: startsWith(env.OS, 'Linux')
uses: ./../linux
with:
GITHUB_TOKEN: ${{ inputs.github_token }}
GITHUB_TOKEN_ACTOR: ${{ inputs.github_token_actor }}
GITHUB_RETRIES: ${{ inputs.github_retries }}
COMMIT: ${{ inputs.commit }}
CHECK_NAME: ${{ inputs.check_name }}
COMMENT_TITLE: ${{ inputs.comment_title }}
COMMENT_MODE: ${{ inputs.comment_mode }}
FAIL_ON: ${{ inputs.fail_on }}
ACTION_FAIL: ${{ inputs.action_fail }}
ACTION_FAIL_ON_INCONCLUSIVE: ${{ inputs.action_fail_on_inconclusive }}
FILES: ${{ inputs.files }}
JUNIT_FILES: ${{ inputs.junit_files }}
NUNIT_FILES: ${{ inputs.nunit_files }}
XUNIT_FILES: ${{ inputs.xunit_files }}
TRX_FILES: ${{ inputs.trx_files }}
TIME_UNIT: ${{ inputs.time_unit }}
TEST_FILE_PREFIX: ${{ inputs.test_file_prefix }}
REPORT_INDIVIDUAL_RUNS: ${{ inputs.report_individual_runs }}
REPORT_SUITE_LOGS: ${{ inputs.report_suite_logs }}
DEDUPLICATE_CLASSES_BY_FILE_NAME: ${{ inputs.deduplicate_classes_by_file_name }}
LARGE_FILES: ${{ inputs.large_files }}
IGNORE_RUNS: ${{ inputs.ignore_runs }}
COMPARE_TO_EARLIER_COMMIT: ${{ inputs.compare_to_earlier_commit }}
PULL_REQUEST_BUILD: ${{ inputs.pull_request_build }}
EVENT_FILE: ${{ inputs.event_file }}
EVENT_NAME: ${{ inputs.event_name }}
TEST_CHANGES_LIMIT: ${{ inputs.test_changes_limit }}
CHECK_RUN_ANNOTATIONS: ${{ inputs.check_run_annotations }}
CHECK_RUN_ANNOTATIONS_BRANCH: ${{ inputs.check_run_annotations_branch }}
SECONDS_BETWEEN_GITHUB_READS: ${{ inputs.seconds_between_github_reads }}
SECONDS_BETWEEN_GITHUB_WRITES: ${{ inputs.seconds_between_github_writes }}
SECONDARY_RATE_LIMIT_WAIT_SECONDS: ${{ inputs.secondary_rate_limit_wait_seconds }}
JSON_FILE: ${{ inputs.json_file }}
JSON_THOUSANDS_SEPARATOR: ${{ inputs.json_thousands_separator }}
JSON_SUITE_DETAILS: ${{ inputs.json_suite_details }}
JSON_TEST_CASE_RESULTS: ${{ inputs.json_test_case_results }}
CHECK_RUN: ${{ inputs.check_run }}
JOB_SUMMARY: ${{ inputs.job_summary }}
SEARCH_PULL_REQUESTS: ${{ inputs.search_pull_requests }}
ROOT_LOG_LEVEL: ${{ inputs.root_log_level }}
LOG_LEVEL: ${{ inputs.log_level }}

- name: Run on macOS
id: macos
if: startsWith(env.OS, 'macOS')
uses: ./../macos
with:
GITHUB_TOKEN: ${{ inputs.github_token }}
GITHUB_TOKEN_ACTOR: ${{ inputs.github_token_actor }}
GITHUB_RETRIES: ${{ inputs.github_retries }}
COMMIT: ${{ inputs.commit }}
CHECK_NAME: ${{ inputs.check_name }}
COMMENT_TITLE: ${{ inputs.comment_title }}
COMMENT_MODE: ${{ inputs.comment_mode }}
FAIL_ON: ${{ inputs.fail_on }}
ACTION_FAIL: ${{ inputs.action_fail }}
ACTION_FAIL_ON_INCONCLUSIVE: ${{ inputs.action_fail_on_inconclusive }}
FILES: ${{ inputs.files }}
JUNIT_FILES: ${{ inputs.junit_files }}
NUNIT_FILES: ${{ inputs.nunit_files }}
XUNIT_FILES: ${{ inputs.xunit_files }}
TRX_FILES: ${{ inputs.trx_files }}
TIME_UNIT: ${{ inputs.time_unit }}
TEST_FILE_PREFIX: ${{ inputs.test_file_prefix }}
REPORT_INDIVIDUAL_RUNS: ${{ inputs.report_individual_runs }}
REPORT_SUITE_LOGS: ${{ inputs.report_suite_logs }}
DEDUPLICATE_CLASSES_BY_FILE_NAME: ${{ inputs.deduplicate_classes_by_file_name }}
LARGE_FILES: ${{ inputs.large_files }}
IGNORE_RUNS: ${{ inputs.ignore_runs }}
COMPARE_TO_EARLIER_COMMIT: ${{ inputs.compare_to_earlier_commit }}
PULL_REQUEST_BUILD: ${{ inputs.pull_request_build }}
EVENT_FILE: ${{ inputs.event_file }}
EVENT_NAME: ${{ inputs.event_name }}
TEST_CHANGES_LIMIT: ${{ inputs.test_changes_limit }}
CHECK_RUN_ANNOTATIONS: ${{ inputs.check_run_annotations }}
CHECK_RUN_ANNOTATIONS_BRANCH: ${{ inputs.check_run_annotations_branch }}
SECONDS_BETWEEN_GITHUB_READS: ${{ inputs.seconds_between_github_reads }}
SECONDS_BETWEEN_GITHUB_WRITES: ${{ inputs.seconds_between_github_writes }}
SECONDARY_RATE_LIMIT_WAIT_SECONDS: ${{ inputs.secondary_rate_limit_wait_seconds }}
JSON_FILE: ${{ inputs.json_file }}
JSON_THOUSANDS_SEPARATOR: ${{ inputs.json_thousands_separator }}
JSON_SUITE_DETAILS: ${{ inputs.json_suite_details }}
JSON_TEST_CASE_RESULTS: ${{ inputs.json_test_case_results }}
CHECK_RUN: ${{ inputs.check_run }}
JOB_SUMMARY: ${{ inputs.job_summary }}
SEARCH_PULL_REQUESTS: ${{ inputs.search_pull_requests }}
ROOT_LOG_LEVEL: ${{ inputs.root_log_level }}
LOG_LEVEL: ${{ inputs.log_level }}

- name: Run on Windows
id: windows
if: startsWith(env.OS, 'Windows')
# this general composite action requires Bash shell, so this calls into windows/bash as well
uses: ./../windows/bash
- name: Run
id: run
uses: ./.enricomi.publish-unit-test-result.proxy
with:
GITHUB_TOKEN: ${{ inputs.github_token }}
GITHUB_TOKEN_ACTOR: ${{ inputs.github_token_actor }}
Expand Down Expand Up @@ -304,13 +209,6 @@ runs:
ROOT_LOG_LEVEL: ${{ inputs.root_log_level }}
LOG_LEVEL: ${{ inputs.log_level }}

- name: Run on unsupported Operating System
if: steps.linux.outcome == 'skipped' && steps.macos.outcome == 'skipped' && steps.windows.outcome == 'skipped'
run: |
echo "::error::Unsupported operating system: $RUNNER_OS"
exit 1
shell: bash

branding:
icon: 'check-circle'
color: 'green'
40 changes: 40 additions & 0 deletions composite/proxy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash

set -euo pipefail

case "$RUNNER_OS" in
Linux*)
action="linux"
;;
macOS*)
action="macos"
;;
Windows*)
action="windows/bash"
;;
*)
echo "::error::Unsupported operating system: $RUNNER_OS"
exit 1
;;
esac

action_path="$(cd "$GITHUB_ACTION_PATH/../$action"; pwd)"

in_runs=false
in_check=false
in_run=false

while IFS= read -r line
do
if [ "$line" == "runs:" ]; then in_runs=true
elif [ $in_runs == true ] && [[ "$line" == *"- name: Check OS" ]]; then in_check=true
elif [ $in_runs == true ] && [[ "$line" == *"- name: Run" ]]; then in_check=false; in_run=true
fi

if [ $in_run == true ] && [[ "$line" == *" uses: "* ]]; then
# use $action_path in uses: ...
echo "${line/%:*/: $action_path}"
elif [ $in_check != true ] && ( [ $in_run != true ] || [[ "$line" != *" if:"* ]] ); then
echo "$line"
fi
done < "$GITHUB_ACTION_PATH/action.yml"
10 changes: 9 additions & 1 deletion python/test/test_action_yml.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,15 @@ def do_test_composite_action(self, action: str):
# the 'composite' composite action is just a proxy to the os-specific actions, it forwards inputs via 'with'
steps = [step for step in steps
if 'name' in step
and step.get('name').startswith('Run on ')
and step.get('name').startswith('Run')
and step.get('name') != 'Run on unsupported Operating System']
inputs_key = 'with'
else:
# the other composite actions forward inputs via env
steps = [step for step in steps if step.get('name') == 'Publish Test Results']
inputs_key = 'env'

self.assertTrue(len(steps) > 0)
for step in steps:
self.assertIn(inputs_key, step, step.get('name'))
inputs = {key.upper(): value for key, value in step.get(inputs_key, {}).items()}
Expand All @@ -91,3 +93,9 @@ def do_test_composite_action(self, action: str):
if step.get('uses', '').startswith('actions/cache/restore@'))
self.assertEqual(expected_hash, cache_hash, msg='Changing python/requirements.txt requires '
'to update the MD5 hash in composite/action.yaml')

def test_proxy_action(self):
# TODO
# run RUNNER_OS=Linux|Windows|macOS GITHUB_ACTION_PATH=... composite/proxy.sh
# and compare with python/test/files/proxy.yml
pass

0 comments on commit e2238b9

Please sign in to comment.