Skip to content

Commit

Permalink
feat: Added version and git short sha support
Browse files Browse the repository at this point in the history
github action workflow will tag the image with
a human readable version and git shortSha
version
  • Loading branch information
Kumar Gopal committed Nov 25, 2024
1 parent e88b0b1 commit 52e3405
Showing 1 changed file with 33 additions and 8 deletions.
41 changes: 33 additions & 8 deletions .github/workflows/docker_build_push_action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ name: Build and Push Docker Image

on:
push:
paths:
- 'openaictl/**'
- '.github/workflows/docker-build-and-push.yml'
branches:
- main

Expand All @@ -17,8 +14,31 @@ jobs:
# Checkout the repository
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0 # Ensure all tags are fetched

# Fetch the latest Git tag
- name: Get latest Git tag
id: git-tag
run: |
TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
echo "TAG=$TAG" >> $GITHUB_ENV
# Get the Git short SHA
- name: Get Git short SHA
id: git-sha
run: echo "SHORT_SHA=$(git rev-parse --short HEAD)" >> $GITHUB_ENV

# Increment the patch version and prepare the new tag
- name: Increment version
id: increment-version
run: |
OLD_TAG=${{ env.TAG }}
NEW_TAG=$(echo $OLD_TAG | awk -F. -v OFS=. '{$3+=1; print}')
echo "NEW_TAG=$NEW_TAG" >> $GITHUB_ENV
echo "NEW_TAG_SHORT=$NEW_TAG-${{ env.SHORT_SHA }}" >> $GITHUB_ENV
# Set up Docker Buildx for multi-platform builds
# Set up Docker Buildx
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

Expand All @@ -36,8 +56,13 @@ jobs:
push: true
tags: |
gshiva/openaictl:latest
gshiva/openaictl:${{ github.sha }}
gshiva/openaictl:${{ env.NEW_TAG }}
gshiva/openaictl:${{ env.NEW_TAG_SHORT }}
# Optionally add QEMU for cross-platform builds
- name: Install QEMU for ARM builds
uses: docker/setup-qemu-action@v2
# Create and push the new Git tag
- name: Create and push Git tag
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag -a ${{ env.NEW_TAG }} -m "Release ${{ env.NEW_TAG }}"
git push origin ${{ env.NEW_TAG }}

0 comments on commit 52e3405

Please sign in to comment.