This repository contains two GitHub Actions:
- Check Version - Ensures that the version in
pyproject.tomlhas been updated before merging a pull request. - Tag Version - Automatically tags a commit with the version from
pyproject.tomlwhen changes are merged intomain.
Add the following to your .github/workflows/check_version.yml:
name: Check Version
on:
pull_request:
branches:
- main
jobs:
check_version:
runs-on: ubuntu-latest
steps:
- uses: villoro/vhooks/[email protected]
with:
branch: "main" # Change this to compare against a different branch
path: "project/version" # Specify the version path inside pyproject.toml| Input | Description | Required | Default |
|---|---|---|---|
branch |
The branch to compare the version against. | ❌ No | main |
path |
Path inside pyproject.toml to extract the version. |
❌ No | project/version |
- Fails the PR if the version in
pyproject.tomlhas not been updated. - Fails the PR if the version increments are not consecutive.
- Passes the PR if the version has been correctly incremented.
| Scenario | Expected Outcome |
|---|---|
| Version not updated | ❌ Fails, requires increment |
| Version incremented | ✅ Passes |
Version skipped multiple steps (e.g., 1.0.0 → 1.2.0) |
❌ Fails |
| Comparing against a different branch | ✅ Works with --branch=<branch> |
Using a custom version path inside pyproject.toml |
✅ Works with --path=<path> |
Add the following to your .github/workflows/tag_version.yml:
name: Tag Version
on:
push:
branches:
- main
paths:
- pyproject.toml
permissions:
contents: write
jobs:
tag_version:
runs-on: ubuntu-latest
steps:
- uses: villoro/vhooks/[email protected]
with:
path: "project/version" # Specify the version path inside pyproject.toml| Input | Description | Required | Default |
|---|---|---|---|
path |
Path inside pyproject.toml to extract the version. |
❌ No | project/version |
- Creates a new Git tag when
pyproject.tomlis modified inmain. - Uses the specified version path to extract the version.
- Skips tagging if the version is already tagged.