-
Notifications
You must be signed in to change notification settings - Fork 2
212 lines (181 loc) · 6.62 KB
/
Copy pathci.yaml
File metadata and controls
212 lines (181 loc) · 6.62 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
name: CI Pipeline
on:
push:
branches:
- main
- develop
pull_request:
branches:
- main
- develop
permissions:
contents: write
checks: write
pull-requests: write
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10"]
steps:
- name: Check out the repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all history to support dependency checks
ref: ${{ github.head_ref || github.ref }}
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install uv
run: |
curl -LsSf https://astral.sh/uv/install.sh | sh
echo "$HOME/.cargo/bin" >> $GITHUB_PATH
- name: Setup Python environment with uv
run: |
uv venv
source .venv/bin/activate
uv pip install -e .
uv pip install --group dev
- name: Check for dependency changes
id: deps
run: |
# Determine if the event is a pull request
if [ "${{ github.event_name }}" == "pull_request" ]; then
echo "PR detected. Comparing with main branch."
# Fetch the main branch
git fetch origin main
# Compare the PR branch with main
CHANGED_FILES=$(git diff --name-only origin/main...HEAD)
else
echo "Push detected. Comparing with previous commit."
# For push events, compare with the previous commit
CHANGED_FILES=$(git diff --name-only HEAD~1 HEAD)
fi
echo "Changed files: $CHANGED_FILES"
# Check if pyproject.toml has changed
if echo "$CHANGED_FILES" | grep -qE '(^|/)pyproject\.toml$'; then
echo "dependencies-changed=true" >> $GITHUB_ENV
else
echo "dependencies-changed=false" >> $GITHUB_ENV
fi
- name: Generate requirements.txt
if: env.dependencies-changed == 'true'
run: |
source .venv/bin/activate
uv pip freeze > requirements.txt
- name: Commit and push updated requirements.txt
if: |
env.dependencies-changed == 'true' &&
github.event_name == 'pull_request' &&
github.event.pull_request.head.repo.full_name == github.repository
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git add requirements.txt
git diff --cached --exit-code || git commit -m "Update requirements.txt [skip ci]"
git push || echo "Nothing to push"
- name: Run Black (auto-reformat)
run: |
source .venv/bin/activate
black .
- name: Run isort (auto-reformat)
run: |
source .venv/bin/activate
isort .
- name: Run pytest and generate coverage report
run: |
source .venv/bin/activate
pytest --cov-report=term-missing:skip-covered --cov=codes test/ --cov-report=xml:coverage.xml
- name: Upload results to Codecov
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage.xml # Path to the coverage XML file, adjust if necessary
fail_ci_if_error: true # Optional, ensures the CI fails if Codecov upload fails
docs:
runs-on: ubuntu-latest
permissions:
contents: write # needed to push to gh-pages
pull-requests: write # needed to comment on PRs (preview link)
strategy:
matrix:
python-version: ["3.10"]
steps:
- name: Check out the repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install uv
run: |
curl -LsSf https://astral.sh/uv/install.sh | sh
echo "$HOME/.cargo/bin" >> $GITHUB_PATH
- name: Setup Python environment with uv
run: |
uv venv
source .venv/bin/activate
uv pip install -e .
uv pip install --group dev
- name: Generate API Documentation with Sphinx
run: |
source .venv/bin/activate
sphinx-apidoc -o docs/ codes
- name: Build HTML with Sphinx
run: |
source .venv/bin/activate
sphinx-build -b html docs/ docs/_build
# ----------------------------
# Production deploy (main only)
# ----------------------------
- name: Deploy docs to gh-pages (production)
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: docs/_build
publish_branch: gh-pages
user_name: "GitHub Actions"
user_email: "actions@github.com"
force_orphan: false
# ----------------------------
# PR preview deploy (PRs only, same-repo only)
# ----------------------------
- name: Deploy docs preview to gh-pages (PR)
if: |
github.event_name == 'pull_request' &&
github.event.pull_request.base.repo.full_name == github.repository &&
github.event.pull_request.head.repo.full_name == github.repository
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: docs/_build
publish_branch: gh-pages
destination_dir: pr-${{ github.event.pull_request.number }}
user_name: "GitHub Actions"
user_email: "actions@github.com"
- name: Comment preview URL on PR
if: |
github.event_name == 'pull_request' &&
github.event.pull_request.base.repo.full_name == github.repository &&
github.event.pull_request.head.repo.full_name == github.repository
uses: actions/github-script@v7
with:
script: |
const prNumber = context.payload.pull_request.number;
const owner = context.repo.owner;
const repo = context.repo.repo;
// GitHub Pages project URL: https://<owner>.github.io/<repo>/
const base = `https://${owner}.github.io/${repo}/`;
const url = `${base}pr-${prNumber}/`;
const body = `📚 Docs preview: ${url}`;
await github.rest.issues.createComment({
owner,
repo,
issue_number: prNumber,
body
});