setup: Migrate to uv and pyproject.toml (#33) #200
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: default | |
| on: | |
| push: | |
| branches: [main] | |
| pull_request: | |
| branches: [main] | |
| release: | |
| types: [created] | |
| branches: | |
| - 'main' | |
| workflow_dispatch: | |
| jobs: | |
| pre-commit-check: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Install uv | |
| uses: astral-sh/setup-uv@v4 | |
| with: | |
| version: "latest" | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.11" | |
| - name: Cache pre-commit dependencies | |
| id: cache_pre_commit | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| .pre_commit_venv | |
| ~/.cache/pre-commit | |
| key: pre-commit-${{ hashFiles('.pre-commit-config.yaml','~/.cache/pre-commit/*') }} | |
| - name: Install pre-commit | |
| if: steps.cache_pre_commit.outputs.cache-hit != 'true' | |
| run: | | |
| python -m venv .pre_commit_venv | |
| . .pre_commit_venv/bin/activate | |
| pip install --upgrade pip | |
| pip install pre-commit | |
| pre-commit install --install-hooks | |
| pre-commit gc | |
| - name: Run pre-commit hooks | |
| run: | | |
| if [ "$GITHUB_EVENT_NAME" == "pull_request" -a -n "$GITHUB_HEAD_REF" ]; then | |
| echo "(skipping matchers for pull request from local branches)" | |
| else | |
| echo "::add-matcher::.github/workflows/flake8-matcher.json" | |
| echo "::add-matcher::.github/workflows/mypy-matcher.json" | |
| fi | |
| . .pre_commit_venv/bin/activate | |
| pre-commit run --color=always --all-files | |
| test-unit: | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| python-version: ["3.11", "3.12", "3.13"] | |
| services: | |
| redis: | |
| image: redis:7-alpine | |
| ports: | |
| - 6379 | |
| options: >- | |
| --health-cmd "redis-cli ping" | |
| --health-interval 4s | |
| --health-timeout 2s | |
| --health-retries 5 | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Install uv | |
| uses: astral-sh/setup-uv@v4 | |
| with: | |
| version: "latest" | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| - name: Install dependencies | |
| run: | | |
| sudo apt install -y libsnappy-dev | |
| uv sync --extra zeromq --extra redis --extra thrift --extra snappy | |
| - name: Run unit tests | |
| env: | |
| REDIS_HOST: localhost | |
| REDIS_PORT: ${{ job.services.redis.ports[6379] }} | |
| run: | | |
| uv run python -m pytest --cov tests | |
| - name: Upload coverage report | |
| uses: codecov/codecov-action@v3 | |
| test-integration: | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| python-version: ["3.11", "3.12", "3.13"] | |
| services: | |
| redis: | |
| image: redis:7-alpine | |
| ports: | |
| - 6379 | |
| options: >- | |
| --health-cmd "redis-cli ping" | |
| --health-interval 4s | |
| --health-timeout 2s | |
| --health-retries 5 | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Install uv | |
| uses: astral-sh/setup-uv@v4 | |
| with: | |
| version: "latest" | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| - name: Install dependencies | |
| run: | | |
| sudo apt install -y libsnappy-dev | |
| uv sync --extra zeromq --extra redis --extra thrift --extra snappy | |
| - name: Run integration tests | |
| env: | |
| REDIS_HOST: localhost | |
| REDIS_PORT: ${{ job.services.redis.ports[6379] }} | |
| run: | | |
| uv run ./scripts/run-integration-tests.sh | |
| build-distributions: | |
| needs: [pre-commit-check, test-unit, test-integration] | |
| if: github.event_name == 'push' && contains(github.ref, 'refs/tags/') | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Fetch remote tags | |
| run: git fetch origin 'refs/tags/*:refs/tags/*' -f | |
| - name: Install uv | |
| uses: astral-sh/setup-uv@v4 | |
| with: | |
| version: "latest" | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.11" | |
| - name: Install dependencies | |
| run: | | |
| uv sync | |
| - name: Build packages | |
| run: | | |
| uv run python -c "import callosum; print(callosum.__version__)" | tee version.txt | |
| uv build | |
| - name: Upload the build version | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: version | |
| path: version.txt | |
| - name: Upload build artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: distributions | |
| path: dist | |
| publish: | |
| needs: [build-distributions] | |
| if: github.event_name == 'push' && contains(github.ref, 'refs/tags/') | |
| runs-on: ubuntu-latest | |
| environment: release | |
| permissions: | |
| id-token: write # mandatory for trusted publishing | |
| contents: write # mandatory for making repo releases | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Download the build version | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: version | |
| path: . | |
| - name: Download build artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: distributions | |
| path: dist | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.11" | |
| - name: Extract the release changelog | |
| run: | | |
| python ./scripts/extract-release-changelog.py | |
| python ./scripts/determine-release-type.py | |
| - name: Publish to GitHub | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| body_path: "CHANGELOG_RELEASE.md" | |
| prerelease: ${{ env.IS_PRERELEASE }} | |
| files: | | |
| dist/*.tar.gz | |
| dist/*.whl | |
| - name: Publish to PyPI | |
| uses: pypa/gh-action-pypi-publish@release/v1 |