A GitHub Action to bump pyproject.toml version numbers during pull requests
This action will bump the version number of pyproject.toml file with respect to the main branch.
For instance, say the version numbers in branch1 and main are both 1.0.0 and a pull request is being made from branch1 into main, then this action will bump the version number to 2.0.0 (if you specify major as the bump_type input).
Note, that this action will only bump the version if the version number in main is less than or equal to the compare branch version.
You can control whether you want the bump to happen before merging or after by checking the variable github.event.pull_request.merged.
The following example will do the following:
- Only runs on a pull request into main and when any files in the directory
python_project/have changed or thepyproject.tomlfile has changed. - The job only runs if the pull request is not being merged. This is useful for when a repository is set up to not allow writing directly to main.
- It will do a minor version bump to the
pyproject.tomland commit the changes to the compare branch.
name: "Version bumper"
on:
pull_request:
branches:
- main
paths:
- 'python_project/**'
- './pyproject.toml'
jobs:
bump-version:
if: github.event.pull_request.merged == false
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.ref }}
fetch-depth: "0"
- name: Version bumper
uses: apowis/[email protected]
with:
file_to_bump: "./pyproject.toml"
bump_type: "minor"
main_branch: "main"
python_version: "3.10"- Work out more about the fetch depth and potentially using different branches
- Document
version_compare.pymore and add some tests. - Add more options to EndBug/add-and-commit@v9 inputs
- Add option to not merge or not depending on pull request merge status
- Implement more file types than pyproject.toml?
- Long term, think about using npm stuff instead of Python scripts. Probably will never get to doing this.