sadpandajoe commented on code in PR #45750:
URL: https://github.com/apache/superset/pull/45750#discussion_r4384731821


##########
.github/workflows/scripts/check-branch-freshness.sh:
##########
@@ -0,0 +1,71 @@
+#!/bin/bash
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# Shared freshness gate for push-triggered workflows that serialize their
+# real work behind a static (per-branch) concurrency group with
+# cancel-in-progress: false — e.g. the Docs Deployment workflow
+# (superset-docs-deploy.yml, both up front at check-freshness and again right
+# before the deploy step at recheck-freshness) and the Docker image build
+# workflow (docker.yml, check-freshness). Writes an output declaring whether
+# BUILD_SHA is still BRANCH's current tip, so a superseded run can skip
+# cleanly at the job level instead of entering the concurrency group, where a
+# burst of pushes would otherwise queue several runs behind each other and
+# have GitHub force-cancel all but the newest pending one — the queue
+# pruning described at
+# https://docs.github.com/en/actions/using-jobs/using-concurrency, which
+# happens regardless of cancel-in-progress and is why a merely-superseded
+# run shows up as a failing "Cancelled" check instead of a clean "Skipped"
+# one.
+#
+# Required env vars:
+#   BUILD_SHA     - the commit SHA this run is building
+#   REPO          - "owner/repo" to query, e.g. github.repository
+#   OUTPUT_NAME   - the GITHUB_OUTPUT key to write, e.g. "is-current"
+#   GITHUB_OUTPUT - path to append outputs to (set by the Actions runner)
+# Optional env vars:
+#   BRANCH        - the branch whose tip BUILD_SHA is checked against;
+#                   defaults to "master"
+#   EVENT_NAME    - if "workflow_dispatch" or "pull_request", bypasses the
+#                   check and always reports current: a manual dispatch is a
+#                   deliberate, one-off action, and a pull_request build has
+#                   no branch tip to race against (PR staleness is instead
+#                   handled by that workflow's own cancel-in-progress: true)
+#   GH_TOKEN      - passed through to `gh`, needed to call the GitHub API
+
+set -euo pipefail
+
+branch="${BRANCH:-master}"
+
+if [ "${EVENT_NAME:-}" = "workflow_dispatch" ] || [ "${EVENT_NAME:-}" = 
"pull_request" ]; then
+  echo "${OUTPUT_NAME}=true" >>"$GITHUB_OUTPUT"
+  exit 0
+fi
+
+# Fail open: if the API call fails transiently, treat the run as current so a
+# network blip costs at most a redundant build rather than failing the
+# required job and skipping the build entirely.
+if ! latest_sha="$(gh api "repos/${REPO}/commits/${branch}" --jq .sha)"; then

Review Comment:
   This fail-open branch is shared with the docs deploy's `recheck-freshness` 
step, which previously failed (and so skipped the deploy) when the lookup 
errored. Now if an older run passes the early check, waits in the deploy group 
while a newer run deploys, and its recheck hits an API error here, it writes 
`still-current=true` and overwrites the newer docs — the exact case that 
recheck exists to stop. Should fail-open be limited to the docker-build gate 
(e.g. an opt-in env var), keeping the docs recheck fail-closed?



##########
.github/workflows/scripts/check-branch-freshness.test.sh:
##########
@@ -15,36 +15,42 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 #
-# Exercises check-docs-deploy-freshness.sh against a stubbed `gh`, covering
-# the dispatch-bypass, current-tip and stale-tip branches so the output
-# contract (is-current / still-current) can't silently regress. Run
-# directly, no extra tooling required:
-#   bash .github/workflows/scripts/check-docs-deploy-freshness.test.sh
+# Exercises check-branch-freshness.sh against a stubbed `gh`, covering the
+# dispatch-bypass, pull_request-bypass, current-tip, stale-tip and
+# explicit-BRANCH cases so the output contract (is-current / still-current)
+# can't silently regress. Run directly, no extra tooling required:
+#   bash .github/workflows/scripts/check-branch-freshness.test.sh
 
 set -euo pipefail
 
 script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
-script_under_test="${script_dir}/check-docs-deploy-freshness.sh"
+script_under_test="${script_dir}/check-branch-freshness.sh"
 
 failures=0
 
-# Runs the script under test with a stubbed `gh` reporting $1 as master's
-# latest sha, asserting that GITHUB_OUTPUT ends up containing exactly $4.
+# Runs the script under test with a stubbed `gh` reporting $1 as the
+# configured branch's latest sha, asserting that GITHUB_OUTPUT ends up
+# containing exactly $5 and (unless empty) that `gh` was actually called
+# against the expected branch, to catch BRANCH silently not being honored.
 run_case() {
   local case_name="$1"
   local latest_sha="$2"
   local build_sha="$3"
   local event_name="$4"
   local expected_line="$5"
+  local branch="${6:-}"
+  local expect_branch="${7:-}"
 
   local workdir
   workdir="$(mktemp -d)"
   trap 'rm -rf "${workdir}"' RETURN
 
-  # Fake `gh` that just echoes back the requested "latest" sha regardless of
-  # arguments, so the script under test never touches the network.
+  # Fake `gh` that records the requested commits path and echoes back the
+  # requested "latest" sha, so the script under test never touches the
+  # network and the branch it actually queried can be asserted on.
   cat >"${workdir}/gh" <<EOF
 #!/bin/bash
+echo "\$@" >>"${workdir}/gh-args"

Review Comment:
   The `gh` stub always succeeds, so the new fail-open path (`gh api` exits 
non-zero → warning + `is-current=true`, exit 0) has no coverage; deleting that 
whole `if ! latest_sha=...` handler still passes all six cases. Could you add a 
case where the stub exits 1 and assert the script exits 0 with `GITHUB_OUTPUT` 
containing exactly `is-current=true`?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to