Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ jobs:
install-command: npm ci
tags: production,webapp
grep: checkout
github-check-name: Checkly PR code checks
env:
CHECKLY_API_KEY: ${{ secrets.CHECKLY_API_KEY }}
CHECKLY_ACCOUNT_ID: ${{ secrets.CHECKLY_ACCOUNT_ID }}
Expand Down Expand Up @@ -102,6 +103,7 @@ target URL explicitly through `env` or the workflow `env` block.
| `fail-on-no-matching` | `trigger` only. Set to `false` to pass `--no-fail-on-no-matching`. |
| `verbose` | Set to `true` or `false` to pass `--verbose` or `--no-verbose`. |
| `reporting` | Where to report the Checkly result: `auto`, `github-check`, or `github-actions`. Defaults to `auto`. |
| `github-check-name` | GitHub Check name used when reporting through the Checkly GitHub App. Defaults to `Checkly`. |

## Outputs

Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ inputs:
description: Where to report the Checkly result. Use "auto", "github-check", or "github-actions".
required: false
default: auto
github-check-name:
description: GitHub Check name to create when reporting through the Checkly GitHub App. Defaults to "Checkly".
required: false

outputs:
test-session-id:
Expand Down Expand Up @@ -117,3 +120,4 @@ runs:
INPUT_FAIL_ON_NO_MATCHING: ${{ inputs.fail-on-no-matching }}
INPUT_VERBOSE: ${{ inputs.verbose }}
INPUT_REPORTING: ${{ inputs.reporting }}
INPUT_GITHUB_CHECK_NAME: ${{ inputs.github-check-name }}
42 changes: 41 additions & 1 deletion scripts/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ try {
}
if (typeof value === 'string' && value.trim() !== '') {
process.stdout.write(value)
} else if (typeof value === 'number' && Number.isFinite(value)) {
process.stdout.write(String(value))
}
} catch (_) {
process.exit(0)
Expand Down Expand Up @@ -182,6 +184,10 @@ resolve_github_sha() {

clear_github_report_env() {
unset CHECKLY_GITHUB_REPORT
unset CHECKLY_GITHUB_SOURCE
unset CHECKLY_GITHUB_CHECK_NAME
unset CHECKLY_GITHUB_PULL_REQUEST_NUMBER
unset CHECKLY_GITHUB_ENVIRONMENT_URL
unset CHECKLY_GITHUB_REPOSITORY
unset CHECKLY_GITHUB_SHA
unset CHECKLY_GITHUB_RUN_ID
Expand Down Expand Up @@ -224,8 +230,26 @@ configure_deployment_environment_url() {
configure_github_report() {
local repository="$1"
local sha="$2"
local github_check_name="$3"

export CHECKLY_GITHUB_REPORT=true
export CHECKLY_GITHUB_SOURCE=checkly-action

if [[ -n "$github_check_name" ]]; then
export CHECKLY_GITHUB_CHECK_NAME="$github_check_name"
fi

if is_pull_request_event; then
local pull_request_number
pull_request_number="$(github_event_value "pull_request.number")"
if [[ -n "$pull_request_number" ]]; then
export CHECKLY_GITHUB_PULL_REQUEST_NUMBER="$pull_request_number"
fi
fi

if [[ -n "${ENVIRONMENT_URL:-}" ]]; then
export CHECKLY_GITHUB_ENVIRONMENT_URL="$ENVIRONMENT_URL"
fi

if [[ -n "$repository" ]]; then
export CHECKLY_GITHUB_REPOSITORY="$repository"
Expand Down Expand Up @@ -300,6 +324,10 @@ const accountId = process.env.CHECKLY_ACCOUNT_ID
const apiKey = process.env.CHECKLY_API_KEY

const payload = {
source: process.env.CHECKLY_GITHUB_SOURCE,
githubCheckName: process.env.CHECKLY_GITHUB_CHECK_NAME,
pullRequestNumber: process.env.CHECKLY_GITHUB_PULL_REQUEST_NUMBER,
environmentUrl: process.env.CHECKLY_GITHUB_ENVIRONMENT_URL,
repository: process.env.CHECKLY_GITHUB_REPOSITORY,
sha: process.env.CHECKLY_GITHUB_SHA,
runId: process.env.CHECKLY_GITHUB_RUN_ID,
Expand Down Expand Up @@ -353,6 +381,7 @@ cli_version="$(trim "${INPUT_CLI_VERSION:-latest}")"
working_directory="$(trim "${INPUT_WORKING_DIRECTORY:-.}")"
install_command="$(trim "${INPUT_INSTALL_COMMAND:-}")"
reporting="$(trim "${INPUT_REPORTING:-auto}")"
github_check_name="$(trim "${INPUT_GITHUB_CHECK_NAME:-}")"

case "$command_name" in
test|trigger) ;;
Expand Down Expand Up @@ -428,7 +457,7 @@ else
echo "::warning::GitHub Check reporting needs Checkly CLI 8.12.0 or newer (cli-version is '${cli_version}'). Reporting through GitHub Actions instead. Use cli-version: latest or >= 8.12.0 to enable detached GitHub Check reporting."
fi
else
configure_github_report "$github_repository" "$github_sha"
configure_github_report "$github_repository" "$github_sha" "$github_check_name"
preflight_result="$(github_report_preflight)" || preflight_result=$'false\tpreflight_crashed'
IFS=$'\t' read -r github_report_available github_report_reason <<< "$preflight_result"
github_report_reason="$(sanitize_reason "$github_report_reason")"
Expand Down Expand Up @@ -490,10 +519,21 @@ if [[ "${CHECKLY_ACTION_DRY_RUN:-}" == "1" || "${CHECKLY_ACTION_DRY_RUN:-}" == "
printf 'Reporting: GitHub Actions\n'
elif [[ "$github_check_requested" == "true" && "$github_report_available" == "true" ]]; then
printf 'Reporting: GitHub Check'
if [[ -n "${CHECKLY_GITHUB_CHECK_NAME:-}" ]]; then
printf ' "%s"' "$CHECKLY_GITHUB_CHECK_NAME"
fi
if [[ -n "${CHECKLY_GITHUB_REPOSITORY:-}" && -n "${CHECKLY_GITHUB_SHA:-}" ]]; then
printf ' for %s@%s' "$CHECKLY_GITHUB_REPOSITORY" "$CHECKLY_GITHUB_SHA"
fi
printf '\n'
printf 'GitHub metadata: source=%s' "${CHECKLY_GITHUB_SOURCE:-}"
if [[ -n "${CHECKLY_GITHUB_PULL_REQUEST_NUMBER:-}" ]]; then
printf ' pullRequestNumber=%s' "$CHECKLY_GITHUB_PULL_REQUEST_NUMBER"
fi
if [[ -n "${CHECKLY_GITHUB_ENVIRONMENT_URL:-}" ]]; then
printf ' environmentUrl=%s' "$CHECKLY_GITHUB_ENVIRONMENT_URL"
fi
printf '\n'
elif [[ "$github_check_requested" == "true" ]]; then
printf 'Reporting: GitHub Actions (GitHub Check unavailable: %s)\n' "$github_report_reason"
else
Expand Down
6 changes: 5 additions & 1 deletion scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ trap 'rm -f "$github_event_path"' EXIT
cat > "$github_event_path" <<'JSON'
{
"pull_request": {
"number": 5,
"head": {
"sha": "head123def456",
"repo": {
Expand All @@ -146,6 +147,7 @@ JSON
github_report_output="$(
INPUT_COMMAND=test \
INPUT_REPORTING=github-check \
INPUT_GITHUB_CHECK_NAME='Checkly PR code checks' \
CHECKLY_ACTION_GITHUB_REPORT_AVAILABLE=true \
GITHUB_REPOSITORY=checkly/playwright-reporter-demo \
GITHUB_SHA=merge123def456 \
Expand All @@ -160,10 +162,12 @@ github_report_output="$(
GITHUB_HEAD_REF=herve/test-checkly-action \
GITHUB_BASE_REF=main \
GITHUB_SERVER_URL=https://github.com \
ENVIRONMENT_URL=https://preview.example.com \
run_dry
)"

assert_contains "$github_report_output" "Reporting: GitHub Check for checkly/playwright-reporter-demo@head123def456"
assert_contains "$github_report_output" "Reporting: GitHub Check \"Checkly PR code checks\" for checkly/playwright-reporter-demo@head123def456"
assert_contains "$github_report_output" "GitHub metadata: source=checkly-action pullRequestNumber=5 environmentUrl=https://preview.example.com"

github_actions_output="$(
INPUT_COMMAND=test \
Expand Down
Loading