-
Notifications
You must be signed in to change notification settings - Fork 0
237 lines (200 loc) · 7.24 KB
/
Copy pathci.yml
File metadata and controls
237 lines (200 loc) · 7.24 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
name: CI
on:
push:
branches:
- main
- master
pull_request:
branches:
- main
- master
env:
LANG: "en_US.utf-8"
LC_ALL: "en_US.utf-8"
PYTHONIOENCODING: "UTF-8"
jobs:
test:
name: Tests (Python ${{ matrix.python-version }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12"]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Cache apt packages
uses: actions/cache@v4
with:
path: /var/cache/apt/archives
key: ${{ runner.os }}-apt-${{ hashFiles('.github/workflows/ci.yml') }}
restore-keys: |
${{ runner.os }}-apt-
- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y graphviz imagemagick tmux fd-find ripgrep
# Create symlinks for fd (Ubuntu packages it as fd-find)
sudo ln -sf /usr/bin/fdfind /usr/local/bin/fd
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install uv
uses: astral-sh/setup-uv@v4
with:
version: "latest"
enable-cache: true
- name: Install just
uses: extractions/setup-just@v3
- name: Cache uv dependencies
uses: actions/cache@v4
with:
path: |
~/.cache/uv
.venv
key: ${{ runner.os }}-uv-${{ matrix.python-version }}-${{ hashFiles('pyproject.toml', 'uv.lock') }}
restore-keys: |
${{ runner.os }}-uv-${{ matrix.python-version }}-
${{ runner.os }}-uv-
- name: Install dependencies
run: uv sync
- name: Run tests with coverage
run: |
uv run coverage run --rcfile=config/coverage.pytest.ini -m pytest tests -c config/pytest.ini
uv run coverage combine
uv run coverage report --precision=2
uv run coverage xml
docs:
name: Build and Deploy Documentation
runs-on: ubuntu-latest
needs: test
# Only run on main/master branch pushes
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master')
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all history for git-changelog
- name: Cache apt packages
uses: actions/cache@v4
with:
path: /var/cache/apt/archives
key: ${{ runner.os }}-apt-${{ hashFiles('.github/workflows/ci.yml') }}
restore-keys: |
${{ runner.os }}-apt-
- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y graphviz imagemagick tmux fd-find ripgrep
# Create symlinks for fd (Ubuntu packages it as fd-find)
sudo ln -sf /usr/bin/fdfind /usr/local/bin/fd
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install uv
uses: astral-sh/setup-uv@v4
with:
version: "latest"
enable-cache: true
- name: Install just
uses: extractions/setup-just@v3
- name: Cache uv dependencies
uses: actions/cache@v4
with:
path: |
~/.cache/uv
.venv
key: ${{ runner.os }}-uv-3.11-${{ hashFiles('pyproject.toml', 'uv.lock') }}
restore-keys: |
${{ runner.os }}-uv-3.11-
${{ runner.os }}-uv-
- name: Install dependencies
run: uv sync
- name: Build documentation
run: |
just docs
# Ensure badge files are in the site directory
mkdir -p ./site/img
cp docs/img/badge_*.svg ./site/img/ 2>/dev/null || true
ls -la ./site/img/
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./site
cname: ${{ vars.DOCS_CNAME }} # Optional: set this in repository variables if you have a custom domain
coverage-badge:
name: Update Coverage Badge
runs-on: ubuntu-latest
needs: test
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master')
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Cache apt packages
uses: actions/cache@v4
with:
path: /var/cache/apt/archives
key: ${{ runner.os }}-apt-${{ hashFiles('.github/workflows/ci.yml') }}
restore-keys: |
${{ runner.os }}-apt-
- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y graphviz imagemagick tmux fd-find ripgrep
# Create symlinks for fd (Ubuntu packages it as fd-find)
sudo ln -sf /usr/bin/fdfind /usr/local/bin/fd
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install uv
uses: astral-sh/setup-uv@v4
with:
version: "latest"
enable-cache: true
- name: Install just
uses: extractions/setup-just@v3
- name: Cache uv dependencies
uses: actions/cache@v4
with:
path: |
~/.cache/uv
.venv
key: ${{ runner.os }}-uv-3.11-${{ hashFiles('pyproject.toml', 'uv.lock') }}
restore-keys: |
${{ runner.os }}-uv-3.11-
${{ runner.os }}-uv-
- name: Install dependencies
run: uv sync
- name: Generate coverage report
run: |
uv run coverage run --rcfile=config/coverage.pytest.ini -m pytest tests -c config/pytest.ini
uv run coverage combine
uv run coverage report --precision=2 > coverage_report.txt
- name: Extract coverage percentage
id: coverage
run: |
COVERAGE=$(grep "TOTAL" coverage_report.txt | awk '{print $4}' | sed 's/%//' | head -1)
echo "Coverage: $COVERAGE%"
echo "percentage=$COVERAGE" >> $GITHUB_OUTPUT
- name: Create coverage badge
run: |
COVERAGE=$(grep "TOTAL" coverage_report.txt | awk '{print $4}' | sed 's/%//' | head -1)
echo "Coverage: $COVERAGE%"
COLOR="red"
if (( $(echo "$COVERAGE > 80" | bc -l) )); then COLOR="brightgreen"; fi
if (( $(echo "$COVERAGE > 60 && $COVERAGE <= 80" | bc -l) )); then COLOR="yellow"; fi
# Create a simple coverage badge URL for README
echo "Add this to your README:"
echo "[](https://github.com/axiros/docutools/actions/workflows/ci.yml)"
- name: Commit coverage files
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 -f coverage.xml coverage_report.txt || true
git diff --staged --quiet || git commit -m "Update coverage reports" || true
git push || true