|
| 1 | +name: Release |
| 2 | + |
| 3 | +# Publish on merge to main. python-semantic-release inspects the Conventional |
| 4 | +# Commit messages since the last "v*" tag, decides the next version (or that no |
| 5 | +# release is warranted), bumps pyproject.toml, tags, creates a GitHub Release, |
| 6 | +# and we then upload the built artifacts to PyPI. |
| 7 | +# |
| 8 | +# The version-bump commit it pushes back to main contains "[skip ci]" so this |
| 9 | +# workflow does not retrigger itself. |
| 10 | +on: |
| 11 | + push: |
| 12 | + branches: [main] |
| 13 | + |
| 14 | +# Never run two releases concurrently. |
| 15 | +concurrency: |
| 16 | + group: release |
| 17 | + cancel-in-progress: false |
| 18 | + |
| 19 | +jobs: |
| 20 | + test: |
| 21 | + name: Unit tests |
| 22 | + runs-on: ubuntu-latest |
| 23 | + steps: |
| 24 | + - uses: actions/checkout@v4 |
| 25 | + - name: Install uv |
| 26 | + uses: astral-sh/setup-uv@v5 |
| 27 | + with: |
| 28 | + python-version: "3.12" |
| 29 | + - name: Install package + dev deps |
| 30 | + # setup-uv already created .venv and set VIRTUAL_ENV. |
| 31 | + run: uv pip install -e ".[dev]" |
| 32 | + - name: Run unit tests |
| 33 | + run: | |
| 34 | + uv run pytest tests/ \ |
| 35 | + --ignore=tests/test_acceptance.py \ |
| 36 | + --ignore=tests/test_query.py \ |
| 37 | + -q |
| 38 | +
|
| 39 | + release: |
| 40 | + name: Semantic Release |
| 41 | + runs-on: ubuntu-latest |
| 42 | + needs: test |
| 43 | + # Guard against forks: only the canonical repo should publish. |
| 44 | + if: github.repository == 'lightdash/python-sdk' |
| 45 | + permissions: |
| 46 | + contents: write # push the version bump/tag and create the GitHub Release |
| 47 | + id-token: write # PyPI Trusted Publishing (OIDC) |
| 48 | + steps: |
| 49 | + - name: Checkout |
| 50 | + uses: actions/checkout@v4 |
| 51 | + with: |
| 52 | + fetch-depth: 0 # semantic-release needs full history + tags |
| 53 | + |
| 54 | + - name: Python Semantic Release |
| 55 | + id: release |
| 56 | + uses: python-semantic-release/python-semantic-release@v9 |
| 57 | + with: |
| 58 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 59 | + |
| 60 | + - name: Publish to PyPI |
| 61 | + if: steps.release.outputs.released == 'true' |
| 62 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 63 | + |
| 64 | + - name: Upload artifacts to the GitHub Release |
| 65 | + if: steps.release.outputs.released == 'true' |
| 66 | + uses: python-semantic-release/publish-action@v9 |
| 67 | + with: |
| 68 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 69 | + tag: ${{ steps.release.outputs.tag }} |
0 commit comments