Skip to content

Commit

Permalink
chore: fix auto versioning
Browse files Browse the repository at this point in the history
  • Loading branch information
jcmelati committed Jan 15, 2025
1 parent e8bf28d commit 8ec1d42
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions .github/workflows/auto-version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,21 @@ jobs:
uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
token: ${{ secrets.GITHUB_TOKEN }}

- name: Get version info
id: get_version_info
run: |
git config --local user.email "${GITHUB_ACTOR}@users.noreply.github.com"
git config --local user.name "${GITHUB_ACTOR}"
# Handle both PR and push events for branch name
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
EVENT_NAME="${{ github.event_name }}"
if [[ "$EVENT_NAME" == "pull_request" ]]; then
BRANCH_NAME="${{ github.event.pull_request.head.ref }}"
else
BRANCH_NAME=${GITHUB_REF#refs/heads/}
BRANCH_NAME="${GITHUB_REF#refs/heads/}"
fi
# Determine branch type prefix first
Expand All @@ -51,9 +56,19 @@ jobs:
else
PREFIX="build"
fi
# Get latest version tag globally, ignoring branch prefixes
LATEST_TAG=$(git tag --sort=-v:refname | grep -E "^v[0-9]+\.[0-9]+\.[0-9]+" | head -n1 || echo "v0.0.0")
echo "Available tags:"
if ! git tag --list | grep -q "^v"; then
echo "No version tags found, creating initial tag v0.0.1"
git tag -a "v0.0.1" -m "Initial version"
git push origin v0.0.1
LATEST_TAG="v0.0.1"
else
git tag --sort=-v:refname
echo "Filtered tags:"
git tag --sort=-v:refname | grep -E "^v[0-9]+\.[0-9]+\.[0-9]+" || echo "No matching tags"
LATEST_TAG=$(git tag --sort=-v:refname | grep -E "^v[0-9]+\.[0-9]+\.[0-9]+" | head -n1 || echo "v0.0.1")
fi
COMMIT_SHA=$(git rev-parse --short HEAD)
PR_NUMBER=${{ github.event.pull_request.number }}
COMMIT_MSG=$(git log -1 --pretty=%B)
Expand Down Expand Up @@ -86,6 +101,8 @@ jobs:
VERSION=${LATEST_TAG#v}
IFS='.' read -ra VERSION_PARTS <<< "$VERSION"
echo "current_version=${VERSION}" >> $GITHUB_OUTPUT
# Version increment logic
case $BUMP_TYPE in
"major")
Expand Down Expand Up @@ -119,12 +136,8 @@ jobs:
fi
echo "new_version=${NEW_VERSION}" >> $GITHUB_OUTPUT
# Configure git
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
# Update version in build.gradle.kts
# Update version in build.gradle.kts
VERSION_WITHOUT_V=${NEW_VERSION#v}
BASE_VERSION=$(echo $VERSION_WITHOUT_V | cut -d'-' -f1)
sed -i "s/version = \".*\"/version = \"$BASE_VERSION\"/" build.gradle.kts
Expand Down

0 comments on commit 8ec1d42

Please sign in to comment.