-
Notifications
You must be signed in to change notification settings - Fork 2
174 lines (147 loc) · 5.03 KB
/
ci.yaml
File metadata and controls
174 lines (147 loc) · 5.03 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
name: CI Pipeline
on:
push:
branches:
- main
- develop
pull_request:
branches:
- main
- develop
types:
- opened
- synchronize
- reopened
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@v5
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:
name: Docs
runs-on: ubuntu-latest
permissions:
contents: write # needed to push to gh-pages
# Only build+deploy docs when main is updated (i.e., after PR merge)
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
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
mkdir -p docs/source/api
sphinx-apidoc -o docs/source/api codes
- name: Build HTML with Sphinx
run: |
source .venv/bin/activate
sphinx-build -b html docs/source docs/_build/html
- name: Deploy docs to gh-pages
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: docs/_build/html
publish_branch: gh-pages
user_name: "GitHub Actions"
user_email: "actions@github.com"
force_orphan: false