This is an automated email from the ASF dual-hosted git repository.

asf-gitbox-commits pushed a commit to branch HIVE-29591-publish-test
in repository https://gitbox.apache.org/repos/asf/hive.git

commit be04f5587baa55fd5b239511c34cfe0687859cd3
Author: Laszlo Bodor <[email protected]>
AuthorDate: Thu Nov 12 15:26:38 2026 +0100

    Precommit image workflow: a change that does not touch the Dockerfile does 
not need a new version
    
    When the tag is published already, the workflow fails only if the 
Dockerfile changed (against
    the target branch of a PR, or the previous head of a push); otherwise it 
builds the image but
    skips publishing it. A manual run with an existing tag still fails.
    
    Co-Authored-By: Claude Code <[email protected]>
---
 .github/workflows/precommit-image.yml  | 33 +++++++++++++++++++++++++++------
 dev-support/docker/ci/runner/README.md |  4 +++-
 2 files changed, 30 insertions(+), 7 deletions(-)

diff --git a/.github/workflows/precommit-image.yml 
b/.github/workflows/precommit-image.yml
index e32e12b0b5e..f97a2da4679 100644
--- a/.github/workflows/precommit-image.yml
+++ b/.github/workflows/precommit-image.yml
@@ -49,23 +49,44 @@ jobs:
         uses: actions/checkout@v6
         with:
           persist-credentials: false
+          # On a PR, HEAD is the PR merged into its target branch, and HEAD^1 
is the target branch.
+          fetch-depth: 2
 
-      - name: Check that the tag is not published yet
+      # A published tag is never overwritten. When the tag is published 
already, a change of the
+      # Dockerfile needs a new version; any other change (e.g. of this 
workflow) does not publish.
+      - name: Check the tag
         id: tag
         env:
           INPUT_TAG: ${{ github.event.inputs.tag }}
+          BEFORE: ${{ github.event.before }}
         run: |
-          version=$(sed -n 's/^LABEL 
org.opencontainers.image.version="\(.*\)"$/\1/p' 
dev-support/docker/ci/runner/Dockerfile)
+          dockerfile=dev-support/docker/ci/runner/Dockerfile
+          version=$(sed -n 's/^LABEL 
org.opencontainers.image.version="\(.*\)"$/\1/p' "$dockerfile")
           image=apache/hive-ci-runner:${INPUT_TAG:-$version}
           if [[ $image == *: ]]; then
             echo "::error::No org.opencontainers.image.version label in the 
Dockerfile"
             exit 1
           fi
+          publish=true
           if docker manifest inspect "$image" > /dev/null 2>&1; then
-            echo "::error::$image is already published, and a published tag is 
never overwritten. Bump org.opencontainers.image.version in the Dockerfile (or 
pick another tag for a manual run)."
-            exit 1
+            base=
+            if [[ -z $INPUT_TAG ]]; then
+              case $GITHUB_EVENT_NAME in
+                pull_request) base=HEAD^1 ;;
+                push) [[ $BEFORE =~ ^0+$ ]] || base=$BEFORE ;;
+              esac
+            fi
+            if [[ -z $base ]] \
+                || ! { git cat-file -e "$base^{commit}" 2> /dev/null || git 
fetch -q --depth=1 origin "$base"; } \
+                || ! git diff --quiet "$base" HEAD -- "$dockerfile"; then
+              echo "::error::$image is already published, and a published tag 
is never overwritten. Bump org.opencontainers.image.version in the Dockerfile 
(or pick another tag for a manual run)."
+              exit 1
+            fi
+            echo "::notice::$image is already published and the Dockerfile did 
not change: not publishing it again."
+            publish=false
           fi
           echo "image=$image" >> "$GITHUB_OUTPUT"
+          echo "publish=$publish" >> "$GITHUB_OUTPUT"
 
       - name: Set up QEMU
         uses: 
docker/setup-qemu-action@99012661954931238ded8c8b007157a8430204e1 # v4.4.0
@@ -84,14 +105,14 @@ jobs:
         run: docker images hive-ci-runner:test
 
       - name: Login to Docker Hub
-        if: github.event_name != 'pull_request' && github.repository == 
'apache/hive'
+        if: steps.tag.outputs.publish == 'true' && github.event_name != 
'pull_request' && github.repository == 'apache/hive'
         uses: docker/login-action@8aa5831fb8d48d8f76594c7ddde61ae58019f550 # 
v4.8.0
         with:
           username: ${{ secrets.DOCKERHUB_USER }}
           password: ${{ secrets.DOCKERHUB_TOKEN }}
 
       - name: Publish the image
-        if: github.event_name != 'pull_request' && github.repository == 
'apache/hive'
+        if: steps.tag.outputs.publish == 'true' && github.event_name != 
'pull_request' && github.repository == 'apache/hive'
         uses: 
docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7.4.0
         with:
           context: ./dev-support/docker/ci/runner/
diff --git a/dev-support/docker/ci/runner/README.md 
b/dev-support/docker/ci/runner/README.md
index aaf413d268f..a686593d1a8 100644
--- a/dev-support/docker/ci/runner/README.md
+++ b/dev-support/docker/ci/runner/README.md
@@ -41,7 +41,9 @@ the workflow publishes the image for `linux/amd64` and 
`linux/arm64` as
 `apache/hive-ci-runner:<version>`, where `<version>` is the 
`org.opencontainers.image.version`
 label of the Dockerfile.
 
-A published tag is never overwritten: the workflow fails if the tag already 
exists. The
+A published tag is never overwritten: the workflow fails if the Dockerfile 
changed but its
+version is a tag that already exists. A change that does not touch the 
Dockerfile (e.g. of the
+workflow) needs no new version: the workflow builds the image but does not 
publish it. The
 Jenkinsfile pins the tag in `precommitImage`, so a new image is only used once 
a commit bumps
 that pin.
 

Reply via email to