Skip to content

refactor

refactor #5

Workflow file for this run

# Automated release workflow
name: Create Release
on:
push:
branches: [ main ]
paths: [ 'pyproject.toml' ]
jobs:
ci:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: 3.11
- name: Install uv
uses: astral-sh/setup-uv@v3
- name: Install dependencies
run: uv sync --dev --extra pydantic
- name: Run ruff linting
run: uv run ruff check cocapi
- name: Run ruff formatting check
run: uv run ruff format --check cocapi
- name: Run mypy type checking
run: uv run mypy cocapi
- name: Run tests
run: uv run pytest tests/test_cocapi.py -v --tb=short
check-version:
needs: ci
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
version_changed: ${{ steps.version.outputs.changed }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Extract version from pyproject.toml
id: version
run: |
# Get current version from pyproject.toml using grep and sed
CURRENT_VERSION=$(grep '^version = ' pyproject.toml | sed 's/version = "\(.*\)"/\1/')
echo "version=v$CURRENT_VERSION" >> $GITHUB_OUTPUT
# Check if this version already has a tag
if git tag -l | grep -q "^v$CURRENT_VERSION$"; then
echo "changed=false" >> $GITHUB_OUTPUT
echo "Version v$CURRENT_VERSION already exists as a tag"
else
echo "changed=true" >> $GITHUB_OUTPUT
echo "New version detected: v$CURRENT_VERSION"
fi
create-release:
needs: check-version
if: needs.check-version.outputs.version_changed == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Create git tag
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git tag ${{ needs.check-version.outputs.version }}
git push origin ${{ needs.check-version.outputs.version }}
- name: Create GitHub Release
run: |
gh release create ${{ needs.check-version.outputs.version }} \
--title "${{ needs.check-version.outputs.version }}" \
--notes "Release ${{ needs.check-version.outputs.version }}
Auto-generated release from version bump in pyproject.toml"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Python for publishing
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install uv
uses: astral-sh/setup-uv@v3
- name: Build package
run: uv build
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}