Skip to content

Commit bf7d367

Browse files
authored
Update docker.yml
1 parent 6e68877 commit bf7d367

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

.github/workflows/docker.yml

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,17 @@ jobs:
1313
DOCKER_REPO: ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPOSITORY }}
1414

1515
steps:
16-
- name: Fetch full Git history and tags
16+
- name: Checkout code
1717
uses: actions/checkout@v4
1818
with:
1919
fetch-depth: 0
2020

21-
- name: Get the latest tag
22-
id: get_tag
21+
- name: Get version from package.json
22+
id: get_version
2323
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
3027
3128
- name: Set up Docker Buildx
3229
uses: docker/setup-buildx-action@v3
@@ -37,19 +34,19 @@ jobs:
3734
username: ${{ secrets.DOCKERHUB_USERNAME }}
3835
password: ${{ secrets.DOCKERHUB_PASSWORD }}
3936

40-
- name: Check if Docker tag exists
37+
- name: Check if Docker tag exists on Docker Hub
4138
id: tag_check
4239
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
4643
4744
- name: Build and push Docker image
48-
if: steps.tag_check.outputs.exists != '200'
45+
if: steps.tag_check.outputs.status_code != '200'
4946
uses: docker/build-push-action@v6
5047
with:
5148
context: .
5249
push: true
5350
tags: |
5451
${{ env.DOCKER_REPO }}:latest
55-
${{ env.DOCKER_REPO }}:${{ env.TAG }}
52+
${{ env.DOCKER_REPO }}:${{ env.VERSION }}

0 commit comments

Comments
 (0)