diff --git a/.github/workflows/auto-versioning.yml b/.github/workflows/auto-versioning.yml index 5da6a95..0283faf 100644 --- a/.github/workflows/auto-versioning.yml +++ b/.github/workflows/auto-versioning.yml @@ -1,9 +1,9 @@ -name: "Automatic Versioning" +name: Automatic Versioning and Release on: push: {} # branches: - # - main # Replace with your default branch if different + # - main # Replace with your target branch if different jobs: auto-version: @@ -13,22 +13,29 @@ jobs: - name: Checkout Repository uses: actions/checkout@v3 + - name: Fetch All Tags + run: | + git fetch --tags + - name: Determine Version Tag id: versioning run: | DATE=$(date -u +"%Y.%m.%d") BASE_TAG="$DATE" + # Fetch all existing tags matching the current date EXISTING_TAGS=$(git tag -l "${BASE_TAG}.*" | sort -V) if [ -z "$EXISTING_TAGS" ]; then NEW_TAG="${BASE_TAG}.01" else LAST_TAG=$(echo "$EXISTING_TAGS" | tail -n 1) - LAST_INCREMENT=$(echo $LAST_TAG | awk -F. '{print $NF}') + LAST_INCREMENT=$(echo "$LAST_TAG" | awk -F. '{print $NF}') NEW_INCREMENT=$(printf "%02d" $((10#$LAST_INCREMENT + 1))) NEW_TAG="${BASE_TAG}.${NEW_INCREMENT}" fi + echo "Existing Tags: $EXISTING_TAGS" + echo "Last Tag: $LAST_TAG" + echo "New Tag: $NEW_TAG" echo "NEW_TAG=$NEW_TAG" >> $GITHUB_ENV - echo "Generated version tag: $NEW_TAG" - name: Create and Push Tag env: