-
Notifications
You must be signed in to change notification settings - Fork 0
127 lines (106 loc) · 4.39 KB
/
ci.yml
File metadata and controls
127 lines (106 loc) · 4.39 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
127
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
name: CI
on:
push:
# Use ["main", "master"] for CI only on the default branch.
# Use ["**"] for CI on all branches.
branches: ["main", "master"]
pull_request:
branches: ["main", "master"]
permissions:
contents: write
jobs:
build:
strategy:
matrix:
# Update this as needed:
# Common platforms: ["ubuntu-latest", "macos-latest", "windows-latest"]
os: ["ubuntu-latest"]
python-version: ["3.11", "3.12", "3.13"]
# Linux only by default. Use ${{ matrix.os }} for other OSes.
runs-on: ${{ matrix.os }}
steps:
# Generally following uv docs:
# https://docs.astral.sh/uv/guides/integration/github/
- name: Checkout (official GitHub action)
uses: actions/checkout@v4
with:
# Important for versioning plugins:
fetch-depth: 0
- name: Install uv (official Astral action)
uses: astral-sh/setup-uv@v5
with:
# Update this as needed:
version: "0.9.5"
enable-cache: true
python-version: ${{ matrix.python-version }}
- name: Set up Python (using uv)
run: uv python install
# Alternately can use the official Python action:
# - name: Set up Python (using actions/setup-python)
# uses: actions/setup-python@v5
# with:
# python-version: ${{ matrix.python-version }}
- name: Install all dependencies
run: uv sync --all-extras
- name: Check formatting
continue-on-error: true
run: uv run ruff format --check .
- name: Run type checking
run: uv run basedpyright src/ || true
- name: Run tests with coverage
run: uv run pytest --cov=src/python_package_folder --cov-report=xml --cov-report=term tests/
- name: Generate coverage badge
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master'
run: |
python -c "
import xml.etree.ElementTree as ET
import re
# Parse coverage.xml
tree = ET.parse('coverage.xml')
root = tree.getroot()
# Get coverage percentage
line_rate = float(root.get('line-rate', 0))
coverage_percent = int(line_rate * 100)
# Determine color based on coverage
if coverage_percent >= 80:
color = '44cc11'
elif coverage_percent >= 60:
color = 'dfb317'
elif coverage_percent >= 40:
color = 'fe7d37'
else:
color = 'e05d44'
# Generate SVG badge
svg = f'''<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"99\" height=\"20\">
<linearGradient id=\"b\" x2=\"0\" y2=\"100%\">
<stop offset=\"0\" stop-color=\"#bbb\" stop-opacity=\".1\"/>
<stop offset=\"1\" stop-opacity=\".1\"/>
</linearGradient>
<mask id=\"a\">
<rect width=\"99\" height=\"20\" rx=\"3\" fill=\"#fff\"/>
</mask>
<g mask=\"url(#a)\">
<path fill=\"#555\" d=\"M0 0h63v20H0z\"/>
<path fill=\"#{color}\" d=\"M63 0h36v20H63z\"/>
<path fill=\"url(#b)\" d=\"M0 0h99v20H0z\"/>
</g>
<g fill=\"#fff\" text-anchor=\"middle\" font-family=\"DejaVu Sans,Verdana,Geneva,sans-serif\" font-size=\"11\">
<text x=\"31.5\" y=\"15\" fill=\"#010101\" fill-opacity=\".3\">coverage</text>
<text x=\"31.5\" y=\"14\">coverage</text>
<text x=\"81\" y=\"15\" fill=\"#010101\" fill-opacity=\".3\">{coverage_percent}%</text>
<text x=\"81\" y=\"14\">{coverage_percent}%</text>
</g>
</svg>'''
with open('coverage.svg', 'w') as f:
f.write(svg)
"
- name: Commit coverage badge
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master'
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add coverage.svg || true
git diff --staged --quiet || git commit -m "Update coverage badge [skip ci]"
git push || true