From 05dcf2c2d75002a47636cbe76d14ee5bf367a2ab Mon Sep 17 00:00:00 2001 From: finalerock44 <77282157+finalerock44@users.noreply.github.com> Date: Thu, 17 Sep 2026 12:57:20 +0100 Subject: [PATCH] Add cancel_previous input Passes --cancel-previous to the CLI so a new build cancels the still-queued tests of the previous run from the same CI context. Bitrise reports no build id to DeviceCloud, so the same-run sibling guard the other integrations get does not apply here: a build that runs this step twice needs a distinct check_name per invocation, or the second cancels the first. Said so in the input description. Co-Authored-By: Claude Opus 5 (1M context) --- step.sh | 4 ++++ step.yml | 20 ++++++++++++++++++++ test/test.bats | 14 ++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/step.sh b/step.sh index 3913616..3c2fa24 100644 --- a/step.sh +++ b/step.sh @@ -32,6 +32,7 @@ fi # Refine variables [[ "$async" == "true" ]] && is_async="true" [[ "$google_play" == "true" ]] && is_google_play="true" +[[ "$cancel_previous" == "true" ]] && is_cancel_previous="true" [[ "$ignore_sha_check" == "true" ]] && is_ignore_sha_check="true" [[ "$show_crosshairs" == "true" ]] && is_show_crosshairs="true" [[ "$maestro_chrome_onboarding" == "true" ]] && is_maestro_chrome_onboarding="true" @@ -59,6 +60,7 @@ echo "app_binary_id: $app_binary_id" echo "app_file: $app_file" echo "artifacts_path: $artifacts_path" echo "async: $async" +echo "cancel_previous: $cancel_previous" echo "config: $config" echo "device_locale: $device_locale" echo "download_artifacts: $download_artifacts" @@ -107,6 +109,7 @@ ${api_url:+--api-url \"$api_url\"} \ ${app_binary_id:+--app-binary-id \"$app_binary_id\"} \ ${artifacts_path:+--artifacts-path \"$artifacts_path\"} \ ${is_async:+--async} \ +${is_cancel_previous:+--cancel-previous} \ ${config:+--config \"$config\"} \ ${is_debug:+--debug} \ ${device_locale:+--device-locale \"$device_locale\"} \ @@ -158,6 +161,7 @@ ${api_url:+--api-url "$api_url"} \ ${app_binary_id:+--app-binary-id "$app_binary_id"} \ ${artifacts_path:+--artifacts-path "$artifacts_path"} \ ${is_async:+--async} \ +${is_cancel_previous:+--cancel-previous} \ ${config:+--config "$config"} \ ${is_debug:+--debug} \ ${device_locale:+--device-locale "$device_locale"} \ diff --git a/step.yml b/step.yml index 815cae7..03e933b 100644 --- a/step.yml +++ b/step.yml @@ -111,6 +111,26 @@ inputs: - "true" - "false" + - cancel_previous: "false" + opts: + title: "Cancel Previous Run" + summary: "Cancel the still-queued tests of the previous run from the same CI context" + description: | + Cancels the still-queued tests of the previous run from the same CI + context when this run is submitted. Tests already running are left to + finish; cancelled tests are refunded at 75%. + + The context is matched on repository + branch (or PR) + `check_name`. + Bitrise reports no build id to DeviceCloud, so if one build runs this + step more than once give each invocation its own `check_name` — + otherwise the second would cancel the first. + is_expand: true + is_required: false + default_value: "false" + value_options: + - "true" + - "false" + - dry_run: "false" opts: title: "Dry Run" diff --git a/test/test.bats b/test/test.bats index ee25aa5..f9c8a41 100644 --- a/test/test.bats +++ b/test/test.bats @@ -162,6 +162,20 @@ teardown() { [[ "$output" != *"--async"* ]] } +@test "passes --cancel-previous only when cancel_previous=true" { + export api_key="k" + + export cancel_previous="true" + run bash "${TEST_DIR}/step.sh" + [ "$status" -eq 0 ] + [[ "$output" == *"--cancel-previous"* ]] + + export cancel_previous="false" + run bash "${TEST_DIR}/step.sh" + [ "$status" -eq 0 ] + [[ "$output" != *"--cancel-previous"* ]] +} + @test "boolean flags appear only when their inputs are true" { export api_key="k" export google_play="true"