Merge pull request #10 from awhipp/feature/auto_version_bumping #5
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
name: Versioning Workflow | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
determine-version: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: "0" | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: 3.11 | |
- name: Install and Configure Poetry & Git Credentials | |
run: | | |
python -m pip install poetry==1.8.2 | |
python -m poetry config virtualenvs.in-project true | |
git config --global user.email "[email protected]" | |
git config --global user.name "Github Actions Runner" | |
- name: Cache the virtualenv | |
uses: actions/cache@v4 | |
with: | |
path: ./.venv | |
key: ${{ runner.os }}-venv-${{ hashFiles('**/poetry.lock') }} | |
- name: Install dependencies | |
run: python -m poetry install | |
- 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 |