-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from awhipp/feature/adding_version_bumping
feat: 💚 Adding version bumping to main branch
- Loading branch information
Showing
2 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
"""Python script to analyze git history and determine version bump.""" | ||
|
||
import subprocess | ||
|
||
|
||
def get_commit_messages(): | ||
"""Get commit messages using git log.""" | ||
# Get commit messages using git log | ||
commit_log = ( | ||
subprocess.check_output(["git", "log", "--pretty=%s"]).decode().split("\n") | ||
) | ||
# Filter out empty lines | ||
commit_messages = [msg.strip() for msg in commit_log if msg.strip()] | ||
|
||
# Only get the commit messages between the last two merge requests | ||
merge_request_count = 0 | ||
valid_commit_messages = [] | ||
for _, message in enumerate(commit_messages): | ||
if merge_request_count == 2: | ||
break | ||
if "Merge pull request" in message: | ||
merge_request_count += 1 | ||
else: | ||
valid_commit_messages.append(message) | ||
|
||
return valid_commit_messages | ||
|
||
|
||
def determine_version_bump(valid_messages): | ||
"""Determine version bump based on commit messages.""" | ||
version_bump = None | ||
|
||
# Check commit messages for specific keywords to determine version bump | ||
for message in valid_messages: | ||
if message.startswith("fix") and version_bump in [None, "patch"]: | ||
version_bump = "patch" | ||
elif message.startswith("feat") and version_bump in [None, "patch", "minor"]: | ||
version_bump = "minor" | ||
elif message.startswith("BREAKING CHANGE") and version_bump in [ | ||
None, | ||
"patch", | ||
"minor", | ||
"major", | ||
]: | ||
version_bump = "major" | ||
# Add more conditions based on your project's conventions | ||
|
||
# Default to 'patch' if no specific keyword found | ||
return version_bump | ||
|
||
|
||
if __name__ == "__main__": | ||
# Determine version bump | ||
version_bump = determine_version_bump(get_commit_messages()) | ||
|
||
# Output version bump | ||
print(version_bump) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
name: Versioning Workflow | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
determine-version: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout Repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Analyze Commit Messages and Bump Version | ||
run: | | ||
# Custom script to analyze commit messages and determine version bump | ||
## Stored in .github/analyze_git_history.py | ||
## Assuming the script outputs the determined version bump as 'patch', 'minor', or 'major' | ||
## Only None if there is no relevant commits. | ||
version_bump=$(python .github/analyze_git_history.py) | ||
if [ "$version_bump" == "patch" ]; then | ||
poetry version patch | ||
elif [ "$version_bump" == "minor" ]; then | ||
poetry version minor | ||
elif [ "$version_bump" == "major" ]; then | ||
poetry version major | ||
else | ||
echo "Invalid version bump type ($version_bump). Skipping." | ||
exit 0 | ||
fi | ||
# Commit the version change | ||
git add pyproject.toml | ||
git commit -m "chore: Bump version ($version_bump)" | ||
git push origin main |