From eb4d457f448a332006107fd00edb02ea92e10500 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Darko=20Kri=C5=BEi=C4=87?= Date: Sun, 3 Mar 2024 21:25:58 +0100 Subject: [PATCH] Push latest on main --- .github/workflows/build.yml | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index bff75af..d582d34 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -19,15 +19,21 @@ jobs: run: docker build . --file Dockerfile --tag ghcr.io/prodyna/deployment-overview:latest # if tag, get the tag as variable - - name: Set env - run: echo "tag=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV + - name: Get tag if available + if: startsWith(github.ref, 'refs/tags/v') + run: echo "tag=${GITHUB_REF#refs/tags/*}" >> $GITHUB_ENV - # if tagged, create docker tag - - name: Create a tag for the Docker image - if: github.ref == 'refs/heads/main' - run: docker tag ghcr.io/prodyna/deployment-overview:latest ghcr.io/prodyna/deployment-overview:${{ env.tag }} + # Login to the GitHub Container Registry + - name: Login to the GitHub Container Registry + run: echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u ${{ github.actor }} --password ${{ secrets.GITHUB_TOKEN }} + + # Push latest to GitHub Container Registry + - name: Push the latest Docker image to the GitHub Container Registry + run: docker push ghcr.io/prodyna/deployment-overview:latest # if tagged, push the image to the GitHub Container Registry - - name: Push the Docker image to the GitHub Container Registry - if: github.ref == 'refs/heads/main' - run: docker push ghcr.io/prodyna/deployment-overview:${{ env.tag }} + - name: Push the tagged Docker image to the GitHub Container Registry + if: startsWith(github.ref, 'refs/tags/v') + run: | + docker tag ghcr.io/prodyna/deployment-overview:latest ghcr.io/prodyna/deployment-overview:${{ env.tag }} + docker push ghcr.io/prodyna/deployment-overview:${{ env.tag }}