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