|
| 1 | +name: Publish to PyPI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - '[0-9]+.[0-9]+.[0-9]' |
| 7 | + - 'v[0-9]+.[0-9]+.[0-9]' |
| 8 | + - 'V[0-9]+.[0-9]+.[0-9]' |
| 9 | + |
| 10 | +jobs: |
| 11 | + publish: |
| 12 | + runs-on: ubuntu-latest |
| 13 | + strategy: |
| 14 | + matrix: |
| 15 | + python-version: ["3.11"] |
| 16 | + |
| 17 | + permissions: |
| 18 | + id-token: write |
| 19 | + |
| 20 | + steps: |
| 21 | + - uses: actions/checkout@v4 |
| 22 | + |
| 23 | + - name: Install Poetry |
| 24 | + uses: snok/install-poetry@v1 |
| 25 | + with: |
| 26 | + virtualenvs-create: true |
| 27 | + virtualenvs-in-project: true |
| 28 | + |
| 29 | + - name: Set up Python ${{ matrix.python-version }} |
| 30 | + uses: actions/setup-python@v5 |
| 31 | + with: |
| 32 | + python-version: ${{ matrix.python-version }} |
| 33 | + cache: 'poetry' |
| 34 | + |
| 35 | + - name: Install dependencies |
| 36 | + run: | |
| 37 | + poetry install --no-interaction |
| 38 | + pip install -U ruff mypy |
| 39 | +
|
| 40 | + - name: Set version from tag |
| 41 | + run: | |
| 42 | + VERSION=${GITHUB_REF#refs/tags/} # Extract the tag (e.g., v1.0.0 or V2.3.4) |
| 43 | + VERSION=${VERSION#v} # Remove 'v' prefix if present |
| 44 | + VERSION=${VERSION#V} # Remove 'V' prefix if present |
| 45 | + echo "Setting version to $VERSION" |
| 46 | + poetry version $VERSION |
| 47 | +
|
| 48 | + - name: Run ruff format check |
| 49 | + if: always() |
| 50 | + run: poetry run ruff format --check --diff . |
| 51 | + |
| 52 | + - name: Run ruff lint check |
| 53 | + if: always() |
| 54 | + run: poetry run ruff check --diff . |
| 55 | + |
| 56 | + - name: Run tests with coverage |
| 57 | + if: always() |
| 58 | + run: poetry run pytest --cov=${{ github.event.repository.name }} --cov-report=xml |
| 59 | + |
| 60 | + - name: Upload coverage report |
| 61 | + uses: codecov/codecov-action@v5 |
| 62 | + with: |
| 63 | + fail_ci_if_error: true |
| 64 | + files: ./coverage.xml |
| 65 | + token: ${{ secrets.CODECOV_TOKEN }} |
| 66 | + |
| 67 | + - name: Build packages |
| 68 | + run: poetry build |
| 69 | + |
| 70 | + - name: Publish package distributions to PyPI |
| 71 | + uses: pypa/gh-action-pypi-publish@release/v1 |
0 commit comments