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 20ee7c9
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 108 deletions.
119 changes: 12 additions & 107 deletions composite/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -152,67 +152,22 @@ 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: |
echo "GITHUB_ACTION_PATH: $GITHUB_ACTION_PATH"
cp -rv $GITHUB_ACTION_PATH/.. ./enricomi-publish-action-proxy
$GITHUB_ACTION_PATH/proxy.sh > ./enricomi-publish-action-proxy/action.yml
cat ./enricomi-publish-action-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
- name: Run
id: run
uses: ./enricomi-publish-action-proxy
with:
GITHUB_TOKEN: ${{ inputs.github_token }}
GITHUB_TOKEN_ACTOR: ${{ inputs.github_token_actor }}
Expand Down Expand Up @@ -256,59 +211,9 @@ runs:
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
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 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
- name: Clean up
if: always()
run: rm -rf ./enricomi-publish-action-proxy
shell: bash

branding:
Expand Down
41 changes: 41 additions & 0 deletions composite/proxy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/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

in_runs=false
in_check=false
in_run=false
in_cleanup=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
elif [ $in_runs == true ] && [[ "$line" == *"- name: Clean up" ]]; then in_run=false; in_cleanup=true
elif [ "$line" == "branding:" ]; then in_cleanup=false
fi

if [ $in_run == true ] && [[ "$line" == *" uses: "* ]]; then
# use $action in uses: ...
echo "${line/%:*/: ./enricomi-publish-action-proxy/$action}"
elif [ $in_check != true ] && [ $in_cleanup != true ] && ( [ $in_run != true ] || [[ "$line" != *" if:"* ]] ); then
echo "$line"
fi
done < "$GITHUB_ACTION_PATH/action.yml"
2 changes: 2 additions & 0 deletions linux/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ runs:
run: |
echo '::group::Check for Python3'
echo "GITHUB_ACTION_PATH: $GITHUB_ACTION_PATH"
# we check version here just to execute `python3` with an argument
# on Windows, there is a `python3.exe` that is a proxy to trigger installation from app store
# command `which python3` finds that, but `python3 -V` does not return the version on stdout
Expand Down
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 20ee7c9

Please sign in to comment.