Skip to content

Commit a5f779d

Browse files
authored
👷 Add setup to run tests on CI (#6)
1 parent 4fe3a58 commit a5f779d

File tree

12 files changed

+311
-699
lines changed

12 files changed

+311
-699
lines changed

.github/workflows/smokeshow.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: Smokeshow
2+
3+
on:
4+
workflow_run:
5+
workflows:
6+
- Test
7+
types:
8+
- completed
9+
10+
permissions:
11+
statuses: write
12+
13+
env:
14+
UV_SYSTEM_PYTHON: 1
15+
16+
jobs:
17+
smokeshow:
18+
if: ${{ github.event.workflow_run.conclusion == 'success' }}
19+
runs-on: ubuntu-latest
20+
21+
steps:
22+
- name: Dump GitHub context
23+
env:
24+
GITHUB_CONTEXT: ${{ toJson(github) }}
25+
run: echo "$GITHUB_CONTEXT"
26+
- uses: actions/checkout@v5
27+
- uses: actions/setup-python@v6
28+
with:
29+
python-version: '3.9'
30+
- name: Setup uv
31+
uses: astral-sh/setup-uv@v7
32+
with:
33+
version: "0.4.15"
34+
enable-cache: true
35+
cache-dependency-glob: |
36+
requirements**.txt
37+
pyproject.toml
38+
- run: uv pip install -r requirements-tests.txt
39+
- uses: actions/download-artifact@v5
40+
with:
41+
name: coverage-html
42+
path: htmlcov
43+
github-token: ${{ secrets.GITHUB_TOKEN }}
44+
run-id: ${{ github.event.workflow_run.id }}
45+
# Try 5 times to upload coverage to smokeshow
46+
- name: Upload coverage to Smokeshow
47+
run: |
48+
for i in 1 2 3 4 5; do
49+
if smokeshow upload htmlcov; then
50+
echo "Smokeshow upload success!"
51+
break
52+
fi
53+
echo "Smokeshow upload error, sleep 1 sec and try again."
54+
sleep 1
55+
done
56+
env:
57+
SMOKESHOW_GITHUB_STATUS_DESCRIPTION: Coverage {coverage-percentage}
58+
SMOKESHOW_GITHUB_COVERAGE_THRESHOLD: 100
59+
SMOKESHOW_GITHUB_CONTEXT: coverage
60+
SMOKESHOW_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
61+
SMOKESHOW_GITHUB_PR_HEAD_SHA: ${{ github.event.workflow_run.head_sha }}
62+
SMOKESHOW_AUTH_KEY: ${{ secrets.SMOKESHOW_AUTH_KEY }}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Test Redistribute
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
types:
9+
- opened
10+
- synchronize
11+
12+
env:
13+
UV_SYSTEM_PYTHON: 1
14+
15+
jobs:
16+
test-redistribute:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Dump GitHub context
20+
env:
21+
GITHUB_CONTEXT: ${{ toJson(github) }}
22+
run: echo "$GITHUB_CONTEXT"
23+
- uses: actions/checkout@v5
24+
- name: Set up Python
25+
uses: actions/setup-python@v6
26+
with:
27+
python-version: "3.10"
28+
- name: Install build dependencies
29+
run: pip install build
30+
- name: Build source distribution
31+
run: python -m build --sdist
32+
- name: Decompress source distribution
33+
run: |
34+
cd dist
35+
tar xvf annotated_doc*.tar.gz
36+
- name: Install test dependencies
37+
run: |
38+
cd dist/annotated_doc*/
39+
pip install -r requirements-tests.txt
40+
- name: Run source distribution tests
41+
run: |
42+
cd dist/annotated_doc*/
43+
bash scripts/test.sh
44+
- name: Build wheel distribution
45+
run: |
46+
cd dist
47+
pip wheel --no-deps annotated_doc*.tar.gz
48+
49+
# https://github.com/marketplace/actions/alls-green#why
50+
test-redistribute-alls-green: # This job does nothing and is only used for the branch protection
51+
if: always()
52+
needs:
53+
- test-redistribute
54+
runs-on: ubuntu-latest
55+
steps:
56+
- name: Decide whether the needed jobs succeeded or failed
57+
uses: re-actors/alls-green@release/v1
58+
with:
59+
jobs: ${{ toJSON(needs) }}

.github/workflows/test.yml

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
name: Test
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
types:
9+
- opened
10+
- synchronize
11+
workflow_dispatch:
12+
inputs:
13+
debug_enabled:
14+
description: 'Run the build with tmate debugging enabled (https://github.com/marketplace/actions/debugging-with-tmate)'
15+
required: false
16+
default: 'false'
17+
schedule:
18+
# cron every week on monday
19+
- cron: "0 0 * * 1"
20+
21+
env:
22+
UV_SYSTEM_PYTHON: 1
23+
24+
jobs:
25+
test:
26+
strategy:
27+
matrix:
28+
os:
29+
- ubuntu-latest
30+
- windows-latest
31+
- macos-latest
32+
python-version:
33+
- "3.14"
34+
include:
35+
- os: macos-latest
36+
python-version: "3.8"
37+
- os: windows-latest
38+
python-version: "3.9"
39+
- os: ubuntu-latest
40+
python-version: "3.10"
41+
- os: macos-latest
42+
python-version: "3.11"
43+
- os: windows-latest
44+
python-version: "3.12"
45+
- os: ubuntu-latest
46+
python-version: "3.13"
47+
- os: macos-latest
48+
python-version: "3.13"
49+
fail-fast: false
50+
runs-on: ${{ matrix.os }}
51+
steps:
52+
- uses: actions/checkout@v5
53+
- name: Set up Python
54+
uses: actions/setup-python@v6
55+
with:
56+
python-version: ${{ matrix.python-version }}
57+
- name: Setup uv
58+
uses: astral-sh/setup-uv@v7
59+
with:
60+
version: "0.4.15"
61+
enable-cache: true
62+
cache-dependency-glob: |
63+
requirements**.txt
64+
pyproject.toml
65+
# Allow debugging with tmate
66+
- name: Setup tmate session
67+
uses: mxschmitt/action-tmate@v3
68+
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.debug_enabled == 'true' }}
69+
with:
70+
limit-access-to-actor: true
71+
- name: Install Dependencies
72+
run: uv pip install -r requirements-tests.txt
73+
- name: Lint
74+
run: bash scripts/lint.sh
75+
- run: mkdir coverage
76+
- name: Test
77+
run: bash scripts/test.sh
78+
env:
79+
COVERAGE_FILE: coverage/.coverage.${{ runner.os }}-py${{ matrix.python-version }}
80+
CONTEXT: ${{ runner.os }}-py${{ matrix.python-version }}
81+
- name: Store coverage files
82+
uses: actions/upload-artifact@v4
83+
with:
84+
name: coverage-${{ runner.os }}-${{ matrix.python-version }}
85+
path: coverage
86+
include-hidden-files: true
87+
88+
coverage-combine:
89+
needs:
90+
- test
91+
runs-on: ubuntu-latest
92+
steps:
93+
- uses: actions/checkout@v5
94+
- uses: actions/setup-python@v6
95+
with:
96+
python-version: '3.13'
97+
- name: Setup uv
98+
uses: astral-sh/setup-uv@v7
99+
with:
100+
version: "0.4.15"
101+
enable-cache: true
102+
cache-dependency-glob: |
103+
requirements**.txt
104+
pyproject.toml
105+
- name: Get coverage files
106+
uses: actions/download-artifact@v5
107+
with:
108+
pattern: coverage-*
109+
path: coverage
110+
merge-multiple: true
111+
# Allow debugging with tmate
112+
- name: Setup tmate session
113+
uses: mxschmitt/action-tmate@v3
114+
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.debug_enabled == 'true' }}
115+
with:
116+
limit-access-to-actor: true
117+
- name: Install Dependencies
118+
run: uv pip install -r requirements-tests.txt
119+
- run: ls -la coverage
120+
- run: coverage combine coverage
121+
- run: coverage report
122+
- run: coverage html --title "Coverage for ${{ github.sha }}"
123+
- name: Store coverage HTML
124+
uses: actions/upload-artifact@v4
125+
with:
126+
name: coverage-html
127+
path: htmlcov
128+
include-hidden-files: true
129+
130+
# https://github.com/marketplace/actions/alls-green#why
131+
alls-green: # This job does nothing and is only used for the branch protection
132+
if: always()
133+
needs:
134+
- coverage-combine
135+
runs-on: ubuntu-latest
136+
steps:
137+
- name: Decide whether the needed jobs succeeded or failed
138+
uses: re-actors/alls-green@release/v1
139+
with:
140+
jobs: ${{ toJSON(needs) }}

pyproject.toml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,12 @@ junit_family = "xunit2"
5858
parallel = true
5959
data_file = "coverage/.coverage"
6060
source = [
61-
"src",
61+
"src/annotated_doc",
62+
"tests",
6263
]
6364
context = '${CONTEXT}'
6465
dynamic_context = "test_function"
66+
relative_files = true
6567

6668
[tool.coverage.report]
6769
show_missing = true
@@ -91,10 +93,9 @@ ignore = [
9193
# Preserve types, even if a file imports `from __future__ import annotations`.
9294
keep-runtime-typing = true
9395

94-
[dependency-groups]
95-
dev = [
96-
"coverage>=7.6.1",
97-
"mypy>=1.14.1",
98-
"pytest>=8.3.5",
99-
"ruff>=0.14.1",
96+
[tool.uv.build-backend]
97+
source-include = [
98+
"tests/**",
99+
"requirements*.txt",
100+
"scripts/**",
100101
]

requirements-tests.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
-e .
2+
3+
pytest >=8.3.5
4+
coverage[toml] >=7.6.1
5+
mypy ==1.14.1
6+
ruff ==0.14.1
7+
smokeshow >=0.5.0

scripts/coverage.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
set -x
5+
6+
coverage combine
7+
coverage report
8+
coverage html

scripts/format.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env bash
2+
set -x
3+
4+
ruff check src tests scripts --fix
5+
ruff format src tests scripts

scripts/lint.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
set -x
5+
6+
mypy src
7+
ruff check src tests scripts
8+
ruff format src tests --check

scripts/test-cov-html.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
set -x
5+
6+
bash scripts/test.sh ${@}
7+
bash scripts/coverage.sh

scripts/test.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
set -x
5+
6+
coverage run -m pytest tests ${@}

0 commit comments

Comments
 (0)