70 lines
1.8 KiB
YAML
70 lines
1.8 KiB
YAML
# .gitea/workflows/bump-version.yaml
|
|
name: Bump Version
|
|
|
|
on:
|
|
workflow_dispatch:
|
|
inputs:
|
|
bump:
|
|
description: 'Version part to bump'
|
|
required: true
|
|
default: 'patch'
|
|
type: choice
|
|
options:
|
|
- patch
|
|
- minor
|
|
- major
|
|
|
|
jobs:
|
|
bump:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
token: ${{ secrets.GITEA_TOKEN }}
|
|
|
|
- name: Configure git
|
|
run: |
|
|
git config user.name "gitea-actions"
|
|
git config user.email "actions@semrks.nl"
|
|
|
|
- name: Bump version in pyproject.toml
|
|
id: bump
|
|
run: |
|
|
python3 - <<'EOF'
|
|
import re
|
|
|
|
bump = "${{ inputs.bump }}"
|
|
path = "pyproject.toml"
|
|
|
|
with open(path) as f:
|
|
content = f.read()
|
|
|
|
match = re.search(r'(?m)^version = "(\d+)\.(\d+)\.(\d+)"$', content)
|
|
major, minor, patch = map(int, match.groups())
|
|
|
|
if bump == "major":
|
|
major, minor, patch = major + 1, 0, 0
|
|
elif bump == "minor":
|
|
minor, patch = minor + 1, 0
|
|
else:
|
|
patch += 1
|
|
|
|
new_version = f"{major}.{minor}.{patch}"
|
|
new_content = content[:match.start()] + f'version = "{new_version}"' + content[match.end():]
|
|
|
|
with open(path, "w") as f:
|
|
f.write(new_content)
|
|
|
|
with open("$GITEA_ENV", "a") as f:
|
|
f.write(f"NEW_VERSION={new_version}\n")
|
|
EOF
|
|
|
|
- name: Commit and tag
|
|
run: |
|
|
git add pyproject.toml
|
|
git commit -m "Bump version to ${NEW_VERSION}"
|
|
git tag "v${NEW_VERSION}"
|
|
git push origin HEAD:${{ github.ref_name }}
|
|
git push origin "v${NEW_VERSION}"
|