From 8ec1d42d46e9e2db03623ffee5ff67f1b0c168b7 Mon Sep 17 00:00:00 2001 From: John Melati Date: Wed, 15 Jan 2025 16:22:31 +0100 Subject: [PATCH] chore: fix auto versioning --- .github/workflows/auto-version.yml | 33 +++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/.github/workflows/auto-version.yml b/.github/workflows/auto-version.yml index 7c4d747..db035de 100644 --- a/.github/workflows/auto-version.yml +++ b/.github/workflows/auto-version.yml @@ -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 @@ -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) @@ -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") @@ -119,12 +136,8 @@ jobs: fi echo "new_version=${NEW_VERSION}" >> $GITHUB_OUTPUT - - # Configure git - git config --local user.email "action@github.com" - 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