@@ -117,8 +117,8 @@ jobs:
117117 with :
118118 python-version : ${{ env.PYTHON_VERSION }}
119119
120- - name : Install bump2version
121- run : pip install bump2version
120+ - name : Install dependencies
121+ run : pip install packaging
122122
123123 - name : Configure git
124124 run : |
@@ -137,17 +137,29 @@ jobs:
137137 echo "ticket=$TICKET" >> $GITHUB_OUTPUT
138138 echo "Found ticket: $TICKET"
139139
140- - name : Determine version bump type
140+ - name : Determine semantic version bump
141141 id : bump_type
142142 run : |
143- if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
144- echo "type=${{ inputs.version_type }}" >> $GITHUB_OUTPUT
145- elif [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
146- echo "type=patch" >> $GITHUB_OUTPUT
147- elif [[ "${{ github.ref }}" == "refs/heads/develop" ]]; then
143+ # Get commits since last tag
144+ LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
145+ COMMITS=$(git log $LAST_TAG..HEAD --oneline --pretty=format:"%s")
146+
147+ # Check for breaking changes
148+ if echo "$COMMITS" | grep -qi "BREAKING CHANGE\|!:"; then
149+ echo "type=major" >> $GITHUB_OUTPUT
150+ echo "reason=breaking change detected" >> $GITHUB_OUTPUT
151+ # Check for features
152+ elif echo "$COMMITS" | grep -qi "^feat"; then
148153 echo "type=minor" >> $GITHUB_OUTPUT
154+ echo "reason=new feature detected" >> $GITHUB_OUTPUT
155+ # Check for fixes
156+ elif echo "$COMMITS" | grep -qi "^fix"; then
157+ echo "type=patch" >> $GITHUB_OUTPUT
158+ echo "reason=bug fix detected" >> $GITHUB_OUTPUT
159+ # Default to patch for other commits
149160 else
150161 echo "type=patch" >> $GITHUB_OUTPUT
162+ echo "reason=default patch increment" >> $GITHUB_OUTPUT
151163 fi
152164
153165 - name : Get current version
@@ -156,30 +168,43 @@ jobs:
156168 VERSION=$(grep '^version = ' pyproject.toml | cut -d'"' -f2)
157169 echo "current=$VERSION" >> $GITHUB_OUTPUT
158170
159- - name : Bump version
171+ - name : Calculate new version
160172 id : version
161173 run : |
162174 BUMP_TYPE=${{ steps.bump_type.outputs.type }}
175+ CURRENT_VERSION=${{ steps.current_version.outputs.current }}
176+
177+ # Parse current version
178+ IFS='.' read -r major minor patch <<< "$CURRENT_VERSION"
179+
180+ # Calculate new version based on semantic rules
181+ case $BUMP_TYPE in
182+ major)
183+ NEW_VERSION="$((major + 1)).0.0"
184+ ;;
185+ minor)
186+ NEW_VERSION="$major.$((minor + 1)).0"
187+ ;;
188+ patch)
189+ NEW_VERSION="$major.$minor.$((patch + 1))"
190+ ;;
191+ esac
192+
193+ echo "Bumping from $CURRENT_VERSION to $NEW_VERSION ($BUMP_TYPE: ${{ steps.bump_type.outputs.reason }})"
194+
195+ # Update pyproject.toml
196+ sed -i "s/version = \"$CURRENT_VERSION\"/version = \"$NEW_VERSION\"/" pyproject.toml
197+
198+ # Commit and tag
199+ git add pyproject.toml
200+ git commit -m "[${{ steps.ticket.outputs.ticket }}] Release v$NEW_VERSION
201+
202+ Semantic version bump: $BUMP_TYPE
203+ Reason: ${{ steps.bump_type.outputs.reason }}
204+ Previous version: $CURRENT_VERSION"
205+
206+ git tag -a "v$NEW_VERSION" -m "[${{ steps.ticket.outputs.ticket }}] Release v$NEW_VERSION"
163207
164- # Create .bumpversion.cfg with LABIMP commit message format
165- cat > .bumpversion.cfg << EOF
166- [bumpversion]
167- current_version = ${{ steps.current_version.outputs.current }}
168- commit = True
169- tag = True
170- tag_name = v{new_version}
171- message = [${{ steps.ticket.outputs.ticket }}] Bump version: {current_version} → {new_version}
172-
173- [bumpversion:file:pyproject.toml]
174- search = version = "{current_version}"
175- replace = version = "{new_version}"
176- EOF
177-
178- # Bump the version
179- bump2version $BUMP_TYPE
180-
181- # Get the new version
182- NEW_VERSION=$(grep '^version = ' pyproject.toml | cut -d'"' -f2)
183208 echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT
184209 echo "tag=v$NEW_VERSION" >> $GITHUB_OUTPUT
185210
0 commit comments