rusackas commented on code in PR #45750: URL: https://github.com/apache/superset/pull/45750#discussion_r4384056159
########## .github/workflows/scripts/check-branch-freshness.sh: ########## @@ -0,0 +1,64 @@ +#!/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 + +latest_sha="$(gh api "repos/${REPO}/commits/${branch}" --jq .sha)" Review Comment: Fair point. I made the lookup fail open (0b0a7f2): if the `gh api` call fails, it warns and reports the run as current, so a blip costs at most a redundant build instead of failing the required job and skipping the build. ########## .github/workflows/docker.yml: ########## @@ -300,13 +339,18 @@ jobs: docker-build: name: docker-build - needs: [setup_matrix, changes] + needs: [setup_matrix, changes, check-freshness] # Only master pushes publish images (see scripts/docker-build-plan.sh). # Without the Docker Hub credentials (e.g. on a fork or mirror) they can # publish nothing, so they are skipped there. Version-branch pushes and # pull_request builds only load the image to validate that it builds, so - # they run everywhere. + # they run everywhere. check-freshness.outputs.is-current is always + # 'true' for pull_request (it bypasses the check there — a PR build has + # no branch tip to race against, and staleness is instead handled by + # this job's own cancel-in-progress: true below), so this only narrows + # push triggers superseded by a newer commit on the same branch. if: >- + needs.check-freshness.outputs.is-current == 'true' && Review Comment: That gap exists today too: GitHub already prunes all but the newest pending run in a concurrency group, so a Docker-changing push followed by a docs-only push loses the first build either way. This just makes it a clean skip instead of a Cancelled check. Closing it fully would mean diffing against the last built sha rather than the previous commit, which feels out of scope here. -- 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]
