Skip to content

Commit 4bde247

Browse files
authored
fix: implement complete git-tag-based versioning system (#21)
fix: implement complete git-tag-based versioning system - Remove version dependency from pyproject.toml configuration - Configure commitizen to use SCM (git tags) as version provider - Update GitHub Actions workflow to create only git tags, no file modifications - Implement dynamic version detection from git tags in package code - Streamline changelog generation using unreleased-version parameter - Ensure complete git-tag-driven version management without manual updates Resolves version calculation issues and enables fully automated releases Based on git tags as single source of truth for version management
1 parent d7efb57 commit 4bde247

File tree

3 files changed

+43
-17
lines changed

3 files changed

+43
-17
lines changed

.github/workflows/release.yml

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,27 +65,25 @@ jobs:
6565
- name: Bump version automatically
6666
id: bump-version
6767
run: |
68-
# Check if we need to bump version based on conventional commits
68+
# Git-tag-based versioning: Version is determined entirely by git tags
69+
# No pyproject.toml version updates needed - everything is tag-driven
6970
if cz bump --dry-run 2>/dev/null; then
7071
echo "bump_needed=true" >> $GITHUB_OUTPUT
7172
72-
# Get the new version that would be created
73+
# Get the new version that commitizen would create based on conventional commits
7374
NEW_VERSION=$(cz bump --dry-run | grep "bump: version" | sed 's/.*→ //')
7475
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
7576
76-
# Update only the commitizen version configuration before bumping
77-
sed -i.bak "/^\[tool\.commitizen\]/,/^\[/ s/^version = \"[^\"]*\"/version = \"$NEW_VERSION\"/" pyproject.toml
78-
rm -f pyproject.toml.bak
79-
80-
# Now run cz bump which will create a single commit with all changes
81-
cz bump --yes
82-
83-
# Generate changelog content for release (without creating file)
84-
CHANGELOG_CONTENT=$(cz changelog --dry-run)
77+
# Generate changelog content from last tag to current commits
78+
CHANGELOG_CONTENT=$(cz changelog --unreleased-version=$NEW_VERSION --dry-run)
8579
echo "changelog_content<<EOF" >> $GITHUB_OUTPUT
8680
echo "$CHANGELOG_CONTENT" >> $GITHUB_OUTPUT
8781
echo "EOF" >> $GITHUB_OUTPUT
8882
83+
# Create ONLY git tag - no file modifications needed
84+
# All version info comes from git tags via dynamic version detection
85+
cz bump --yes
86+
8987
# Push based on branch protection status
9088
if [ "${{ steps.branch-protection.outputs.can_push_directly }}" = "true" ]; then
9189
echo "Pushing directly to main branch..."

markdown_flow/__init__.py

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,5 +81,35 @@
8181
"replace_variables_in_text",
8282
]
8383

84-
# Version information
85-
__version__ = "0.2.0"
84+
85+
# Version information - dynamically retrieved from git tags
86+
def _get_version():
87+
"""Get version from git tags or package metadata."""
88+
try:
89+
# First try to get from git tags (for development)
90+
import subprocess
91+
92+
result = subprocess.run(
93+
["git", "describe", "--tags", "--abbrev=0"],
94+
capture_output=True,
95+
text=True,
96+
cwd=__file__.rsplit("/", 2)[0], # Go to project root
97+
)
98+
if result.returncode == 0:
99+
return result.stdout.strip().lstrip("v")
100+
except Exception:
101+
pass
102+
103+
try:
104+
# Fallback to package metadata (for installed packages)
105+
from importlib.metadata import version
106+
107+
return version("markdown-flow")
108+
except Exception:
109+
pass
110+
111+
# Final fallback
112+
return "0.0.0-dev"
113+
114+
115+
__version__ = _get_version()

pyproject.toml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,15 +144,13 @@ disallow_incomplete_defs = false
144144
# =============================================================================
145145
[tool.commitizen]
146146
name = "cz_conventional_commits"
147-
version = "0.3.0"
148147
tag_format = "v$major.$minor.$patch"
149148
update_changelog_on_bump = true
150149
annotated_tag = true
151150
gpg_sign = false
152-
version_files = [
153-
"markdown_flow/__init__.py:__version__"
154-
]
151+
# Version is completely determined by git tags - no version_files needed
155152
bump_message = "bump: version $current_version → $new_version"
153+
version_provider = "scm"
156154
style = [
157155
["qmark", "fg:#ff9d00 bold"],
158156
["question", "bold"],

0 commit comments

Comments
 (0)