Skip to content

Build

Build #10

name: Build #and Publish
on:
# push:
# branches: [ "main" ]
# pull_request:
# branches: [ "main" ]
push:
tags:
- 'v*.*.*'
workflow_dispatch:
inputs:
dry-run:
description: "Dry run"
required: false
default: false
type: "boolean"
# version:
# description: "Version"
# required: false
# default: "patch"
# type: "string"
permissions:
contents: write
packages: write
jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.11"]
steps:
- uses: actions/checkout@v4
- name: Cache Poetry
uses: actions/cache@v4
with:
path: ${{ env.PIPX_HOME }}/venvs
key: ${{ runner.os }}-poetry-${{ hashFiles('**/poetry.lock') }}
restore-keys: |
${{ runner.os }}-poetry-
- name: Install Poetry
shell: bash
run: |
pipx install poetry
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: "poetry"
- name: Install dependencies
run: poetry install --with dev
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
poetry run flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
poetry run flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
# - name: Black formatting check
# run: poetry run black . --check --diff --verbose
- name: Test with pytest
run: |
poetry run pytest
- name: Check version
id: check_version
run: |
TAGGED_VERSION=$(echo ${{ github.ref }} | cut -d '/' -f 3) # Extract version from tag
POETRY_VERSION=$(poetry version --short)
if [ "$TAGGED_VERSION" != "$POETRY_VERSION" ]; then
echo "Versions do not match. Updating..."
if [[ $TAGGED_VERSION =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then # Check valid semver tag
poetry version $TAGGED_VERSION
else
poetry version patch # Default to patch version bump
fi
if [ ${{ github.event.inputs.dry-run }} != true ]; then
git config --global user.email "[email protected]"
git config --global user.name "GitHub Actions"
git commit -m "Update version to $(poetry version --short)" pyproject.toml
git push
fi
else
echo "Versions match. No update needed."
fi
# - name: Build package
# run: poetry build
- name: Set PyPI token
run: poetry config pypi-token.pypi ${{ secrets.PYPI_TOKEN }}
- name: Publish package
run: poetry publish --build
# - name: Upload artifact
# uses: actions/upload-artifact@v4
# with:
# name: dist
# path: dist