From 2ca1d2e145f1036d82b52fcc76448291300149d8 Mon Sep 17 00:00:00 2001 From: Aditya Sheth Date: Thu, 22 Oct 2026 10:19:12 +0530 Subject: [PATCH] Optionally start/stop the CI k8s sandbox next to the sandbox label With SANDBOX_K8S_TRIGGER=true (passed by the calling workflow), adding the plain `sandbox` label on needs_sandbox also dispatches sandbox.yml (start), and removing it on stop_sandbox dispatches it with stop: a GITHUB_TOKEN label change starts no workflow. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01A2bggq7D1jK3hGMp87ohdc --- entrypoint.sh | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/entrypoint.sh b/entrypoint.sh index 91c3f11..cbefbcf 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -59,6 +59,19 @@ ci_k8s_request() { # ci_k8s_request : start a CI k8s run of this -d "{\"ref\":\"${ref}\",\"inputs\":{\"pr\":\"${number}\"}}" \ "${URI}/repos/${GITHUB_REPOSITORY}/actions/workflows/${1}/dispatches" || true } + +# Likewise for the plain `sandbox` label: when SANDBOX_K8S_TRIGGER is "true", adding or +# removing it here also starts or stops the CI k8s sandbox (sandbox.yml). Never fails the +# action. +sandbox_k8s_request() { # sandbox_k8s_request : start or stop this PR's CI k8s sandbox + [[ "${SANDBOX_K8S_TRIGGER:-false}" == "true" ]] || return 0 + local ref + ref=$(jq -r '.repository.default_branch // "master"' "$GITHUB_EVENT_PATH") + curl -sSL -o /dev/null -w "dispatch sandbox.yml $1: HTTP %{http_code}\n" \ + -H "${AUTH_HEADER}" -H "${API_HEADER}" -X POST -H "Content-Type: application/json" \ + -d "{\"ref\":\"${ref}\",\"inputs\":{\"pr\":\"${number}\",\"action\":\"${1}\"}}" \ + "${URI}/repos/${GITHUB_REPOSITORY}/actions/workflows/sandbox.yml/dispatches" || true +} # -------------------------------------------------------------------------------------- # action @@ -315,6 +328,7 @@ elif [[ $comment_body =~ ^(e2e_)?needs_sandbox(:(eu|gov|ca|uae|wu|ap))?(:(dev|([ add_label "sandbox :australia:" else add_label "sandbox" + sandbox_k8s_request start fi fi fi @@ -324,6 +338,7 @@ if [[ $comment_body == "stop_sandbox" ]]; then case $label in sandbox) remove_label "sandbox" + sandbox_k8s_request stop ;; "sandbox :eu:") remove_label "sandbox%20:eu:"