Test Pyproject.toml update #4
Workflow file for this run
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: Update Version File | |
on: | |
pull_request: | |
paths: | |
- "pyproject.toml" | |
branches: | |
- master | |
jobs: | |
update-version: | |
runs-on: ubuntu-latest | |
permissions: | |
pull-requests: write | |
contents: write | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: "3.11" | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
- name: Update version.py | |
run: | | |
# Read version from pyproject.toml and update version.py | |
python -c ' | |
import tomllib | |
# Read version from pyproject.toml | |
with open("pyproject.toml", "rb") as f: | |
config = tomllib.load(f) | |
version = config["project"]["version"] | |
# Write version to version.py | |
with open("version.py", "w") as f: | |
f.write("# This file is automatically generated by the build process when version is\n") | |
f.write("# updated in pyproject.toml.\n") | |
f.write(f"__version__ = \"{version}\"\n") | |
' | |
- name: Commit changes | |
run: | | |
git config --local user.name "github-actions" | |
git config --local user.email "[email protected]" | |
git fetch origin ${{ github.head_ref }} | |
git checkout -B ${{ github.head_ref }} origin/${{ github.head_ref }} | |
git add version.py | |
git diff --quiet && git diff --staged --quiet || git commit -m "chore: Update version.py to match pyproject.toml" | |
git push origin HEAD:${{ github.head_ref }} |