Increment Version and Push #12
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: Increment Version and Push | |
on: | |
workflow_dispatch: | |
inputs: | |
bumpPatchVersion: | |
description: "Auto-Bump Patch Version & Commit" | |
required: true | |
default: "false" | |
type: choice | |
options: | |
- false | |
- true | |
jobs: | |
increment-version: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: "3.x" | |
- name: Increment version in pyproject.toml | |
if: ${{ github.event.inputs.bumpPatchVersion == 'true' }} | |
run: | | |
python -c "import re; open('pyproject.toml', 'r+', encoding='utf-8').write(re.sub(r'(version\s*=\s*\"\\d+\\.\\d+\\.)(\\d+)', lambda m: f'{m.group(1)}{int(m.group(2))+1}', open('pyproject.toml').read()))" | |
- name: Commit and push changes | |
if: ${{ github.event.inputs.bumpPatchVersion == 'true' }} | |
run: | | |
git config --global user.name 'github-actions[bot]' | |
git config --global user.email 'github-actions[bot]@users.noreply.github.com' | |
git add pyproject.toml | |
git commit -m "Increment version" | |
git push | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Echo Version Number | |
run: | | |
version=$(python -c "print(next(line.split('=')[1].strip().strip('\"') for line in open('pyproject.toml') if line.startswith('version')))") | |
echo "Version is $version" |