Skip to content

Commit f786967

Browse files
authored
feat: create docker tag if it doesn’t really exist
1 parent 7982516 commit f786967

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

Diff for: .github/workflows/docker.yml

+9-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ jobs:
99
push_to_registry:
1010
name: Build and push Docker image to Docker Hub
1111
runs-on: ubuntu-22.04
12-
if: startsWith(github.event.ref_name, 'release-')
1312

1413
steps:
1514
- name: Check out the repo with the latest code
@@ -29,14 +28,21 @@ jobs:
2928
run: |
3029
git fetch --prune --unshallow
3130
TAG=$(git describe --tags --abbrev=0)
32-
echo $TAG
3331
echo "TAG=$TAG" >> $GITHUB_ENV
3432
33+
- name: Check if Docker tag exists
34+
id: tagCheck
35+
run: |
36+
REPO="${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPOSITORY }}"
37+
TAG_EXISTS=$(curl -s -o /dev/null -w "%{http_code}" "https://hub.docker.com/v2/repositories/${REPO}/tags/${TAG}/")
38+
echo "TAG_EXISTS=$TAG_EXISTS" >> $GITHUB_ENV
39+
3540
- name: Build and push Docker image
41+
if: env.TAG_EXISTS != '200'
3642
uses: docker/build-push-action@v6
3743
with:
3844
context: .
3945
push: true
4046
tags: |
4147
${{ secrets.DOCKERHUB_REPOSITORY }}:latest
42-
${{ secrets.DOCKERHUB_REPOSITORY }}:${{ env.TAG }}
48+
${{ secrets.DOCKERHUB_REPOSITORY }}:${{ env.TAG }}

0 commit comments

Comments
 (0)