Skip to content

Commit 482a44f

Browse files
authored
ci: automate releases on merge to main (#32)
1 parent 472e0f6 commit 482a44f

3 files changed

Lines changed: 131 additions & 0 deletions

File tree

.github/workflows/ci.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: CI
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches: [main]
7+
8+
# Cancel superseded runs on the same ref to save CI minutes.
9+
concurrency:
10+
group: ci-${{ github.ref }}
11+
cancel-in-progress: true
12+
13+
jobs:
14+
test:
15+
name: Unit tests (py${{ matrix.python-version }})
16+
runs-on: ubuntu-latest
17+
strategy:
18+
fail-fast: false
19+
matrix:
20+
# Floor and a current version; bump as supported range changes.
21+
python-version: ["3.9", "3.12"]
22+
steps:
23+
- uses: actions/checkout@v4
24+
25+
- name: Install uv
26+
uses: astral-sh/setup-uv@v5
27+
with:
28+
python-version: ${{ matrix.python-version }}
29+
30+
- name: Install package + dev deps
31+
# setup-uv already created .venv and set VIRTUAL_ENV.
32+
run: uv pip install -e ".[dev]"
33+
34+
- name: Run unit tests
35+
# test_acceptance.py and test_query.py require a live Lightdash
36+
# instance + credentials, so they are excluded from CI.
37+
run: |
38+
uv run pytest tests/ \
39+
--ignore=tests/test_acceptance.py \
40+
--ignore=tests/test_query.py \
41+
-q

.github/workflows/release.yml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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 }}

pyproject.toml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,24 @@ include = ["lightdash*"]
2828
testpaths = ["tests"]
2929
python_files = ["test_*.py"]
3030
log_cli_level = "DEBUG"
31+
32+
[build-system]
33+
requires = ["setuptools>=61.0"]
34+
build-backend = "setuptools.build_meta"
35+
36+
# Releases are automated by GitHub Actions (.github/workflows/release.yml).
37+
# python-semantic-release computes the next version from Conventional Commit
38+
# messages (feat: -> minor, fix: -> patch, BREAKING CHANGE -> major) since the
39+
# last "v*" tag, bumps the version below, tags, creates a GitHub Release, and
40+
# publishes to PyPI. Do not bump `version` by hand.
41+
[tool.semantic_release]
42+
version_toml = ["pyproject.toml:project.version"]
43+
build_command = "pip install build && python -m build"
44+
commit_message = "chore(release): v{version} [skip ci]"
45+
tag_format = "v{version}"
46+
47+
[tool.semantic_release.branches.main]
48+
match = "main"
49+
50+
[tool.semantic_release.changelog]
51+
exclude_commit_patterns = ['''chore\(release\):.*''']

0 commit comments

Comments
 (0)