Auto Increment Pyproject Version
Closed this issue · 5 comments
Auto increment pyproject version based on commit notes
Is your feature request related to a problem? Please describe.
Currently, the pyproject version is manually incremented by developers during merging of branches. This is time-consuming and prone to human error. The contributors of this project then have to manually create a release tag that corresponds to that increment.
Describe the solution you'd like
An automated process that increments the pyproject version based on the commit notes during the merge to the trunk. If a breaking change is found, then the major version will be updated. If a new feature is added, the minor version will be updated. If a bug or small enhancement is added, the fix version will be updated.
Describe alternatives you've considered
The only alternative considered is the manual increment of the pyproject version, which is time-consuming and prone to human error.
This article was an interesting read and may be related: https://mestrak.com/blog/semantic-release-with-python-poetry-github-actions-20nn
I'll need to dig deeper into the tools mentioned. Poetry may also be a way to manager the dependencies of this project is a better way.
We're using Semantic Versioning for this project, or well intend to. https://semver.org/
If we want to automatically increment the versions we should consider using: https://www.conventionalcommits.org/en/v1.0.0-beta.2/#why-use-conventional-commits
I like this: https://github.com/conventional-changelog/commitlint/tree/master
I just don't see a way to add it as a github action, I'll have to do some more investigation but I'm sure there is a way.
I added this: https://github.com/Ezard/semantic-prs#readme
To the project. This will ensure we have semantic PRs.
Wow, I just found this https://python-semver.readthedocs.io because ChatGPT gave me this workflow
name: Release
on:
push:
branches:
- trunk
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Install dependencies
run: |
pip install semver
pip install pydantic
- name: Get current version
id: get_version
run: |
VERSION=$(python -c "import pydantic; print(pydantic.VersionInfo.parse_file('pyproject.toml').version)")
echo "::set-output name=version::$VERSION"
- name: Increment version
id: increment_version
run: |
VERSION=$(python -c "import pydantic; print(pydantic.VersionInfo.parse_file('pyproject.toml').version)")
NEW_VERSION=$(semver bump ${GITHUB_REF##*/})
sed -i "s/version = \"$VERSION\"/version = \"$NEW_VERSION\"/" pyproject.toml
echo "::set-output name=new_version::$NEW_VERSION"
- name: Generate changelog
id: generate_changelog
run: |
NEW_VERSION=$INPUT_NEW_VERSION
CURRENT_VERSION=$(git tag | sort -V | tail -n1)
CHANGELOG=$(git log --pretty=format:"%h %s (%an)" $CURRENT_VERSION..HEAD)
echo "## $NEW_VERSION" > changelog.md
echo "$CHANGELOG" >> changelog.md
echo "::set-output name=changelog::$CHANGELOG"
- name: Create release tag
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.increment_version.outputs.new_version }}
release_name: Release ${{ steps.increment_version.outputs.new_version }}
body: ${{ steps.generate_changelog.outputs.changelog }}
I started the branch add-auto-semvar