diff --git a/step.sh b/step.sh index d309850..758885b 100644 --- a/step.sh +++ b/step.sh @@ -90,7 +90,12 @@ echo "app_url: $app_url" echo "disable_animations: $disable_animations" echo "quiet: $quiet" echo "use_beta: $use_beta" +echo "check_name: $check_name" +# check_name is passed as its own quoted `-m` pair rather than folded into +# metadata_parsed, which expands unquoted: a check name containing a space would +# split into two argv entries and the stray word would land as a positional (app +# file / workspace). echo "Running command: npx --yes \"$DCD_VERSION\" cloud --quiet \ --apiKey \"$api_key\" \ ${allure_path:+--allure-path \"$allure_path\"} \ @@ -121,6 +126,7 @@ ${junit_path:+--junit-path \"$junit_path\"} \ ${is_maestro_chrome_onboarding:+--maestro-chrome-onboarding} \ ${maestro_version:+--maestro-version \"$maestro_version\"} \ ${name:+--name \"$name\"} \ +${check_name:+-m \"gh_check_name=$check_name\"} \ ${orientation:+--orientation \"$orientation\"} \ ${report:+--report \"$report\"} \ ${retry:+--retry \"$retry\"} \ @@ -170,6 +176,7 @@ ${junit_path:+--junit-path "$junit_path"} \ ${is_maestro_chrome_onboarding:+--maestro-chrome-onboarding} \ ${maestro_version:+--maestro-version "$maestro_version"} \ ${name:+--name "$name"} \ +${check_name:+-m "gh_check_name=$check_name"} \ ${orientation:+--orientation "$orientation"} \ ${report:+--report "$report"} \ ${retry:+--retry "$retry"} \ diff --git a/step.yml b/step.yml index edc0ed3..0a5798f 100644 --- a/step.yml +++ b/step.yml @@ -180,6 +180,13 @@ inputs: is_expand: true is_required: false + - check_name: "" + opts: + title: "GitHub Check Name" + summary: "Names the GitHub check this run posts, e.g. \"iOS\" gives \"DeviceCloud / iOS\". Only applies when the run carries GitHub commit metadata (gh_sha/gh_repo) and your org has the DeviceCloud GitHub App installed. Use it when a commit is tested more than once so each run gets a check that can be required separately in branch protection, and keep the value fixed for a given workflow." + is_expand: true + is_required: false + - device_locale: "" opts: title: "Device Locale" diff --git a/test/test.bats b/test/test.bats index 923e9fb..ee25aa5 100644 --- a/test/test.bats +++ b/test/test.bats @@ -30,6 +30,9 @@ done case "$sub" in cloud) echo "STUB_CLOUD_CALLED_WITH: $*" + # One line per argv entry as well, so a test can tell "-m a=b c" (three + # words, from an unquoted expansion) from "-m" plus "a=b c" (two args). + for a in "$@"; do echo "STUB_CLOUD_ARG: $a"; done echo "View results: https://console.devicecloud.dev/results?upload=fake-upload-id" exit "${STUB_CLOUD_EXIT:-0}" ;; @@ -70,8 +73,8 @@ STUB # step.sh reads Bitrise inputs from lowercase env vars; clear any the host # runner may have exported so each test specifies exactly what it wants. unset api_key app_file workspace android_device android_api_level ios_device \ - name async google_play debug disable_animations use_beta env_list \ - metadata download_artifacts STUB_STATUS STUB_CLOUD_EXIT + name check_name async google_play debug disable_animations use_beta \ + env_list metadata download_artifacts STUB_STATUS STUB_CLOUD_EXIT } teardown() { @@ -127,6 +130,24 @@ teardown() { [[ "$output" == *"--name My Run"* ]] } +@test "sends check_name as a single gh_check_name metadata pair" { + # A space in the value must survive as one argument: it reaches the backend as + # the GitHub check's name, and a split would leave a stray positional where the + # app file / workspace go. + export api_key="k" + export check_name="iOS smoke" + run bash "${TEST_DIR}/step.sh" + [ "$status" -eq 0 ] + [[ "$output" == *"STUB_CLOUD_ARG: gh_check_name=iOS smoke"* ]] +} + +@test "sends no gh_check_name when check_name is unset" { + export api_key="k" + run bash "${TEST_DIR}/step.sh" + [ "$status" -eq 0 ] + [[ "$output" != *"gh_check_name"* ]] +} + @test "passes --async only when async=true" { export api_key="k"