Skip to content

Commit 345bbc3

Browse files
thebiglabaskyclaude
andcommitted
fix: harden the github-report path for zero-config marketplace use
- An old pinned CLI no longer hard-fails the job: cli-version < 8.12.0 now falls back to the non-detached mode with reason cli_version_too_old, skipping the preflight entirely. - The preflight fetch gets a 10s AbortSignal timeout so a slow backend can never stall the customer's job before tests run. - The preflight command substitution tolerates a non-zero node exit (OOM/kill) instead of aborting the whole action under set -e. - The preflight-sourced reason is sanitized to [a-z0-9_] before being interpolated into ::warning:: workflow commands and the step summary, closing a workflow-command injection surface. - resolve_github_repository/sha run once and feed both env configs, dropping four redundant node forks per run; configure_github_report loses its unreachable duplicate boolean validation. - README/action.yml copy updated; tests cover the old-CLI fallback and the invalid-boolean error. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 1dd0644 commit 345bbc3

4 files changed

Lines changed: 64 additions & 45 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ target URL explicitly through `env` or the workflow `env` block.
7777
| Input | Description |
7878
| --- | --- |
7979
| `command` | `test` for local constructs or `trigger` for deployed checks. Defaults to `test`. |
80-
| `cli-version` | Checkly CLI npm version. Defaults to `latest`. When `github-report` is enabled, pinned stable versions must be `8.12.0` or newer. Dist-tags, canaries, and prereleases are allowed. |
80+
| `cli-version` | Checkly CLI npm version. Defaults to `latest`. GitHub Check writeback needs `8.12.0` or newer; older pinned versions fall back to waiting in the Action. Dist-tags, canaries, and prereleases are assumed compatible. |
8181
| `working-directory` | Directory where the CLI command should run. Defaults to `.`. |
8282
| `install-command` | Optional command to run before the Checkly CLI command, inside `working-directory`. |
8383
| `tags` | One `--tags` filter per line. Each line can contain comma-separated tags. |

action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ inputs:
1212
required: false
1313
default: test
1414
cli-version:
15-
description: Checkly CLI npm version to run. When github-report is enabled, pinned stable versions must be 8.12.0 or newer.
15+
description: Checkly CLI npm version to run. GitHub Check writeback needs 8.12.0 or newer; older pinned versions fall back to waiting in the Action.
1616
required: false
1717
default: latest
1818
working-directory:

scripts/run.sh

Lines changed: 49 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -79,30 +79,32 @@ add_positional_from_lines() {
7979
done <<< "$values"
8080
}
8181

82-
validate_cli_version_for_github_report() {
82+
cli_version_supports_github_report() {
8383
local version
8484
version="$(trim "${1:-}")"
85-
if [[ -z "$version" ]]; then
86-
return
87-
fi
8885

89-
# Only reject exact pinned stable semver below 8.12.0. Dist-tags, ranges,
90-
# canaries, and prereleases are allowed because they may point at compatible
91-
# builds before a stable release exists.
92-
if [[ "$version" =~ ^v?([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then
86+
# Only exact pinned stable semver is comparable against the 8.12.0 floor.
87+
# Dist-tags, ranges, canaries, and prereleases pass because they may point
88+
# at compatible builds before a stable release exists.
89+
if [[ "$version" =~ ^v?([0-9]+)\.([0-9]+)\.[0-9]+$ ]]; then
9390
local major="${BASH_REMATCH[1]}"
9491
local minor="${BASH_REMATCH[2]}"
95-
local patch="${BASH_REMATCH[3]}"
9692

9793
if (( major < 8 || (major == 8 && minor < 12) )); then
98-
echo "::error::github-report requires Checkly CLI 8.12.0 or newer when cli-version is pinned. Use cli-version: latest, a canary/prerelease, or a version >= 8.12.0. Got '${version}'." >&2
99-
exit 1
94+
return 1
10095
fi
101-
102-
# Keep shellcheck/linters happy that patch is intentionally parsed as part
103-
# of the exact semver guard even though the minimum is major/minor aligned.
104-
: "$patch"
10596
fi
97+
98+
return 0
99+
}
100+
101+
# Reasons are interpolated into ::warning:: workflow commands and the step
102+
# summary; constrain them to a safe charset so a malformed or hostile
103+
# preflight response can never inject workflow commands or extra lines.
104+
sanitize_reason() {
105+
local value
106+
value="$(printf '%s' "${1:-}" | tr -cd 'a-z0-9_')"
107+
printf '%s' "${value:-unavailable}"
106108
}
107109

108110
write_output() {
@@ -192,14 +194,13 @@ clear_github_report_env() {
192194
}
193195

194196
configure_generic_repo_env() {
195-
local repository
196-
repository="$(resolve_github_repository)"
197+
local repository="$1"
198+
local sha="$2"
199+
197200
if [[ -n "$repository" ]]; then
198201
export CHECKLY_REPO_URL="${CHECKLY_REPO_URL:-${GITHUB_SERVER_URL:-https://github.com}/${repository}}"
199202
fi
200203

201-
local sha
202-
sha="$(resolve_github_sha)"
203204
if [[ -n "$sha" ]]; then
204205
export CHECKLY_REPO_SHA="${CHECKLY_REPO_SHA:-$sha}"
205206
fi
@@ -219,26 +220,15 @@ configure_deployment_environment_url() {
219220
}
220221

221222
configure_github_report() {
222-
local value="${INPUT_GITHUB_REPORT:-true}"
223-
if falsey "$value"; then
224-
clear_github_report_env
225-
return
226-
fi
227-
if ! truthy "$value"; then
228-
echo "::error::Expected boolean input for github-report, got '${value}'." >&2
229-
exit 1
230-
fi
223+
local repository="$1"
224+
local sha="$2"
231225

232226
export CHECKLY_GITHUB_REPORT=true
233227

234-
local repository
235-
repository="$(resolve_github_repository)"
236228
if [[ -n "$repository" ]]; then
237229
export CHECKLY_GITHUB_REPOSITORY="$repository"
238230
fi
239231

240-
local sha
241-
sha="$(resolve_github_sha)"
242232
if [[ -n "$sha" ]]; then
243233
export CHECKLY_GITHUB_SHA="$sha"
244234
fi
@@ -336,6 +326,8 @@ async function main() {
336326
'x-checkly-cli-version': process.env.CHECKLY_PREFLIGHT_CLI_VERSION ?? '',
337327
},
338328
body: JSON.stringify(payload),
329+
// The preflight is advisory: never let a slow backend hold up the run.
330+
signal: AbortSignal.timeout(10_000),
339331
})
340332
341333
if (!response.ok) {
@@ -397,7 +389,12 @@ if [[ "$command_name" == "test" && -n "$(trim "${INPUT_FAIL_ON_NO_MATCHING:-}")"
397389
exit 1
398390
fi
399391

400-
configure_generic_repo_env
392+
# Resolve the repository/sha once; both the generic repo env and the GitHub
393+
# report env derive from the same values.
394+
github_repository="$(resolve_github_repository)"
395+
github_sha="$(resolve_github_sha)"
396+
397+
configure_generic_repo_env "$github_repository" "$github_sha"
401398
configure_deployment_environment_url
402399

403400
github_report_requested=false
@@ -410,17 +407,27 @@ if falsey "${INPUT_GITHUB_REPORT:-true}"; then
410407
clear_github_report_env
411408
elif truthy "${INPUT_GITHUB_REPORT:-true}"; then
412409
github_report_requested=true
413-
validate_cli_version_for_github_report "$cli_version"
414-
configure_github_report
415-
preflight_result="$(github_report_preflight)"
416-
IFS=$'\t' read -r github_report_available github_report_reason <<< "$preflight_result"
417-
if [[ "$github_report_available" == "true" ]]; then
418-
detach_run=true
419-
github_reporter_run=false
420-
else
410+
if ! cli_version_supports_github_report "$cli_version"; then
411+
# Writeback needs CLI >= 8.12.0, but an older pinned CLI is not an error:
412+
# fall back to the non-detached mode like any other unavailable reason.
413+
github_report_reason="cli_version_too_old"
421414
clear_github_report_env
422415
if [[ "${GITHUB_ACTIONS:-}" == "true" ]]; then
423-
echo "::warning::Checkly GitHub App reporting is unavailable (${github_report_reason}). Running without --detach so this GitHub Actions job waits for the Checkly test session result. Install the Checkly GitHub App on this repository to run detached and receive a Checkly GitHub Check instead."
416+
echo "::warning::GitHub Check writeback needs Checkly CLI 8.12.0 or newer (cli-version is '${cli_version}'). Running without --detach so this GitHub Actions job waits for the Checkly test session result. Use cli-version: latest or >= 8.12.0 to enable detached GitHub Check reporting."
417+
fi
418+
else
419+
configure_github_report "$github_repository" "$github_sha"
420+
preflight_result="$(github_report_preflight)" || preflight_result=$'false\tpreflight_crashed'
421+
IFS=$'\t' read -r github_report_available github_report_reason <<< "$preflight_result"
422+
github_report_reason="$(sanitize_reason "$github_report_reason")"
423+
if [[ "$github_report_available" == "true" ]]; then
424+
detach_run=true
425+
github_reporter_run=false
426+
else
427+
clear_github_report_env
428+
if [[ "${GITHUB_ACTIONS:-}" == "true" ]]; then
429+
echo "::warning::Checkly GitHub App reporting is unavailable (${github_report_reason}). Running without --detach so this GitHub Actions job waits for the Checkly test session result. Install the Checkly GitHub App on this repository to run detached and receive a Checkly GitHub Check instead."
430+
fi
424431
fi
425432
fi
426433
else

scripts/test.sh

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,23 @@ fallback_command_output="$(
8484
assert_contains "$fallback_command_output" "checkly@8.12.0 test --reporter=github"
8585
assert_contains "$fallback_command_output" "GitHub report: unavailable (github_app_not_connected), waiting for CLI result"
8686

87-
assert_fails_with "github-report requires Checkly CLI 8.12.0 or newer" env \
87+
# An old pinned CLI must fall back (skipping the preflight entirely), not fail
88+
# the job: CHECKLY_ACTION_GITHUB_REPORT_AVAILABLE=true would force the detached
89+
# path if the preflight were still consulted.
90+
old_cli_fallback_output="$(
8891
INPUT_COMMAND=test \
8992
INPUT_CLI_VERSION=8.11.9 \
9093
INPUT_GITHUB_REPORT=true \
9194
CHECKLY_ACTION_GITHUB_REPORT_AVAILABLE=true \
95+
run_dry
96+
)"
97+
98+
assert_contains "$old_cli_fallback_output" "checkly@8.11.9 test --reporter=github"
99+
assert_contains "$old_cli_fallback_output" "GitHub report: unavailable (cli_version_too_old), waiting for CLI result"
100+
101+
assert_fails_with "Expected boolean input for github-report" env \
102+
INPUT_COMMAND=test \
103+
INPUT_GITHUB_REPORT=banana \
92104
CHECKLY_ACTION_DRY_RUN=1 \
93105
"$ROOT_DIR/scripts/run.sh"
94106

0 commit comments

Comments
 (0)