ci: automate releases on merge to main (#32) #1
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: Release | |
| # Publish on merge to main. python-semantic-release inspects the Conventional | |
| # Commit messages since the last "v*" tag, decides the next version (or that no | |
| # release is warranted), bumps pyproject.toml, tags, creates a GitHub Release, | |
| # and we then upload the built artifacts to PyPI. | |
| # | |
| # The version-bump commit it pushes back to main contains "[skip ci]" so this | |
| # workflow does not retrigger itself. | |
| on: | |
| push: | |
| branches: [main] | |
| # Never run two releases concurrently. | |
| concurrency: | |
| group: release | |
| cancel-in-progress: false | |
| jobs: | |
| test: | |
| name: Unit tests | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Install uv | |
| uses: astral-sh/setup-uv@v5 | |
| with: | |
| python-version: "3.12" | |
| - name: Install package + dev deps | |
| # setup-uv already created .venv and set VIRTUAL_ENV. | |
| run: uv pip install -e ".[dev]" | |
| - name: Run unit tests | |
| run: | | |
| uv run pytest tests/ \ | |
| --ignore=tests/test_acceptance.py \ | |
| --ignore=tests/test_query.py \ | |
| -q | |
| release: | |
| name: Semantic Release | |
| runs-on: ubuntu-latest | |
| needs: test | |
| # Guard against forks: only the canonical repo should publish. | |
| if: github.repository == 'lightdash/python-sdk' | |
| permissions: | |
| contents: write # push the version bump/tag and create the GitHub Release | |
| id-token: write # PyPI Trusted Publishing (OIDC) | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 # semantic-release needs full history + tags | |
| - name: Python Semantic Release | |
| id: release | |
| uses: python-semantic-release/python-semantic-release@v9 | |
| with: | |
| github_token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Publish to PyPI | |
| if: steps.release.outputs.released == 'true' | |
| uses: pypa/gh-action-pypi-publish@release/v1 | |
| - name: Upload artifacts to the GitHub Release | |
| if: steps.release.outputs.released == 'true' | |
| uses: python-semantic-release/publish-action@v9 | |
| with: | |
| github_token: ${{ secrets.GITHUB_TOKEN }} | |
| tag: ${{ steps.release.outputs.tag }} |