Skip to content

Commit 2ad6051

Browse files
Copilotwdconinc
andauthored
Rewrite digests step to loop over architecture artifacts dynamically (#73)
* Initial plan * Rewrite digests step to loop over architecture artifacts and use 'all' output Co-authored-by: wdconinc <4656391+wdconinc@users.noreply.github.com> * Fix leading space issue and use nullglob for glob pattern handling Co-authored-by: wdconinc <4656391+wdconinc@users.noreply.github.com> * Add error handling when no digest files are found Co-authored-by: wdconinc <4656391+wdconinc@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: wdconinc <4656391+wdconinc@users.noreply.github.com>
1 parent 2f97229 commit 2ad6051

File tree

1 file changed

+53
-25
lines changed

1 file changed

+53
-25
lines changed

.github/workflows/build-push.yml

Lines changed: 53 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -272,29 +272,42 @@ jobs:
272272
- name: Analyze digest artifacts
273273
id: digests
274274
run: |
275-
# Read the digests from the files
276-
DIGEST_AMD64=$(cat /tmp/digests/${{ matrix.BUILD_IMAGE }}-amd64.digest)
277-
if [ -f /tmp/digests/${{ matrix.BUILD_IMAGE }}-arm64.digest ]; then
278-
DIGEST_ARM64=$(cat /tmp/digests/${{ matrix.BUILD_IMAGE }}-arm64.digest)
279-
else
280-
DIGEST_ARM64=""
275+
# Loop over all available architecture artifacts
276+
ALL_DIGESTS=""
277+
FIRST_DIGEST=""
278+
shopt -s nullglob
279+
for digest_file in /tmp/digests/${{ matrix.BUILD_IMAGE }}-*.digest; do
280+
DIGEST=$(cat "$digest_file")
281+
echo "Found digest: $DIGEST"
282+
if [ -z "$ALL_DIGESTS" ]; then
283+
ALL_DIGESTS="$DIGEST"
284+
else
285+
ALL_DIGESTS="$ALL_DIGESTS $DIGEST"
286+
fi
287+
if [ -z "$FIRST_DIGEST" ]; then
288+
FIRST_DIGEST="$DIGEST"
289+
fi
290+
done
291+
shopt -u nullglob
292+
# Check if at least one digest was found
293+
if [ -z "$FIRST_DIGEST" ]; then
294+
echo "Error: No digest files found"
295+
exit 1
281296
fi
282-
# Get the base image name from the digests (they'll be the same)
283-
REGISTRY_IMAGE_TAG=$(echo $DIGEST_AMD64 | cut -d'@' -f1)
297+
# Get the base image name from the first digest
298+
REGISTRY_IMAGE_TAG=$(echo $FIRST_DIGEST | cut -d'@' -f1)
284299
REGISTRY_IMAGE=$(echo $REGISTRY_IMAGE_TAG | cut -d':' -f1)
285300
REGISTRY=$(echo $REGISTRY_IMAGE | cut -d'/' -f1-2)
286301
IMAGE=$(echo $REGISTRY_IMAGE | cut -d'/' -f3)
287302
TAG=$(echo $REGISTRY_IMAGE_TAG | cut -d':' -f2)
288303
echo "Registry Name: $REGISTRY"
289304
echo "Image Name: $IMAGE"
290305
echo "Tag Name: $TAG"
291-
echo "AMD64 Digest: $DIGEST_AMD64"
292-
echo "ARM64 Digest: $DIGEST_ARM64"
306+
echo "All Digests: $ALL_DIGESTS"
293307
echo "registry=$REGISTRY" >> $GITHUB_OUTPUT
294308
echo "image=$IMAGE" >> $GITHUB_OUTPUT
295309
echo "tag=$TAG" >> $GITHUB_OUTPUT
296-
echo "amd64=$DIGEST_AMD64" >> $GITHUB_OUTPUT
297-
echo "arm64=$DIGEST_ARM64" >> $GITHUB_OUTPUT
310+
echo "all=$ALL_DIGESTS" >> $GITHUB_OUTPUT
298311
- name: Extract Docker metadata for final tags
299312
id: meta
300313
uses: docker/metadata-action@v5
@@ -316,8 +329,7 @@ jobs:
316329
# Create the manifest list and tag it with the final tags
317330
docker buildx imagetools create \
318331
$TAG_ARGS \
319-
${{ steps.digests.outputs.amd64 }} \
320-
${{ steps.digests.outputs.arm64 }}
332+
${{ steps.digests.outputs.all }}
321333
322334
eic:
323335
name: Build ${{ matrix.BUILD_IMAGE }}${{ matrix.ENV }} on ${{ matrix.arch }}
@@ -511,25 +523,42 @@ jobs:
511523
- name: Analyze digest artifacts
512524
id: digests
513525
run: |
514-
# Read the digests from the files
515-
DIGEST_AMD64=$(cat /tmp/digests/amd64.digest)
516-
DIGEST_ARM64=$(cat /tmp/digests/arm64.digest)
517-
# Get the base image name from the digests (they'll be the same)
518-
REGISTRY_IMAGE_TAG=$(echo $DIGEST_AMD64 | cut -d'@' -f1)
526+
# Loop over all available architecture artifacts
527+
ALL_DIGESTS=""
528+
FIRST_DIGEST=""
529+
shopt -s nullglob
530+
for digest_file in /tmp/digests/*.digest; do
531+
DIGEST=$(cat "$digest_file")
532+
echo "Found digest: $DIGEST"
533+
if [ -z "$ALL_DIGESTS" ]; then
534+
ALL_DIGESTS="$DIGEST"
535+
else
536+
ALL_DIGESTS="$ALL_DIGESTS $DIGEST"
537+
fi
538+
if [ -z "$FIRST_DIGEST" ]; then
539+
FIRST_DIGEST="$DIGEST"
540+
fi
541+
done
542+
shopt -u nullglob
543+
# Check if at least one digest was found
544+
if [ -z "$FIRST_DIGEST" ]; then
545+
echo "Error: No digest files found"
546+
exit 1
547+
fi
548+
# Get the base image name from the first digest
549+
REGISTRY_IMAGE_TAG=$(echo $FIRST_DIGEST | cut -d'@' -f1)
519550
REGISTRY_IMAGE=$(echo $REGISTRY_IMAGE_TAG | cut -d':' -f1)
520551
REGISTRY=$(echo $REGISTRY_IMAGE | cut -d'/' -f1-2)
521552
IMAGE=$(echo $REGISTRY_IMAGE | cut -d'/' -f3)
522553
TAG=$(echo $REGISTRY_IMAGE_TAG | cut -d':' -f2)
523554
echo "Registry Name: $REGISTRY"
524555
echo "Image Name: $IMAGE"
525556
echo "Tag Name: $TAG"
526-
echo "AMD64 Digest: $DIGEST_AMD64"
527-
echo "ARM64 Digest: $DIGEST_ARM64"
557+
echo "All Digests: $ALL_DIGESTS"
528558
echo "registry=$REGISTRY" >> $GITHUB_OUTPUT
529559
echo "image=$IMAGE" >> $GITHUB_OUTPUT
530560
echo "tag=$TAG" >> $GITHUB_OUTPUT
531-
echo "amd64=$DIGEST_AMD64" >> $GITHUB_OUTPUT
532-
echo "arm64=$DIGEST_ARM64" >> $GITHUB_OUTPUT
561+
echo "all=$ALL_DIGESTS" >> $GITHUB_OUTPUT
533562
- name: Extract Docker metadata for final tags
534563
id: meta
535564
uses: docker/metadata-action@v5
@@ -551,5 +580,4 @@ jobs:
551580
# Create the manifest list and tag it with the final tags
552581
docker buildx imagetools create \
553582
$TAG_ARGS \
554-
${{ steps.digests.outputs.amd64 }} \
555-
${{ steps.digests.outputs.arm64 }}
583+
${{ steps.digests.outputs.all }}

0 commit comments

Comments
 (0)