From d586cd8194ffc241dc1b6ba5e9101aee8667857a Mon Sep 17 00:00:00 2001
From: John Wesley Walker III <81404201+jww3@users.noreply.github.com>
Date: Tue, 20 Feb 2024 20:18:06 +0100
Subject: [PATCH] Update update-test-ubuntu-git.yml

---
 .github/workflows/update-test-ubuntu-git.yml | 23 ++++++++++----------
 1 file changed, 11 insertions(+), 12 deletions(-)

diff --git a/.github/workflows/update-test-ubuntu-git.yml b/.github/workflows/update-test-ubuntu-git.yml
index b5ddfe4..f7ce8c2 100644
--- a/.github/workflows/update-test-ubuntu-git.yml
+++ b/.github/workflows/update-test-ubuntu-git.yml
@@ -1,4 +1,4 @@
-name: Publishes the test-ubuntu-git Container Image
+name: Publish test-ubuntu-git Container
 
 on:
   # Use an on demand workflow trigger.  
@@ -7,7 +7,7 @@ on:
   workflow_dispatch:
     inputs:
       publish:
-        description:  'Publish to ghcr.io?'
+        description:  'Publish to ghcr.io? (main branch only)'
         type: boolean
         required: true
         default: false
@@ -37,12 +37,10 @@ jobs:
           username: ${{ github.actor }}
           password: ${{ secrets.GITHUB_TOKEN }}
 
-      # Use `docker/metadata-action` to preserve tags and labels that exist on the GHCR.io container image. 
-      # - name: Extract metadata (tags, labels) for Docker
-      #   id: meta
-      #   uses: docker/metadata-action@v5.5.1
-      #   with:
-      #     images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
+      - name: Format Timestamp
+        id: timestamp
+        # Use `date` with a custom format to achieve the key=value format GITHUB_OUTPUT expects.
+        run: date -u "+now=%y%m%d.%H%M%S.%3NZ" >> "$GITHUB_OUTPUT"
 
       # Use `docker/build-push-action` to build (and optionally publish) the image. 
       - name: Build and push Docker image
@@ -50,7 +48,8 @@ jobs:
         with:
           context: .
           file: images/test-ubuntu-git.Dockerfile
-          push: ${{ inputs.publish }}
-          tags:  ${{ env.IMAGE_NAME }}:sha-${{ env.GITHUB_SHA }}
-          # tags: ${{ steps.meta.outputs.tags }}
-          # labels: ${{ steps.meta.outputs.labels }}
+          # For now, attempts to push to ghcr.io must target the `main` branch.
+          # In the future, consider also allowing attempts from `releases/*` branches.
+          push: ${{ inputs.publish && github.ref_name == 'main' }}
+          tags: |
+            ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.ref_name }}.${{ steps.timestamp.outputs.now }}