1414 runs-on : ubuntu-latest
1515 outputs :
1616 python_changed : ${{ steps.check-python-changes.outputs.python_changed }}
17+ effective_version : ${{ steps.effective-version.outputs.effective_version }}
1718
1819 steps :
1920 - name : Checkout repository
@@ -41,15 +42,15 @@ jobs:
4142 id : check-python-changes
4243 run : |
4344 git fetch origin main
44- # Compare current commit to previous one on this branch
4545 CHANGED_FILES=$(git diff --name-only HEAD^ HEAD)
4646 echo "Changed files: $CHANGED_FILES"
47-
48- # Check if any Python file was changed
47+
4948 if echo "$CHANGED_FILES" | grep -E '\.py$'; then
5049 echo "python_changed=true" >> $GITHUB_ENV
50+ echo "::set-output name=python_changed::true"
5151 else
5252 echo "python_changed=false" >> $GITHUB_ENV
53+ echo "::set-output name=python_changed::false"
5354 fi
5455
5556 - name : Set Version Bump Type from GitVersion
5960 VERSION_INCREMENT="${{ steps.gitversion.outputs.MajorMinorPatch }}"
6061 TAG="${{ steps.gitversion.outputs.PreReleaseLabel }}"
6162
62- # Default bump type
6363 BUMP_TYPE="patch"
6464
65- # If Python files changed → apply version logic
6665 if [[ "${{ env.python_changed }}" == "true" ]]; then
6766 if [[ "$VERSION_INCREMENT" =~ ^[1-9][0-9]*\.0\.0$ ]]; then
6867 BUMP_TYPE="major"
7271 BUMP_TYPE="patch"
7372 fi
7473
75- # Handle pre-release versions
7674 if [[ -n "$TAG" ]]; then
7775 BUMP_TYPE="pre${BUMP_TYPE}"
7876 fi
@@ -83,11 +81,29 @@ jobs:
8381 echo "Version bump detected: $BUMP_TYPE"
8482 echo "bump_type=$BUMP_TYPE" >> $GITHUB_ENV
8583
84+ - name : Determine Effective Version
85+ id : effective-version
86+ run : |
87+ if [[ "${{ env.python_changed }}" == "true" ]]; then
88+ EFFECTIVE_VERSION="${{ steps.gitversion.outputs.semVer }}"
89+ else
90+ PREV_TAG=$(git describe --tags --abbrev=0)
91+ echo "Previous tag: $PREV_TAG"
92+
93+ MAJOR=$(echo $PREV_TAG | cut -d. -f1)
94+ MINOR=$(echo $PREV_TAG | cut -d. -f2)
95+ PATCH=$(echo $PREV_TAG | cut -d. -f3)
96+ NEW_PATCH=$((PATCH + 1))
8697
98+ EFFECTIVE_VERSION="$MAJOR.$MINOR.$NEW_PATCH"
99+ echo "Forcing patch bump: $EFFECTIVE_VERSION"
100+ fi
87101
102+ echo "effective_version=$EFFECTIVE_VERSION" >> $GITHUB_ENV
103+ echo "::set-output name=effective_version::$EFFECTIVE_VERSION"
88104
89105 - name : Update CHANGELOG.md
90- if : github.ref == 'refs/heads/main' # Only update for stable releases
106+ if : github.ref == 'refs/heads/main'
91107 uses : release-flow/keep-a-changelog-action@v3.0.0
92108 with :
93109 command : bump
97113 if : github.ref == 'refs/heads/main'
98114 uses : stefanzweifel/git-auto-commit-action@v5
99115 with :
100- commit_message : " Update CHANGELOG for release ${{ steps.gitversion .outputs.semVer }}"
116+ commit_message : " Update CHANGELOG for release ${{ steps.effective-version .outputs.effective_version }}"
101117 file_pattern : " CHANGELOG.md"
102-
103118
104119 - uses : actions/setup-python@v5
105120 with :
@@ -115,66 +130,59 @@ jobs:
115130 pyproject_file = "pyproject.toml"
116131 with open(pyproject_file, "r", encoding="utf-8") as f:
117132 data = tomlkit.load(f)
118- data["project"]["version"] = "${{ steps.gitversion .outputs.semVer }}"
119- data["tool"]["poetry"]["version"] = "${{ steps.gitversion .outputs.semVer }}"
133+ data["project"]["version"] = "${{ steps.effective-version .outputs.effective_version }}"
134+ data["tool"]["poetry"]["version"] = "${{ steps.effective-version .outputs.effective_version }}"
120135 with open(pyproject_file, "w", encoding="utf-8") as f:
121136 tomlkit.dump(data, f)
122137 EOF
123138
124139 - name : Commit Updated pyproject.toml
125140 uses : stefanzweifel/git-auto-commit-action@v5
126141 with :
127- commit_message : " Update pyproject.toml for release ${{ steps.gitversion .outputs.semVer }}"
142+ commit_message : " Update pyproject.toml for release ${{ steps.effective-version .outputs.effective_version }}"
128143 file_pattern : " pyproject.toml"
129144
130145 - name : Build release distributions
146+ if : env.python_changed == 'true'
131147 run : |
132- # NOTE: put your own distribution build steps here.
133148 python -m pip install build
134149 python -m build
135150
136151 - name : Create Git Tag
137152 run : |
138- git tag ${{ steps.gitversion .outputs.semVer }}
139- git push origin ${{ steps.gitversion .outputs.semVer }}
153+ git tag ${{ steps.effective-version .outputs.effective_version }}
154+ git push origin ${{ steps.effective-version .outputs.effective_version }}
140155
141156 - name : Create GitHub Release
142157 if : env.python_changed == 'true'
143158 uses : softprops/action-gh-release@v1
144159 with :
145- tag_name : v${{ steps.gitversion .outputs.semVer }}
146- name : Release v${{ steps.gitversion .outputs.semVer }}
160+ tag_name : v${{ steps.effective-version .outputs.effective_version }}
161+ name : Release v${{ steps.effective-version .outputs.effective_version }}
147162 body : " ${{ steps.extract-changelog.outputs.release-notes }}"
148163 draft : false
149164 prerelease : ${{ github.ref == 'refs/heads/Dev' }}
150165 files : |
151166 dist/*.whl
152167 dist/*.tar.gz
168+
153169 - name : Upload distributions
154170 if : env.python_changed == 'true'
155171 uses : actions/upload-artifact@v4
156172 with :
157173 name : release-dists
158174 path : dist/
175+
159176 pypi-publish :
160177 runs-on : ubuntu-latest
161178 needs :
162179 - create-release
163- if : github.ref == 'refs/heads/main' && needs.create-release.outputs.python_changed == 'true' # Ensures it only runs for the main branch and if Python files were changed
180+ if : github.ref == 'refs/heads/main' && needs.create-release.outputs.python_changed == 'true'
164181 permissions :
165- # IMPORTANT: this permission is mandatory for trusted publishing
166182 id-token : write
167183
168- # Dedicated environments with protections for publishing are strongly recommended.
169- # For more information, see: https://docs.github.com/en/actions/deployment/targeting-different-environments/using-environments-for-deployment#deployment-protection-rules
170184 environment :
171185 name : pypi
172- # OPTIONAL: uncomment and update to include your PyPI project URL in the deployment status:
173- # url: https://pypi.org/p/YOURPROJECT
174- #
175- # ALTERNATIVE: if your GitHub Release name is the PyPI project version string
176- # ALTERNATIVE: exactly, uncomment the following line instead:
177- # url: https://pypi.org/project/YOURPROJECT/${{ github.event.release.name }}
178186
179187 steps :
180188 - name : Retrieve release distributions
@@ -186,4 +194,4 @@ jobs:
186194 - name : Publish release distributions to PyPI
187195 uses : pypa/gh-action-pypi-publish@release/v1
188196 with :
189- packages-dir : dist/
197+ packages-dir : dist/
0 commit comments