Skip to content

fix(workflow): add poetry-bumpversion to Python package workflow #46

fix(workflow): add poetry-bumpversion to Python package workflow

fix(workflow): add poetry-bumpversion to Python package workflow #46

Workflow file for this run

# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
name: Python package
permissions:
contents: read
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
steps:
- uses: actions/create-github-app-token@v2
id: app-token
with:
app-id: ${{ vars.FLAGGLE_BOT_ID }}
private-key: ${{ secrets.FLAGGLE_BOT_KEY }}
- uses: actions/checkout@v4
with:
token: ${{ steps.app-token.outputs.token }}
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install poetry
run: |
pipx install poetry
poetry config virtualenvs.in-project true
poetry self add poetry-bumpversion
poetry lock --verbose
poetry install --no-interaction --no-ansi
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
${{ github.workspace }}/.venv/bin/flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics --exclude=.venv,.git,__pycache__,docs,tests,examples
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
${{ github.workspace }}/.venv/bin/flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics --statistics --exclude=.venv,.git,__pycache__,docs,tests,examples
- name: Test with pytest
run: |
${{ github.workspace }}/.venv/bin/pytest --cov=flaggle --cov-report=xml --cov-report=term-missing
version-bump:
runs-on: ubuntu-latest
needs: build
if: github.event_name == 'pull_request' || github.event_name == 'push'
steps:
- uses: actions/create-github-app-token@v2
id: app-token
with:
app-id: ${{ vars.FLAGGLE_BOT_ID }}
private-key: ${{ secrets.FLAGGLE_BOT_KEY }}
- uses: actions/checkout@v4
with:
token: ${{ steps.app-token.outputs.token }}
- name: Install poetry
run: |
pipx install poetry
poetry config virtualenvs.in-project true
poetry self add poetry-bumpversion
poetry lock --verbose
poetry install --no-interaction --no-ansi
- name: Get SEMVER from PR Title
id: semver
run: |
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
pr_title="${{ github.event.pull_request.title }}"
pr_title_norm=$(echo "$pr_title" | tr '[:upper:]' '[:lower:]')
if [[ "$pr_title_norm" =~ ^fix ]]; then
echo "semver=patch" >> $GITHUB_OUTPUT
elif [[ "$pr_title_norm" =~ ^feat ]]; then
echo "semver=minor" >> $GITHUB_OUTPUT
elif [[ "$pr_title_norm" =~ ^breaking[[:space:]]change ]]; then
echo "semver=major" >> $GITHUB_OUTPUT
else
echo "PR title '${pr_title}' does not start with fix, feat, or breaking change, skipping version bump."
echo "semver=" >> $GITHUB_OUTPUT
fi
fi
- name: Get GitHub App User ID
if: steps.semver.outputs.semver != ''
id: get-user-id
run: echo "user-id=$(gh api "/users/${{ steps.generate-token.outputs.app-slug }}[bot]" --jq .id)" >> "$GITHUB_OUTPUT"
env:
GH_TOKEN: ${{ steps.generate-token.outputs.token }}
- name: Bump version
if: steps.semver.outputs.semver != ''
run: |
echo "Bumping version with semver: ${{ steps.semver.outputs.semver }}"
poetry version ${{ steps.semver.outputs.semver }}
- name: Set Commiter
run: |
git config --global user.name '${{ steps.generate-token.outputs.app-slug }}[bot]'
git config --global user.email '${{ steps.get-user-id.outputs.user-id }}+${{ steps.generate-token.outputs.app-slug }}[bot]@users.noreply.github.com'
- name: Commit and push changes
if: steps.semver.outputs.semver != ''
run: |
git add .
git commit -m "[skip ci] 🔖 Bump version to ${{ steps.semver.outputs.semver }}"
git push