diff --git a/.github/workflows/windows_build.yml b/.github/workflows/windows_build.yml index 799b8d5..c15978d 100644 --- a/.github/workflows/windows_build.yml +++ b/.github/workflows/windows_build.yml @@ -18,28 +18,36 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v4 + with: + fetch-tags: true - name: Bump patch version id: bump run: | - VERSION_FILE="__init__.py" - CONTENT=$(cat "$VERSION_FILE") - MAJOR=$(echo "$CONTENT" | sed -nE 's/__version__\s*=\s*"([0-9]+)\.([0-9]+)\.([0-9]+)"/\1/p') - MINOR=$(echo "$CONTENT" | sed -nE 's/__version__\s*=\s*"([0-9]+)\.([0-9]+)\.([0-9]+)"/\2/p') - PATCH=$(echo "$CONTENT" | sed -nE 's/__version__\s*=\s*"([0-9]+)\.([0-9]+)\.([0-9]+)"/\3/p') + LATEST_TAG=$(git tag --sort=-creatordate | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' | head -1 || echo "0.0.0") + MAJOR=$(echo "$LATEST_TAG" | cut -d. -f1) + MINOR=$(echo "$LATEST_TAG" | cut -d. -f2) + PATCH=$(echo "$LATEST_TAG" | cut -d. -f3) + MAJOR=${MAJOR:-0} + MINOR=${MINOR:-0} + PATCH=${PATCH:-0} NEW_PATCH=$((PATCH + 1)) NEW_VERSION="${MAJOR}.${MINOR}.${NEW_PATCH}" - sed -i "s/__version__ = \"${MAJOR}\.${MINOR}\.${PATCH}\"/__version__ = \"${NEW_VERSION}\"/" "$VERSION_FILE" echo "new_version=${NEW_VERSION}" >> "$GITHUB_OUTPUT" - - name: Commit version bump and tag + - name: Tag version run: | - git config user.name "github-actions[bot]" - git config user.email "github-actions[bot]@users.noreply.github.com" - git add __init__.py - git commit -m "chore: bump version to ${{ steps.bump.outputs.new_version }} [skip ci]" - git tag ${{ steps.bump.outputs.new_version }} - git push origin main --tags + if git rev-parse ${{ steps.bump.outputs.new_version }} >/dev/null 2>&1; then + echo "Tag ${{ steps.bump.outputs.new_version }} already exists, skipping" + else + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + sed -i "s/__version__ = .*/__version__ = \"${{ steps.bump.outputs.new_version }}\"/" __init__.py + git add __init__.py + git commit -m "chore: bump version to ${{ steps.bump.outputs.new_version }}" + git tag ${{ steps.bump.outputs.new_version }} + git push origin ${{ steps.bump.outputs.new_version }} + fi build: needs: version @@ -76,7 +84,7 @@ jobs: retention-days: 5 - name: Create Release - if: github.event_name == 'push' && needs.version.result == 'success' && needs.version.outputs.new_version != '' + if: github.event_name == 'push' uses: softprops/action-gh-release@v2 with: tag_name: ${{ needs.version.outputs.new_version }}