-
Notifications
You must be signed in to change notification settings - Fork 153
126 lines (104 loc) · 3.57 KB
/
ci-tests.yml
File metadata and controls
126 lines (104 loc) · 3.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
name: tests
on:
push:
branches: [ main, dev ]
pull_request:
branches: [ main, dev ]
workflow_dispatch:
env:
PYTHONUTF8: "1"
PYTHONIOENCODING: "utf-8"
jobs:
tests-with-vcr:
strategy:
matrix:
os: [ "ubuntu-latest" ]
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
defaults:
run:
shell: bash
runs-on: ${{ matrix.os }}
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
id: setup-python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install uv
uses: astral-sh/setup-uv@v6
with:
enable-cache: true
- name: Install dependencies
run: uv sync --all-groups
- name: Code formatting and linting checks
run: |
uv run ruff check contextgem dev tests
uv run ruff format --check contextgem dev tests
- name: Type checking
run: |
uv run pyright
- name: Dependency health check
run: |
uv run deptry .
- name: Docstring coverage check
run: |
uv run interrogate
- name: Run coverage (with VCR)
run: |
uv run coverage run --source contextgem -m pytest --maxfail=1 --disable-warnings -v
uv run coverage report -m
uv run coverage xml -o coverage_quick.xml
- name: Extract coverage
id: get_coverage
run: |
COVERAGE=$(python -c "import xml.etree.ElementTree as ET; print(round(float(ET.parse('coverage_quick.xml').getroot().attrib['line-rate'])*100))")
echo "percentage=$COVERAGE" >> $GITHUB_OUTPUT
# Determine badge color based on coverage percentage
if [ $COVERAGE -ge 80 ]; then
echo "color=success" >> $GITHUB_OUTPUT
elif [ $COVERAGE -ge 60 ]; then
echo "color=yellow" >> $GITHUB_OUTPUT
else
echo "color=critical" >> $GITHUB_OUTPUT
fi
- name: Upload coverage artifact
if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.14'
uses: actions/upload-artifact@v4
with:
name: coverage-data
path: |
coverage_quick.xml
retention-days: 1
update-badge:
needs: tests-with-vcr
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
steps:
- name: Download coverage artifact
uses: actions/download-artifact@v4
with:
name: coverage-data
- name: Extract coverage
id: get_coverage
run: |
COVERAGE=$(python -c "import xml.etree.ElementTree as ET; print(round(float(ET.parse('coverage_quick.xml').getroot().attrib['line-rate'])*100))")
echo "percentage=$COVERAGE" >> $GITHUB_OUTPUT
# Determine badge color based on coverage percentage
if [ $COVERAGE -ge 80 ]; then
echo "color=success" >> $GITHUB_OUTPUT
elif [ $COVERAGE -ge 60 ]; then
echo "color=yellow" >> $GITHUB_OUTPUT
else
echo "color=critical" >> $GITHUB_OUTPUT
fi
- name: Update coverage badge
uses: schneegans/dynamic-badges-action@v1.7.0
with:
auth: ${{ secrets.GIST_SECRET }}
gistID: daaee00e1dfff7a29ca10a922ec3becd
filename: coverage.json
label: coverage
message: ${{ steps.get_coverage.outputs.percentage }}%
color: ${{ steps.get_coverage.outputs.color }}