@@ -13,20 +13,17 @@ jobs:
13
13
DOCKER_REPO : ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPOSITORY }}
14
14
15
15
steps :
16
- - name : Fetch full Git history and tags
16
+ - name : Checkout code
17
17
uses : actions/checkout@v4
18
18
with :
19
19
fetch-depth : 0
20
20
21
- - name : Get the latest tag
22
- id : get_tag
21
+ - name : Get version from package.json
22
+ id : get_version
23
23
run : |
24
- TAG=$(git describe --tags `git rev-list --tags --max-count=1`)
25
- echo "TAG=$TAG" >> $GITHUB_ENV
26
- echo "::set-output name=tag::$TAG"
27
-
28
- - name : Checkout latest tag
29
- run : git checkout tags/${{ env.TAG }}
24
+ VERSION=$(jq -r .version package.json)
25
+ echo "VERSION=$VERSION" >> $GITHUB_ENV
26
+ echo "version=$VERSION" >> $GITHUB_OUTPUT
30
27
31
28
- name : Set up Docker Buildx
32
29
uses : docker/setup-buildx-action@v3
@@ -37,19 +34,19 @@ jobs:
37
34
username : ${{ secrets.DOCKERHUB_USERNAME }}
38
35
password : ${{ secrets.DOCKERHUB_PASSWORD }}
39
36
40
- - name : Check if Docker tag exists
37
+ - name : Check if Docker tag exists on Docker Hub
41
38
id : tag_check
42
39
run : |
43
- TAG_EXISTS =$(curl -s -o /dev/null -w "%{http_code}" \
44
- https://hub.docker.com/v2/repositories/${DOCKER_REPO} /tags/${TAG }/)
45
- echo "exists=$TAG_EXISTS " >> $GITHUB_OUTPUT
40
+ STATUS_CODE =$(curl -s -o /dev/null -w "%{http_code}" \
41
+ https://hub.docker.com/v2/repositories/${{ env. DOCKER_REPO }} /tags/${{ steps.get_version.outputs.version } }/)
42
+ echo "status_code=$STATUS_CODE " >> $GITHUB_OUTPUT
46
43
47
44
- name : Build and push Docker image
48
- if : steps.tag_check.outputs.exists != '200'
45
+ if : steps.tag_check.outputs.status_code != '200'
49
46
uses : docker/build-push-action@v6
50
47
with :
51
48
context : .
52
49
push : true
53
50
tags : |
54
51
${{ env.DOCKER_REPO }}:latest
55
- ${{ env.DOCKER_REPO }}:${{ env.TAG }}
52
+ ${{ env.DOCKER_REPO }}:${{ env.VERSION }}
0 commit comments