Skip to content

Commit

Permalink
Added build distance as number of commits in ghcr tag
Browse files Browse the repository at this point in the history
  • Loading branch information
saisab29 committed Dec 16, 2024
1 parent 5c19813 commit 56b0985
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 22 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.git
.gitignore
Dockerfile
node_modules/
**/__tests__
32 changes: 10 additions & 22 deletions .github/workflows/publish-ghcr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,32 +25,20 @@ jobs:
with:
fetch-depth: 0

- name: Get latest tag
id: get_latest_tag
run: |
# Get the latest tag, sorted by version
LATEST_TAG=$(git describe --tags --abbrev=0)
echo "latest_tag=${LATEST_TAG}" >> $GITHUB_OUTPUT
- name: Generate version
id: version
- name: Get latest tag and commit distance
id: get_version_info
run: |
# Get the latest tag
LATEST_TAG=${{ steps.get_latest_tag.outputs.latest_tag }}
# Remove 'v' prefix and split version
VERSION_PARTS=($(echo "${LATEST_TAG#v}" | tr '.' ' '))
LATEST_TAG=$(git describe --tags --abbrev=0)
# Extract parts or default to 0
MAJOR=${VERSION_PARTS[0]:-0}
MINOR=${VERSION_PARTS[1]:-0}
PATCH=${VERSION_PARTS[2]:-0}
# Remove 'v' prefix from latest tag
BASE_VERSION=${LATEST_TAG#v}
# Increment patch version
PATCH=$((PATCH + 1))
# Get the number of commits since the last tag
COMMIT_DISTANCE=$(git rev-list --count ${LATEST_TAG}..HEAD)
# Construct new version
NEW_VERSION="v${MAJOR}.${MINOR}.${PATCH}"
# Construct new version with build number
NEW_VERSION="v${BASE_VERSION}-build${COMMIT_DISTANCE}"
echo "version=${NEW_VERSION}" >> $GITHUB_OUTPUT
echo "Generated version: ${NEW_VERSION}"
Expand All @@ -68,7 +56,7 @@ jobs:
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=${{ steps.version.outputs.version }}
type=raw,value=${{ steps.get_version_info.outputs.version }}
- name: Build and push Docker image
id: push
Expand Down

0 comments on commit 56b0985

Please sign in to comment.