Skip to content

maintenance and improvements #7

maintenance and improvements

maintenance and improvements #7

Workflow file for this run

name: build
on:
push:
branches:
- main
pull_request:
branches:
- main
workflow_dispatch:
inputs:
publish:
description: 'Publish to PyPI (staging for non-main branches, production for main)'
required: false
type: boolean
default: false
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.9'
- name: Install uv
uses: astral-sh/setup-uv@v4
- name: Install dependencies
run: uv sync
- name: Run pre-commit
run: |
uv run pre-commit run --all-files
- name: Run tests
run: |
uv run python -m unittest discover -s tests -p "*.py"
publish:
needs: test
runs-on: ubuntu-latest
if: github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && inputs.publish)
permissions:
id-token: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.9'
- name: Install uv
uses: astral-sh/setup-uv@v4
- name: Install dependencies
run: uv sync
- name: Update version for staging (non-main branches)
if: github.ref != 'refs/heads/main'
run: |
TIMESTAMP=$(date +%Y%m%d%H%M%S)
CURRENT_VERSION=$(grep '^version = ' pyproject.toml | sed 's/version = "\(.*\)"/\1/')
NEW_VERSION="${CURRENT_VERSION}.dev${TIMESTAMP}"
sed -i "s/^version = .*/version = \"${NEW_VERSION}\"/" pyproject.toml
echo "Publishing version ${NEW_VERSION} to Test PyPI"
- name: Build package
run: uv build
- name: Publish to Test PyPI (staging)
if: github.ref != 'refs/heads/main'
run: |
uv publish --publish-url https://test.pypi.org/legacy/ --trusted-publishing always
- name: Publish to PyPI (production)
if: github.ref == 'refs/heads/main'
run: |
uv publish --trusted-publishing always