Skip to content

add badges

add badges #4

Workflow file for this run

name: Publish to PyPI
on:
push:
branches:
- main
release:
types: [published]
jobs:
check-version:
runs-on: ubuntu-latest
outputs:
version-changed: ${{ steps.check.outputs.changed }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check if version was bumped
id: check
run: |
CURRENT_VERSION=$(grep '^version = ' pyproject.toml | grep -oE '[0-9]+\.[0-9]+\.[0-9]+')
LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
if [ -z "$LAST_TAG" ]; then
echo "No previous tags found, version changed"
echo "changed=true" >> $GITHUB_OUTPUT
else
LAST_VERSION=${LAST_TAG#v}
if [ "$CURRENT_VERSION" != "$LAST_VERSION" ]; then
echo "Version changed from $LAST_VERSION to $CURRENT_VERSION"
echo "changed=true" >> $GITHUB_OUTPUT
else
echo "Version unchanged at $CURRENT_VERSION"
echo "changed=false" >> $GITHUB_OUTPUT
fi
fi
test:
if: github.event_name == 'release' || (github.event_name == 'push' && needs.check-version.outputs.version-changed == 'true')
needs: check-version
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install uv
uses: astral-sh/setup-uv@v7
with:
enable-cache: true
cache-dependency-glob: |
**/uv.lock
**/pyproject.toml
- name: Install dependencies
run: uv pip install -e ".[dev]" --system
- name: Run tests
run: uv run pytest
publish:
needs: [check-version, test]
if: github.event_name == 'release' || (github.event_name == 'push' && needs.check-version.outputs.version-changed == 'true')
runs-on: ubuntu-latest
environment: release
permissions:
id-token: write
contents: write
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install uv
uses: astral-sh/setup-uv@v7
with:
enable-cache: true
cache-dependency-glob: |
**/uv.lock
**/pyproject.toml
- name: Build distribution
run: uv build
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
- name: Create and push git tag
run: |
VERSION=$(grep '^version = ' pyproject.toml | grep -oE '[0-9]+\.[0-9]+\.[0-9]+')
TAG="v${VERSION}"
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag -a "$TAG" -m "Release version $VERSION" ${{ github.sha }}
git push origin "$TAG"