diff --git a/.github/workflows/build-and-push.yml b/.github/workflows/build-and-push.yml index 77bc890..66d0f93 100644 --- a/.github/workflows/build-and-push.yml +++ b/.github/workflows/build-and-push.yml @@ -39,18 +39,30 @@ jobs: echo "version=$VERSION" >> $GITHUB_OUTPUT echo "Current version: $VERSION" + - name: Check if version tag exists on Docker Hub + id: check_version + run: | + if docker manifest inspect ${{ env.DOCKERHUB_REPO }}:${{ steps.version.outputs.version }} > /dev/null 2>&1; then + echo "exists=true" >> $GITHUB_OUTPUT + echo "Version ${{ steps.version.outputs.version }} already exists, skipping push" + else + echo "exists=false" >> $GITHUB_OUTPUT + echo "Version ${{ steps.version.outputs.version }} is new, will push" + fi + - name: Set up Docker Buildx + if: steps.check_version.outputs.exists == 'false' || github.event_name == 'pull_request' uses: docker/setup-buildx-action@v3 - name: Log in to Docker Hub - if: github.event_name != 'pull_request' + if: github.event_name != 'pull_request' && steps.check_version.outputs.exists == 'false' uses: docker/login-action@v3 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Log in to GitHub Container Registry - if: github.event_name != 'pull_request' + if: github.event_name != 'pull_request' && steps.check_version.outputs.exists == 'false' uses: docker/login-action@v3 with: registry: ghcr.io @@ -58,6 +70,7 @@ jobs: password: ${{ secrets.GITHUB_TOKEN }} - name: Extract metadata for Docker + if: steps.check_version.outputs.exists == 'false' || github.event_name == 'pull_request' id: meta uses: docker/metadata-action@v5 with: @@ -67,9 +80,9 @@ jobs: tags: | type=raw,value=latest,enable={{is_default_branch}} type=raw,value=${{ steps.version.outputs.version }} - type=sha,prefix= - name: Build and push + if: steps.check_version.outputs.exists == 'false' || github.event_name == 'pull_request' uses: docker/build-push-action@v5 with: context: . diff --git a/VERSION b/VERSION index 3eefcb9..7dea76e 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.0.0 +1.0.1