feat: tag several images; find the pushed sha tag (full or 8 characters)
test / test (push) Successful in 5s
test / test (push) Successful in 5s
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
a5b65dd406
commit
6b33877b62
+4
-4
@@ -17,10 +17,10 @@ inputs:
|
||||
description: File to read the first-release version from.
|
||||
default: ''
|
||||
image:
|
||||
description: Image to tag, e.g. git.extant2000.com/extant2000/app. Empty = no image.
|
||||
description: Image(s) to tag, space or newline separated, e.g. git.extant2000.com/extant2000/app. Empty = no image.
|
||||
default: ''
|
||||
image-source-tag:
|
||||
description: Already pushed tag to copy (default the first 8 characters of sha).
|
||||
description: Already pushed tag to copy (default the full sha, else its first 8 characters).
|
||||
default: ''
|
||||
registry-user:
|
||||
default: extant2000git
|
||||
@@ -59,13 +59,13 @@ runs:
|
||||
- if: inputs.image != '' && steps.release.outputs.version != '' && inputs.dry-run != 'true'
|
||||
shell: bash
|
||||
env:
|
||||
IMAGE: ${{ inputs.image }}
|
||||
IMAGES: ${{ inputs.image }}
|
||||
SOURCE_TAG: ${{ inputs.image-source-tag }}
|
||||
SHA: ${{ inputs.sha }}
|
||||
VERSION_TAG: ${{ steps.release.outputs.tag }}
|
||||
REGISTRY_USER: ${{ inputs.registry-user }}
|
||||
REGISTRY_TOKEN: ${{ inputs.registry-token }}
|
||||
run: SOURCE_TAG=${SOURCE_TAG:-${SHA::8}} bash "${{ github.action_path }}/image-tag.sh"
|
||||
run: bash "${{ github.action_path }}/image-tag.sh"
|
||||
- if: inputs.npm-token != '' && steps.release.outputs.version != '' && inputs.dry-run != 'true'
|
||||
shell: bash
|
||||
env:
|
||||
|
||||
+22
-10
@@ -1,16 +1,28 @@
|
||||
#!/usr/bin/env bash
|
||||
# Pushes IMAGE:VERSION_TAG next to the already pushed IMAGE:SOURCE_TAG.
|
||||
# Environment: IMAGE, SOURCE_TAG, VERSION_TAG, REGISTRY_USER, REGISTRY_TOKEN (never printed).
|
||||
# Pushes IMAGE:VERSION_TAG next to the already pushed IMAGE:<source> for each
|
||||
# image in IMAGES (space or newline separated). Source = SOURCE_TAG when set,
|
||||
# else the full SHA, else its first 8 characters (whichever exists).
|
||||
# Environment: IMAGES, SHA, SOURCE_TAG, VERSION_TAG, REGISTRY_USER, REGISTRY_TOKEN (never printed).
|
||||
set -euo pipefail
|
||||
: "${IMAGE:?}" "${SOURCE_TAG:?}" "${VERSION_TAG:?}" "${REGISTRY_USER:?}" "${REGISTRY_TOKEN:?}"
|
||||
: "${IMAGES:?}" "${VERSION_TAG:?}" "${REGISTRY_USER:?}" "${REGISTRY_TOKEN:?}"
|
||||
if ! command -v docker >/dev/null 2>&1; then
|
||||
curl -fsSL https://download.docker.com/linux/static/stable/x86_64/docker-27.5.1.tgz | tar xz -C /tmp
|
||||
install /tmp/docker/docker /usr/local/bin/docker
|
||||
fi
|
||||
REGISTRY=${IMAGE%%/*}
|
||||
printf '%s' "$REGISTRY_TOKEN" | docker login "$REGISTRY" -u "$REGISTRY_USER" --password-stdin >/dev/null
|
||||
trap 'docker logout "$REGISTRY" >/dev/null 2>&1 || true' EXIT
|
||||
docker pull -q "$IMAGE:$SOURCE_TAG"
|
||||
docker tag "$IMAGE:$SOURCE_TAG" "$IMAGE:$VERSION_TAG"
|
||||
for i in 1 2 3; do docker push -q "$IMAGE:$VERSION_TAG" && break; [ "$i" = 3 ] && exit 1; sleep 10; done
|
||||
echo "pushed $IMAGE:$VERSION_TAG = $IMAGE:$SOURCE_TAG"
|
||||
logged=""
|
||||
trap 'for r in $logged; do docker logout "$r" >/dev/null 2>&1 || true; done' EXIT
|
||||
for IMAGE in $IMAGES; do
|
||||
REGISTRY=${IMAGE%%/*}
|
||||
case " $logged " in *" $REGISTRY "*) ;; *)
|
||||
printf '%s' "$REGISTRY_TOKEN" | docker login "$REGISTRY" -u "$REGISTRY_USER" --password-stdin >/dev/null
|
||||
logged="$logged $REGISTRY" ;;
|
||||
esac
|
||||
src=""
|
||||
for cand in ${SOURCE_TAG:-} ${SHA:+$SHA ${SHA:0:8}}; do
|
||||
if docker pull -q "$IMAGE:$cand" >/dev/null 2>&1; then src=$cand; break; fi
|
||||
done
|
||||
[ -n "$src" ] || { echo "no pushed tag for $IMAGE (tried ${SOURCE_TAG:-} ${SHA:-} ${SHA:0:8})" >&2; exit 1; }
|
||||
docker tag "$IMAGE:$src" "$IMAGE:$VERSION_TAG"
|
||||
for i in 1 2 3; do docker push -q "$IMAGE:$VERSION_TAG" >/dev/null && break; [ "$i" = 3 ] && exit 1; sleep 10; done
|
||||
echo "pushed $IMAGE:$VERSION_TAG = $IMAGE:$src"
|
||||
done
|
||||
|
||||
+1
-1
@@ -194,7 +194,7 @@ main() {
|
||||
fi
|
||||
compute "$SHA"
|
||||
if [ "$RELEASED" != true ]; then
|
||||
log "no release: ${TAG:+$SHA is already $TAG}${TAG:-no commits since v$PREVIOUS}"
|
||||
if [ -n "$TAG" ]; then log "no release: $SHA is already $TAG"; else log "no release: no counted commits since v$PREVIOUS"; fi
|
||||
emit; return 0
|
||||
fi
|
||||
log "release $TAG ($BUMP${PREVIOUS:+ from v$PREVIOUS}) at $SHA"
|
||||
|
||||
Reference in New Issue
Block a user