Copilot commented on code in PR #923:
URL: https://github.com/apache/solr-operator/pull/923#discussion_r4762684224


##########
.github/workflows/delete-rc-docker-image.yaml:
##########
@@ -0,0 +1,141 @@
+#
+# 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.
+#
+
+name: Delete RC Docker Image
+
+# Deletes the Docker image of a release candidate from Docker Hub, once it is 
not needed anymore.
+#
+# The "Publish Docker Image" workflow publishes 
apache/solr-operator:<version>-rc<N> from the RC branch
+# rc/<version>-rc<N>. The release wizard deletes that RC branch once the RC is 
done with, either because its
+# vote failed and a new RC is started, or because the release is published. 
Deleting the RC branch triggers this
+# workflow, which deletes the matching RC image.
+#
+# It can also be run manually, for an RC image whose branch is already gone. 
Only RC image tags (vX.Y.Z-rcN)
+# are ever deleted, never release images, and never while the RC branch still 
exists.
+
+on:
+  # The delete event has no branch filters, so the job below only runs for RC 
branches.
+  delete:
+  workflow_dispatch:
+    inputs:
+      rc-image-tag:
+        description: 'RC image tag to delete from apache/solr-operator, e.g. 
v0.11.0-rc1'
+        required: true
+        type: string
+
+permissions:
+  contents: read
+
+concurrency:
+  group: delete-rc-docker-image-${{ github.event.ref || inputs.rc-image-tag }}

Review Comment:
   Publication and deletion use separate concurrency groups, so aborting an RC 
during its build can delete the image (or report 404) before the publisher 
recreates it. Use a shared, normalized per-image concurrency key in both 
workflows, including manual cleanup. Also prevent queued publishers from 
publishing after their RC branch is gone.



##########
.github/workflows/publish-docker-image.yaml:
##########
@@ -0,0 +1,246 @@
+#
+# 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.
+#
+
+name: Publish Docker Image
+
+# Builds the multi-architecture Solr Operator Docker image for a release, and 
pushes it to Docker Hub.
+# This is done by CI so that the release manager does not need personal push 
access to apache/solr-operator.
+#
+#   - Pushing an RC branch, rc/<version>-rc<N> (e.g. rc/v0.11.0-rc1), 
publishes apache/solr-operator:<version>-rc<N>.
+#     The release wizard pushes this branch with the release commit that the 
RC artifacts were built from.
+#   - Pushing a release tag, <version> (e.g. v0.11.0), publishes 
apache/solr-operator:<version>.
+#     The release wizard pushes this tag once the vote has passed, on that 
same release commit.
+#
+# Both are built from the exact commit pushed, so the Git SHA in the image is 
the release commit's.
+# Release images are never overwritten: if the release image tag already 
exists the run fails.
+# RC images are overwritten when their RC branch is (force) pushed again, 
which the release wizard only allows before the
+# vote on that RC has started. Voters' smoke tests check the Git SHA in the 
image, so they would catch a mismatched image.
+
+on:
+  push:
+    branches:
+      - 'rc/v[0-9]+.[0-9]+.[0-9]+-rc[0-9]+'
+    tags:
+      - 'v[0-9]+.[0-9]+.[0-9]+'
+
+permissions:
+  contents: read
+
+# Two runs for the same ref must never race to push the same image tag.
+concurrency:
+  group: publish-docker-image-${{ github.ref }}
+  cancel-in-progress: false
+
+env:
+  IMAGE_REPO: docker.io/apache/solr-operator
+  PLATFORMS: linux/amd64,linux/arm64
+
+jobs:
+  publish:
+    name: Build & Publish Docker Image
+    runs-on: ubuntu-latest
+    timeout-minutes: 60
+    steps:
+      # Full history, so the release tag's commit can be checked against the 
release branch below.
+      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # 
v7.0.1
+        with:
+          fetch-depth: 0
+          persist-credentials: false
+
+      # The ref name is passed through the environment rather than 
interpolated into the script body, so
+      # that a malicious ref name cannot inject shell commands.
+      - name: Determine the image tag
+        id: meta
+        env:
+          REF_TYPE: ${{ github.ref_type }}
+          REF_NAME: ${{ github.ref_name }}
+        run: |
+          set -euo pipefail
+
+          # The trigger filters are globs, so re-check the ref names strictly 
here.
+          if [[ "${REF_TYPE}" == "branch" && "${REF_NAME}" =~ 
^rc/(v([0-9]+)\.([0-9]+)\.[0-9]+)-rc[0-9]+$ ]]; then
+            VERSION="${BASH_REMATCH[1]}"
+            IMAGE_TAG="${REF_NAME#rc/}"
+          elif [[ "${REF_TYPE}" == "tag" && "${REF_NAME}" =~ 
^(v([0-9]+)\.([0-9]+)\.[0-9]+)$ ]]; then
+            VERSION="${BASH_REMATCH[1]}"
+            IMAGE_TAG="${VERSION}"
+          else
+            echo "Error: '${REF_NAME}' (${REF_TYPE}) is neither an RC branch 
(rc/vX.Y.Z-rcN) nor a release tag (vX.Y.Z)" >&2
+            exit 1
+          fi
+          MAJOR="${BASH_REMATCH[2]}"
+          MINOR="${BASH_REMATCH[3]}"
+
+          # For an annotated tag, HEAD is the tagged commit (not the tag 
object), which is what the binary reports.
+          # The release wizard and smoke tests identify the commit by its 
first 7 characters.
+          GIT_REV="$(git rev-parse HEAD)"
+
+          {
+            echo "version=${VERSION}"
+            echo "image-tag=${IMAGE_TAG}"
+            echo "image=${IMAGE_REPO}:${IMAGE_TAG}"
+            echo "docs-version=${MAJOR}_${MINOR}"
+            echo "release-branch=release-${MAJOR}.${MINOR}"
+            echo "git-rev=${GIT_REV}"
+            echo "git-sha=${GIT_REV:0:7}"
+          } >> "$GITHUB_OUTPUT"
+          echo "Publishing ${IMAGE_REPO}:${IMAGE_TAG} from commit ${GIT_REV}"
+
+      # Only a release commit, made by the release wizard, may be published as 
a release or RC image.
+      - name: Verify this is the release commit for the version
+        env:
+          VERSION: ${{ steps.meta.outputs.version }}
+        run: |
+          set -euo pipefail
+          COMMIT_VERSION="$(sed -nE 's/^[[:space:]]*Version[[:space:]]+= 
"(.*)"/\1/p' version/version.go)"
+          COMMIT_SUFFIX="$(sed -nE 's/^[[:space:]]*VersionSuffix[[:space:]]+= 
"(.*)"/\1/p' version/version.go)"
+          if [[ "${COMMIT_VERSION}" != "${VERSION}" || -n "${COMMIT_SUFFIX}" 
]]; then
+            echo "Error: version/version.go has version '${COMMIT_VERSION}' 
and suffix '${COMMIT_SUFFIX}'," >&2
+            echo "       but a release commit for ${VERSION} must have version 
'${VERSION}' and no suffix" >&2
+            exit 1
+          fi
+          echo "version/version.go is set to ${VERSION}, with no suffix"
+
+      # A release must be the RC commit that was voted on, fast-forwarded onto 
the release branch before tagging.
+      - name: Verify the release tag is on the release branch
+        if: ${{ github.ref_type == 'tag' }}
+        env:
+          RELEASE_BRANCH: ${{ steps.meta.outputs.release-branch }}
+          GIT_REV: ${{ steps.meta.outputs.git-rev }}
+        run: |
+          set -euo pipefail
+          if ! git merge-base --is-ancestor "${GIT_REV}" 
"origin/${RELEASE_BRANCH}"; then
+            echo "Error: commit ${GIT_REV} is not on ${RELEASE_BRANCH}." >&2
+            echo "       Fast-forward ${RELEASE_BRANCH} to the release commit 
before pushing the release tag." >&2
+            exit 1
+          fi
+          echo "Commit ${GIT_REV} is on ${RELEASE_BRANCH}"
+
+      # A release image must never replace one that people may already have 
pulled. An RC image may be replaced,
+      # since the RC branch is only overwritten before the vote on it starts, 
but its previous digest is recorded.
+      - name: Check whether the image tag already exists
+        id: existing
+        env:
+          IMAGE: ${{ steps.meta.outputs.image }}
+          REF_TYPE: ${{ github.ref_type }}
+        run: |
+          set -euo pipefail
+          if OUTPUT="$(docker buildx imagetools inspect "${IMAGE}" --format 
'{{json .Manifest.Digest}}' 2>&1)"; then
+            if [[ "${REF_TYPE}" == "tag" ]]; then
+              echo "Error: ${IMAGE} already exists, and release images are 
never overwritten." >&2
+              exit 1
+            fi
+            PREVIOUS_DIGEST="$(tr -d '"' <<< "${OUTPUT}")"
+            echo "::warning::${IMAGE} already exists (${PREVIOUS_DIGEST}), and 
will be overwritten with an image built from this RC branch"
+            echo "previous-digest=${PREVIOUS_DIGEST}" >> "$GITHUB_OUTPUT"
+            exit 0

Review Comment:
   Rerunning an RC workflow reaches this overwrite path even when the branch 
has not changed, including after voting has started. The wizard’s force-push 
restriction does not protect against workflow reruns, and `--pull` plus the 
binary’s current build timestamp can produce a different image from the same 
commit. Please make reruns for an already-published commit verification-only, 
and restrict replacement to an intentional RC branch update.



##########
.github/workflows/publish-docker-image.yaml:
##########
@@ -0,0 +1,246 @@
+#
+# 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.
+#
+
+name: Publish Docker Image
+
+# Builds the multi-architecture Solr Operator Docker image for a release, and 
pushes it to Docker Hub.
+# This is done by CI so that the release manager does not need personal push 
access to apache/solr-operator.
+#
+#   - Pushing an RC branch, rc/<version>-rc<N> (e.g. rc/v0.11.0-rc1), 
publishes apache/solr-operator:<version>-rc<N>.
+#     The release wizard pushes this branch with the release commit that the 
RC artifacts were built from.
+#   - Pushing a release tag, <version> (e.g. v0.11.0), publishes 
apache/solr-operator:<version>.
+#     The release wizard pushes this tag once the vote has passed, on that 
same release commit.
+#
+# Both are built from the exact commit pushed, so the Git SHA in the image is 
the release commit's.
+# Release images are never overwritten: if the release image tag already 
exists the run fails.
+# RC images are overwritten when their RC branch is (force) pushed again, 
which the release wizard only allows before the
+# vote on that RC has started. Voters' smoke tests check the Git SHA in the 
image, so they would catch a mismatched image.
+
+on:
+  push:
+    branches:
+      - 'rc/v[0-9]+.[0-9]+.[0-9]+-rc[0-9]+'
+    tags:
+      - 'v[0-9]+.[0-9]+.[0-9]+'
+
+permissions:
+  contents: read
+
+# Two runs for the same ref must never race to push the same image tag.
+concurrency:
+  group: publish-docker-image-${{ github.ref }}
+  cancel-in-progress: false
+
+env:
+  IMAGE_REPO: docker.io/apache/solr-operator
+  PLATFORMS: linux/amd64,linux/arm64
+
+jobs:
+  publish:
+    name: Build & Publish Docker Image
+    runs-on: ubuntu-latest
+    timeout-minutes: 60
+    steps:
+      # Full history, so the release tag's commit can be checked against the 
release branch below.
+      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # 
v7.0.1
+        with:
+          fetch-depth: 0
+          persist-credentials: false
+
+      # The ref name is passed through the environment rather than 
interpolated into the script body, so
+      # that a malicious ref name cannot inject shell commands.
+      - name: Determine the image tag
+        id: meta
+        env:
+          REF_TYPE: ${{ github.ref_type }}
+          REF_NAME: ${{ github.ref_name }}
+        run: |
+          set -euo pipefail
+
+          # The trigger filters are globs, so re-check the ref names strictly 
here.
+          if [[ "${REF_TYPE}" == "branch" && "${REF_NAME}" =~ 
^rc/(v([0-9]+)\.([0-9]+)\.[0-9]+)-rc[0-9]+$ ]]; then
+            VERSION="${BASH_REMATCH[1]}"
+            IMAGE_TAG="${REF_NAME#rc/}"
+          elif [[ "${REF_TYPE}" == "tag" && "${REF_NAME}" =~ 
^(v([0-9]+)\.([0-9]+)\.[0-9]+)$ ]]; then
+            VERSION="${BASH_REMATCH[1]}"
+            IMAGE_TAG="${VERSION}"
+          else
+            echo "Error: '${REF_NAME}' (${REF_TYPE}) is neither an RC branch 
(rc/vX.Y.Z-rcN) nor a release tag (vX.Y.Z)" >&2
+            exit 1
+          fi
+          MAJOR="${BASH_REMATCH[2]}"
+          MINOR="${BASH_REMATCH[3]}"
+
+          # For an annotated tag, HEAD is the tagged commit (not the tag 
object), which is what the binary reports.
+          # The release wizard and smoke tests identify the commit by its 
first 7 characters.
+          GIT_REV="$(git rev-parse HEAD)"
+
+          {
+            echo "version=${VERSION}"
+            echo "image-tag=${IMAGE_TAG}"
+            echo "image=${IMAGE_REPO}:${IMAGE_TAG}"
+            echo "docs-version=${MAJOR}_${MINOR}"
+            echo "release-branch=release-${MAJOR}.${MINOR}"
+            echo "git-rev=${GIT_REV}"
+            echo "git-sha=${GIT_REV:0:7}"
+          } >> "$GITHUB_OUTPUT"
+          echo "Publishing ${IMAGE_REPO}:${IMAGE_TAG} from commit ${GIT_REV}"
+
+      # Only a release commit, made by the release wizard, may be published as 
a release or RC image.
+      - name: Verify this is the release commit for the version
+        env:
+          VERSION: ${{ steps.meta.outputs.version }}
+        run: |
+          set -euo pipefail
+          COMMIT_VERSION="$(sed -nE 's/^[[:space:]]*Version[[:space:]]+= 
"(.*)"/\1/p' version/version.go)"
+          COMMIT_SUFFIX="$(sed -nE 's/^[[:space:]]*VersionSuffix[[:space:]]+= 
"(.*)"/\1/p' version/version.go)"
+          if [[ "${COMMIT_VERSION}" != "${VERSION}" || -n "${COMMIT_SUFFIX}" 
]]; then
+            echo "Error: version/version.go has version '${COMMIT_VERSION}' 
and suffix '${COMMIT_SUFFIX}'," >&2
+            echo "       but a release commit for ${VERSION} must have version 
'${VERSION}' and no suffix" >&2
+            exit 1
+          fi
+          echo "version/version.go is set to ${VERSION}, with no suffix"
+
+      # A release must be the RC commit that was voted on, fast-forwarded onto 
the release branch before tagging.
+      - name: Verify the release tag is on the release branch
+        if: ${{ github.ref_type == 'tag' }}
+        env:
+          RELEASE_BRANCH: ${{ steps.meta.outputs.release-branch }}
+          GIT_REV: ${{ steps.meta.outputs.git-rev }}
+        run: |
+          set -euo pipefail
+          if ! git merge-base --is-ancestor "${GIT_REV}" 
"origin/${RELEASE_BRANCH}"; then
+            echo "Error: commit ${GIT_REV} is not on ${RELEASE_BRANCH}." >&2
+            echo "       Fast-forward ${RELEASE_BRANCH} to the release commit 
before pushing the release tag." >&2
+            exit 1
+          fi
+          echo "Commit ${GIT_REV} is on ${RELEASE_BRANCH}"
+
+      # A release image must never replace one that people may already have 
pulled. An RC image may be replaced,
+      # since the RC branch is only overwritten before the vote on it starts, 
but its previous digest is recorded.
+      - name: Check whether the image tag already exists
+        id: existing
+        env:
+          IMAGE: ${{ steps.meta.outputs.image }}
+          REF_TYPE: ${{ github.ref_type }}
+        run: |
+          set -euo pipefail
+          if OUTPUT="$(docker buildx imagetools inspect "${IMAGE}" --format 
'{{json .Manifest.Digest}}' 2>&1)"; then
+            if [[ "${REF_TYPE}" == "tag" ]]; then
+              echo "Error: ${IMAGE} already exists, and release images are 
never overwritten." >&2
+              exit 1
+            fi
+            PREVIOUS_DIGEST="$(tr -d '"' <<< "${OUTPUT}")"
+            echo "::warning::${IMAGE} already exists (${PREVIOUS_DIGEST}), and 
will be overwritten with an image built from this RC branch"
+            echo "previous-digest=${PREVIOUS_DIGEST}" >> "$GITHUB_OUTPUT"
+            exit 0
+          fi
+          # Any other failure (e.g. Docker Hub being unreachable) must not be 
mistaken for the tag not existing.
+          if ! grep -qi "not found" <<< "${OUTPUT}"; then
+            echo "Error: could not check whether ${IMAGE} exists:" >&2
+            echo "${OUTPUT}" >&2
+            exit 1
+          fi
+          echo "${IMAGE} does not exist yet"
+
+      # DOCKERHUB_USER and DOCKERHUB_TOKEN are provided to the repository by 
ASF Infra.
+      - name: Log in to Docker Hub
+        env:
+          DOCKERHUB_USER: ${{ secrets.DOCKERHUB_USER }}
+          DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
+        run: |
+          set -euo pipefail
+          if [[ -z "${DOCKERHUB_USER}" || -z "${DOCKERHUB_TOKEN}" ]]; then
+            echo "Error: the DOCKERHUB_USER and DOCKERHUB_TOKEN secrets are 
not available to this workflow." >&2
+            exit 1
+          fi
+          echo "${DOCKERHUB_TOKEN}" | docker login docker.io -u 
"${DOCKERHUB_USER}" --password-stdin
+
+      # The Docker CLI on the runner already includes buildx. The Dockerfile 
cross-compiles the binary, so the
+      # images for every platform are built natively on this runner, without 
CPU emulation.
+      - name: Build and push the image
+        env:
+          IMAGE: ${{ steps.meta.outputs.image }}
+          IMAGE_TAG: ${{ steps.meta.outputs.image-tag }}
+          GIT_SHA: ${{ steps.meta.outputs.git-sha }}
+          DOCS_VERSION: ${{ steps.meta.outputs.docs-version }}
+        run: |
+          set -euo pipefail
+          docker buildx create --use --name solr-operator-release
+          docker buildx build --pull --push \

Review Comment:
   An obsolete RC run can overwrite the current candidate: after the branch 
moves from A to B and B's image is published, rerunning A checks out the 
original event SHA and reaches this unconditional push. Verification also 
expects A, so it succeeds while the image no longer matches the RC branch or 
staged artifacts, potentially during B's vote. Recheck that the remote RC 
branch still exists and points to this run's commit at publication time, and 
skip obsolete runs.



##########
.github/workflows/publish-docker-image.yaml:
##########
@@ -0,0 +1,246 @@
+#
+# 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.
+#
+
+name: Publish Docker Image
+
+# Builds the multi-architecture Solr Operator Docker image for a release, and 
pushes it to Docker Hub.
+# This is done by CI so that the release manager does not need personal push 
access to apache/solr-operator.
+#
+#   - Pushing an RC branch, rc/<version>-rc<N> (e.g. rc/v0.11.0-rc1), 
publishes apache/solr-operator:<version>-rc<N>.
+#     The release wizard pushes this branch with the release commit that the 
RC artifacts were built from.
+#   - Pushing a release tag, <version> (e.g. v0.11.0), publishes 
apache/solr-operator:<version>.
+#     The release wizard pushes this tag once the vote has passed, on that 
same release commit.
+#
+# Both are built from the exact commit pushed, so the Git SHA in the image is 
the release commit's.
+# Release images are never overwritten: if the release image tag already 
exists the run fails.
+# RC images are overwritten when their RC branch is (force) pushed again, 
which the release wizard only allows before the
+# vote on that RC has started. Voters' smoke tests check the Git SHA in the 
image, so they would catch a mismatched image.
+
+on:
+  push:
+    branches:
+      - 'rc/v[0-9]+.[0-9]+.[0-9]+-rc[0-9]+'
+    tags:
+      - 'v[0-9]+.[0-9]+.[0-9]+'
+
+permissions:
+  contents: read
+
+# Two runs for the same ref must never race to push the same image tag.
+concurrency:
+  group: publish-docker-image-${{ github.ref }}
+  cancel-in-progress: false
+
+env:
+  IMAGE_REPO: docker.io/apache/solr-operator
+  PLATFORMS: linux/amd64,linux/arm64
+
+jobs:
+  publish:
+    name: Build & Publish Docker Image

Review Comment:
   Deleting an RC branch emits a `push` event as well as a `delete` event, so 
the wizard’s cleanup also starts this publishing job. GitHub uses the 
default-branch commit for a deleted ref, causing an unnecessary failed publish 
run against the wrong commit. Skip deleted push events at the job level.



##########
.github/workflows/publish-docker-image.yaml:
##########
@@ -0,0 +1,246 @@
+#
+# 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.
+#
+
+name: Publish Docker Image
+
+# Builds the multi-architecture Solr Operator Docker image for a release, and 
pushes it to Docker Hub.
+# This is done by CI so that the release manager does not need personal push 
access to apache/solr-operator.
+#
+#   - Pushing an RC branch, rc/<version>-rc<N> (e.g. rc/v0.11.0-rc1), 
publishes apache/solr-operator:<version>-rc<N>.
+#     The release wizard pushes this branch with the release commit that the 
RC artifacts were built from.
+#   - Pushing a release tag, <version> (e.g. v0.11.0), publishes 
apache/solr-operator:<version>.
+#     The release wizard pushes this tag once the vote has passed, on that 
same release commit.
+#
+# Both are built from the exact commit pushed, so the Git SHA in the image is 
the release commit's.
+# Release images are never overwritten: if the release image tag already 
exists the run fails.
+# RC images are overwritten when their RC branch is (force) pushed again, 
which the release wizard only allows before the
+# vote on that RC has started. Voters' smoke tests check the Git SHA in the 
image, so they would catch a mismatched image.
+
+on:
+  push:
+    branches:
+      - 'rc/v[0-9]+.[0-9]+.[0-9]+-rc[0-9]+'
+    tags:
+      - 'v[0-9]+.[0-9]+.[0-9]+'
+
+permissions:
+  contents: read
+
+# Two runs for the same ref must never race to push the same image tag.
+concurrency:
+  group: publish-docker-image-${{ github.ref }}
+  cancel-in-progress: false
+
+env:
+  IMAGE_REPO: docker.io/apache/solr-operator
+  PLATFORMS: linux/amd64,linux/arm64
+
+jobs:
+  publish:
+    name: Build & Publish Docker Image
+    runs-on: ubuntu-latest
+    timeout-minutes: 60
+    steps:
+      # Full history, so the release tag's commit can be checked against the 
release branch below.
+      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # 
v7.0.1
+        with:
+          fetch-depth: 0
+          persist-credentials: false
+
+      # The ref name is passed through the environment rather than 
interpolated into the script body, so
+      # that a malicious ref name cannot inject shell commands.
+      - name: Determine the image tag
+        id: meta
+        env:
+          REF_TYPE: ${{ github.ref_type }}
+          REF_NAME: ${{ github.ref_name }}
+        run: |
+          set -euo pipefail
+
+          # The trigger filters are globs, so re-check the ref names strictly 
here.
+          if [[ "${REF_TYPE}" == "branch" && "${REF_NAME}" =~ 
^rc/(v([0-9]+)\.([0-9]+)\.[0-9]+)-rc[0-9]+$ ]]; then
+            VERSION="${BASH_REMATCH[1]}"
+            IMAGE_TAG="${REF_NAME#rc/}"
+          elif [[ "${REF_TYPE}" == "tag" && "${REF_NAME}" =~ 
^(v([0-9]+)\.([0-9]+)\.[0-9]+)$ ]]; then
+            VERSION="${BASH_REMATCH[1]}"
+            IMAGE_TAG="${VERSION}"
+          else
+            echo "Error: '${REF_NAME}' (${REF_TYPE}) is neither an RC branch 
(rc/vX.Y.Z-rcN) nor a release tag (vX.Y.Z)" >&2
+            exit 1
+          fi
+          MAJOR="${BASH_REMATCH[2]}"
+          MINOR="${BASH_REMATCH[3]}"
+
+          # For an annotated tag, HEAD is the tagged commit (not the tag 
object), which is what the binary reports.
+          # The release wizard and smoke tests identify the commit by its 
first 7 characters.
+          GIT_REV="$(git rev-parse HEAD)"
+
+          {
+            echo "version=${VERSION}"
+            echo "image-tag=${IMAGE_TAG}"
+            echo "image=${IMAGE_REPO}:${IMAGE_TAG}"
+            echo "docs-version=${MAJOR}_${MINOR}"
+            echo "release-branch=release-${MAJOR}.${MINOR}"
+            echo "git-rev=${GIT_REV}"
+            echo "git-sha=${GIT_REV:0:7}"
+          } >> "$GITHUB_OUTPUT"
+          echo "Publishing ${IMAGE_REPO}:${IMAGE_TAG} from commit ${GIT_REV}"
+
+      # Only a release commit, made by the release wizard, may be published as 
a release or RC image.
+      - name: Verify this is the release commit for the version
+        env:
+          VERSION: ${{ steps.meta.outputs.version }}
+        run: |
+          set -euo pipefail
+          COMMIT_VERSION="$(sed -nE 's/^[[:space:]]*Version[[:space:]]+= 
"(.*)"/\1/p' version/version.go)"
+          COMMIT_SUFFIX="$(sed -nE 's/^[[:space:]]*VersionSuffix[[:space:]]+= 
"(.*)"/\1/p' version/version.go)"
+          if [[ "${COMMIT_VERSION}" != "${VERSION}" || -n "${COMMIT_SUFFIX}" 
]]; then
+            echo "Error: version/version.go has version '${COMMIT_VERSION}' 
and suffix '${COMMIT_SUFFIX}'," >&2
+            echo "       but a release commit for ${VERSION} must have version 
'${VERSION}' and no suffix" >&2
+            exit 1
+          fi
+          echo "version/version.go is set to ${VERSION}, with no suffix"
+
+      # A release must be the RC commit that was voted on, fast-forwarded onto 
the release branch before tagging.
+      - name: Verify the release tag is on the release branch
+        if: ${{ github.ref_type == 'tag' }}
+        env:
+          RELEASE_BRANCH: ${{ steps.meta.outputs.release-branch }}
+          GIT_REV: ${{ steps.meta.outputs.git-rev }}
+        run: |
+          set -euo pipefail
+          if ! git merge-base --is-ancestor "${GIT_REV}" 
"origin/${RELEASE_BRANCH}"; then
+            echo "Error: commit ${GIT_REV} is not on ${RELEASE_BRANCH}." >&2
+            echo "       Fast-forward ${RELEASE_BRANCH} to the release commit 
before pushing the release tag." >&2
+            exit 1
+          fi
+          echo "Commit ${GIT_REV} is on ${RELEASE_BRANCH}"
+
+      # A release image must never replace one that people may already have 
pulled. An RC image may be replaced,
+      # since the RC branch is only overwritten before the vote on it starts, 
but its previous digest is recorded.
+      - name: Check whether the image tag already exists
+        id: existing
+        env:
+          IMAGE: ${{ steps.meta.outputs.image }}
+          REF_TYPE: ${{ github.ref_type }}
+        run: |
+          set -euo pipefail
+          if OUTPUT="$(docker buildx imagetools inspect "${IMAGE}" --format 
'{{json .Manifest.Digest}}' 2>&1)"; then
+            if [[ "${REF_TYPE}" == "tag" ]]; then
+              echo "Error: ${IMAGE} already exists, and release images are 
never overwritten." >&2
+              exit 1

Review Comment:
   If publication succeeds but the subsequent anonymous pull, verification, or 
summary fails, re-running the failed job always stops here because the release 
tag now exists. The documented recovery path therefore cannot complete without 
deleting the published image. Keep the no-overwrite protection, but make 
post-publication verification independently retryable, for example in a 
separate job.



-- 
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