Skip to content

Commit

Permalink
Read the version from Git Tag
Browse files Browse the repository at this point in the history
  • Loading branch information
nesimtunc committed Oct 13, 2024
1 parent ec2a062 commit 7ecd61c
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
name: Publish Docker Image

# Trigger this workflow only when a tag is pushed, with pattern `v*`
on:
push:
tags:
Expand All @@ -13,19 +14,29 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v2

# Extract the Git tag version, removing the 'refs/tags/' prefix
- name: Extract version from tag
id: extract_version
run: |
VERSION=${GITHUB_REF#refs/tags/}
echo "VERSION=$VERSION" >> $GITHUB_ENV
# Log in to GitHub Container Registry
- name: Log in to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

# Log in to Docker Hub
- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}

# Extract metadata (tags, labels) for Docker
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
Expand All @@ -34,22 +45,24 @@ jobs:
ghcr.io/cothings-app/cothings/cothings
cothings/web-app
# Build and push Docker image to GitHub Container Registry
- name: Build and push Docker image to GitHub Container Registry
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: |
ghcr.io/cothings-app/cothings/cothings:${{ github.ref }}
ghcr.io/cothings-app/cothings/cothings:${{ env.VERSION }}
ghcr.io/cothings-app/cothings/cothings:latest
labels: ${{ steps.meta.outputs.labels }}

# Build and push Docker image to Docker Hub
- name: Build and push Docker image to Docker Hub
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: |
cothings/web-app:${{ github.ref }}
cothings/web-app:${{ env.VERSION }}
cothings/web-app:latest
labels: ${{ steps.meta.outputs.labels }}

0 comments on commit 7ecd61c

Please sign in to comment.