Skip to content

Commit f2c9297

Browse files
committed
Add an alternative Precommit workflow
1 parent 32bd415 commit f2c9297

15 files changed

Lines changed: 1202 additions & 40 deletions

.github/workflows/precommit.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: Precommit
2+
3+
on:
4+
workflow_dispatch:
5+
pull_request:
6+
7+
concurrency:
8+
group: ${{ github.workflow }}-${{ github.ref }}
9+
cancel-in-progress: true
10+
11+
jobs:
12+
test:
13+
name: Precommit
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout repository
17+
uses: actions/checkout@v6
18+
with:
19+
fetch-depth: 0
20+
# We will handle submodules manually after fixing ownership
21+
submodules: 'false'
22+
23+
- name: Update submodules
24+
run: |
25+
git config --global --add safe.directory "$GITHUB_WORKSPACE"
26+
git submodule update --init --recursive
27+
28+
- name: Configure precommit server
29+
run: |
30+
cd tools/precommit
31+
./start_local_server.sh &
32+
33+
- name: Wait for precommit server
34+
run: |
35+
for i in {1..300}; do
36+
if curl -fs -o /dev/null http://127.0.0.1:8080/ 2>/dev/null; then
37+
echo "precommit server is ready"
38+
exit 0
39+
fi
40+
sleep 1
41+
done
42+
43+
echo "precommit server did not become ready" >&2
44+
echo "==== precommit server log ====" >&2
45+
cat "$RUNNER_TEMP/precommit-server.log" >&2 || true
46+
exit 1
47+
48+
- name: Run precommit
49+
env:
50+
ABACUS_PRECOMMIT_SERVER: "http://127.0.0.1:8080"
51+
run: |
52+
if ! ./tools/precommit/precommit.py --no-cache; then
53+
echo ""
54+
echo "********************************************"
55+
echo "* *"
56+
echo "* O/ Try running ./make_pretty.sh *"
57+
echo "* /| *"
58+
echo "* / \\ *"
59+
echo "********************************************"
60+
echo ""
61+
exit 1
62+
fi

.github/workflows/test.yml

Lines changed: 65 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -32,214 +32,239 @@ jobs:
3232
- name: Install CI tools
3333
run: |
3434
sudo apt-get update
35-
sudo apt-get install -y ccache ca-certificates python-is-python3 python3-pip
36-
sudo pip install clang-format clang-tidy
35+
sudo apt-get install -y ccache ca-certificates python-is-python3
3736
3837
- name: Configure
3938
run: |
4039
cmake -B build -DBUILD_TESTING=ON -DENABLE_MLALGO=ON -DENABLE_LIBXC=ON -DENABLE_LIBRI=ON -DENABLE_GOOGLEBENCH=ON -DENABLE_RAPIDJSON=ON -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -DENABLE_FLOAT_FFTW=ON
4140
42-
# Temporarily removed because no one maintains this now.
43-
# And it will break the CI test workflow.
44-
45-
# - uses: pre-commit/action@v3.0.1
46-
# with:
47-
# extra_args:
48-
# --from-ref ${{ github.event.pull_request.base.sha }}
49-
# --to-ref ${{ github.event.pull_request.head.sha }}
50-
# continue-on-error: true
51-
# - uses: pre-commit-ci/lite-action@v1.0.3
52-
5341
- name: Build
5442
run: |
5543
cmake --build build -j8
5644
cmake --install build
5745
46+
- name: Prepare ctest wrapper
47+
run: |
48+
cat > "$RUNNER_TEMP/run_ctest.sh" <<'EOF'
49+
#!/usr/bin/env bash
50+
set +e
51+
52+
name="$1"
53+
shift
54+
55+
echo "::group::$name"
56+
ctest --test-dir build -V --timeout 1700 "$@"
57+
status=$?
58+
echo "::endgroup::"
59+
60+
if [ "$status" -ne 0 ]; then
61+
echo "$name" >> "$RUNNER_TEMP/failed-tests.txt"
62+
echo "::error title=$name failed::ctest exited with status $status"
63+
fi
64+
65+
exit 0
66+
EOF
67+
68+
chmod +x "$RUNNER_TEMP/run_ctest.sh"
69+
5870
- name: Integrated Tests Preparation
5971
env:
6072
GTEST_COLOR: 'yes'
6173
OMP_NUM_THREADS: '2'
6274
run: |
63-
ctest --test-dir build -V --timeout 1700 -R integrated_test
75+
"$RUNNER_TEMP/run_ctest.sh" "Integrated Tests Preparation" -R integrated_test
6476
6577
- name: Module_Base Unittests
6678
env:
6779
GTEST_COLOR: 'yes'
6880
OMP_NUM_THREADS: '2'
6981
run: |
70-
ctest --test-dir build -V --timeout 1700 -R MODULE_BASE
82+
"$RUNNER_TEMP/run_ctest.sh" "Module_Base Unittests" -R MODULE_BASE
7183
7284
- name: Module_IO Unittests
7385
env:
7486
GTEST_COLOR: 'yes'
7587
OMP_NUM_THREADS: '2'
7688
run: |
77-
ctest --test-dir build -V --timeout 1700 -R MODULE_IO
89+
"$RUNNER_TEMP/run_ctest.sh" "Module_IO Unittests" -R MODULE_IO
7890
7991
- name: Module_HSolver Unittests
8092
env:
8193
GTEST_COLOR: 'yes'
8294
OMP_NUM_THREADS: '2'
8395
run: |
84-
ctest --test-dir build -V --timeout 1700 -R MODULE_HSOLVER -E PERF_MODULE_HSOLVER_KERNELS
96+
"$RUNNER_TEMP/run_ctest.sh" "Module_HSolver Unittests" -R MODULE_HSOLVER -E PERF_MODULE_HSOLVER_KERNELS
8597
8698
- name: Module_Cell Unittests
8799
env:
88100
GTEST_COLOR: 'yes'
89101
OMP_NUM_THREADS: '2'
90102
run: |
91-
ctest --test-dir build -V --timeout 1700 -R MODULE_CELL
103+
"$RUNNER_TEMP/run_ctest.sh" "Module_Cell Unittests" -R MODULE_CELL
92104
93105
- name: Module_MD Unittests
94106
env:
95107
GTEST_COLOR: 'yes'
96108
OMP_NUM_THREADS: '2'
97109
run: |
98-
ctest --test-dir build -V --timeout 1700 -R MODULE_MD
110+
"$RUNNER_TEMP/run_ctest.sh" "Module_MD Unittests" -R MODULE_MD
99111
100112
- name: Module_Psi Unittests
101113
env:
102114
GTEST_COLOR: 'yes'
103115
OMP_NUM_THREADS: '2'
104116
run: |
105-
ctest --test-dir build -V --timeout 1700 -R MODULE_PSI
117+
"$RUNNER_TEMP/run_ctest.sh" "Module_Psi Unittests" -R MODULE_PSI
106118
107119
- name: Module_RI Unittests
108120
env:
109121
GTEST_COLOR: 'yes'
110122
OMP_NUM_THREADS: '2'
111123
run: |
112-
ctest --test-dir build -V --timeout 1700 -R MODULE_RI
124+
"$RUNNER_TEMP/run_ctest.sh" "Module_RI Unittests" -R MODULE_RI
113125
114126
- name: Module_Estate Unittests
115127
env:
116128
GTEST_COLOR: 'yes'
117129
OMP_NUM_THREADS: '2'
118130
run: |
119-
ctest --test-dir build -V --timeout 1700 -R MODULE_ESTATE
131+
"$RUNNER_TEMP/run_ctest.sh" "Module_Estate Unittests" -R MODULE_ESTATE
120132
121133
- name: Module_Hamilt Unittests
122134
env:
123135
GTEST_COLOR: 'yes'
124136
OMP_NUM_THREADS: '2'
125137
run: |
126-
ctest --test-dir build -V --timeout 1700 -R MODULE_HAMILT
138+
"$RUNNER_TEMP/run_ctest.sh" "Module_Hamilt Unittests" -R MODULE_HAMILT
127139
128140
- name: Module_PW Unittests
129141
env:
130142
GTEST_COLOR: 'yes'
131143
OMP_NUM_THREADS: '2'
132144
run: |
133-
ctest --test-dir build -V --timeout 1700 -R MODULE_PW
145+
"$RUNNER_TEMP/run_ctest.sh" "Module_PW Unittests" -R MODULE_PW
134146
135147
- name: Module_LCAO Unittests
136148
env:
137149
GTEST_COLOR: 'yes'
138150
OMP_NUM_THREADS: '2'
139151
run: |
140-
ctest --test-dir build -V --timeout 1700 -R MODULE_LCAO
152+
"$RUNNER_TEMP/run_ctest.sh" "Module_LCAO Unittests" -R MODULE_LCAO
141153
142154
- name: Module_AO Unittests
143155
env:
144156
GTEST_COLOR: 'yes'
145157
OMP_NUM_THREADS: '2'
146158
run: |
147-
ctest --test-dir build -V --timeout 1700 -R MODULE_AO
159+
"$RUNNER_TEMP/run_ctest.sh" "Module_AO Unittests" -R MODULE_AO
148160
149161
- name: Module_NAO Unittests
150162
env:
151163
GTEST_COLOR: 'yes'
152164
OMP_NUM_THREADS: '2'
153165
run: |
154-
ctest --test-dir build -V --timeout 1700 -R MODULE_NAO
166+
"$RUNNER_TEMP/run_ctest.sh" "Module_NAO Unittests" -R MODULE_NAO
155167
156168
- name: Module_RELAX Unittests
157169
env:
158170
GTEST_COLOR: 'yes'
159171
OMP_NUM_THREADS: '2'
160172
run: |
161-
ctest --test-dir build -V --timeout 1700 -R MODULE_RELAX
173+
"$RUNNER_TEMP/run_ctest.sh" "Module_RELAX Unittests" -R MODULE_RELAX
162174
163175
- name: Module_LR Unittests
164176
env:
165177
GTEST_COLOR: 'yes'
166178
OMP_NUM_THREADS: '2'
167179
run: |
168-
ctest --test-dir build -V --timeout 1700 -R MODULE_LR
180+
"$RUNNER_TEMP/run_ctest.sh" "Module_LR Unittests" -R MODULE_LR
169181
170182
- name: 01_PW Test
171183
env:
172184
GTEST_COLOR: 'yes'
173185
OMP_NUM_THREADS: '2'
174186
run: |
175-
ctest --test-dir build -V --timeout 1700 -R 01_PW
187+
"$RUNNER_TEMP/run_ctest.sh" "01_PW Test" -R 01_PW
176188
177189
- name: 02_NAO_Gamma Test
178190
env:
179191
GTEST_COLOR: 'yes'
180192
OMP_NUM_THREADS: '2'
181193
run: |
182-
ctest --test-dir build -V --timeout 1700 -R 02_NAO_Gamma
194+
"$RUNNER_TEMP/run_ctest.sh" "02_NAO_Gamma Test" -R 02_NAO_Gamma
183195
184196
- name: 03_NAO_multik Test
185197
env:
186198
GTEST_COLOR: 'yes'
187199
OMP_NUM_THREADS: '2'
188200
run: |
189-
ctest --test-dir build -V --timeout 1700 -R 03_NAO_multik
201+
"$RUNNER_TEMP/run_ctest.sh" "03_NAO_multik Test" -R 03_NAO_multik
190202
191203
- name: 04_FF Test
192204
env:
193205
GTEST_COLOR: 'yes'
194206
OMP_NUM_THREADS: '2'
195207
run: |
196-
ctest --test-dir build -V --timeout 1700 -R 04_FF
208+
"$RUNNER_TEMP/run_ctest.sh" "04_FF Test" -R 04_FF
197209
198210
- name: 05_rtTDDFT Test
199211
env:
200212
GTEST_COLOR: 'yes'
201213
OMP_NUM_THREADS: '2'
202214
run: |
203-
ctest --test-dir build -V --timeout 1700 -R 05_rtTDDFT
215+
"$RUNNER_TEMP/run_ctest.sh" "05_rtTDDFT Test" -R 05_rtTDDFT
204216
205217
- name: 06_SDFT Test
206218
env:
207219
GTEST_COLOR: 'yes'
208220
OMP_NUM_THREADS: '2'
209221
run: |
210-
ctest --test-dir build -V --timeout 1700 -R 06_SDFT
222+
"$RUNNER_TEMP/run_ctest.sh" "06_SDFT Test" -R 06_SDFT
211223
212224
- name: 07_OFDFT Test
213225
env:
214226
GTEST_COLOR: 'yes'
215227
OMP_NUM_THREADS: '2'
216228
run: |
217-
ctest --test-dir build -V --timeout 1700 -R 07_OFDFT
229+
"$RUNNER_TEMP/run_ctest.sh" "07_OFDFT Test" -R 07_OFDFT
218230
219231
- name: 08_EXX Test
220232
env:
221233
GTEST_COLOR: 'yes'
222234
OMP_NUM_THREADS: '2'
223235
run: |
224-
ctest --test-dir build -V --timeout 1700 -R 08_EXX
236+
"$RUNNER_TEMP/run_ctest.sh" "08_EXX Test" -R 08_EXX
225237
226238
- name: 09_DeePKS Test
227239
env:
228240
GTEST_COLOR: 'yes'
229241
OMP_NUM_THREADS: '2'
230242
run: |
231-
ctest --test-dir build -V --timeout 1700 -R 09_DeePKS
243+
"$RUNNER_TEMP/run_ctest.sh" "09_DeePKS Test" -R 09_DeePKS
232244
233245
- name: 10_others Test
234246
env:
235247
GTEST_COLOR: 'yes'
236248
OMP_NUM_THREADS: '2'
237249
run: |
238-
ctest --test-dir build -V --timeout 1700 -R 10_others
250+
"$RUNNER_TEMP/run_ctest.sh" "10_others Test" -R 10_others
239251
240252
- name: Other Unittests
241253
env:
242254
GTEST_COLOR: 'yes'
243255
OMP_NUM_THREADS: '2'
244256
run: |
245-
ctest --test-dir build -V --timeout 1700 -E 'integrate_test|01_PW|02_NAO_Gamma|03_NAO_multik|04_FF|05_rtTDDFT|06_SDFT|07_OFDFT|08_EXX|09_DeePKS|10_others|11_PW_GPU|12_NAO_Gamma_GPU|13_NAO_multik_GPU|15_rtTDDFT_GPU|16_SDFT_GPU|MODULE_BASE|MODULE_IO|MODULE_HSOLVER|MODULE_CELL|MODULE_MD|MODULE_PSI|MODULE_ESTATE|MODULE_RI|MODULE_HAMILT|MODULE_PW|MODULE_LCAO|MODULE_AO|MODULE_NAO|MODULE_RELAX|MODULE_LR'
257+
"$RUNNER_TEMP/run_ctest.sh" "Other Unittests" -E 'integrate_test|01_PW|02_NAO_Gamma|03_NAO_multik|04_FF|05_rtTDDFT|06_SDFT|07_OFDFT|08_EXX|09_DeePKS|10_others|11_PW_GPU|12_NAO_Gamma_GPU|13_NAO_multik_GPU|15_rtTDDFT_GPU|16_SDFT_GPU|MODULE_BASE|MODULE_IO|MODULE_HSOLVER|MODULE_CELL|MODULE_MD|MODULE_PSI|MODULE_ESTATE|MODULE_RI|MODULE_HAMILT|MODULE_PW|MODULE_LCAO|MODULE_AO|MODULE_NAO|MODULE_RELAX|MODULE_LR'
258+
259+
- name: Fail if any test group failed
260+
if: always()
261+
run: |
262+
if [ -s "$RUNNER_TEMP/failed-tests.txt" ]; then
263+
echo ""
264+
echo "The following test groups failed:"
265+
cat "$RUNNER_TEMP/failed-tests.txt"
266+
echo ""
267+
exit 1
268+
fi
269+
270+
echo "All test groups passed."

tools/precommit/Dockerfile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FROM ubuntu:24.04
2+
3+
# Based on CP2K's tools/precommit/Dockerfile, adapted for ABACUS.
4+
5+
WORKDIR /opt/abacus-precommit
6+
COPY install_requirements.sh requirements.txt ./
7+
RUN ./install_requirements.sh
8+
ENV PATH="/opt/venv/bin:/opt/abacus-precommit:$PATH"
9+
10+
ARG REVISION
11+
ENV REVISION=${REVISION}
12+
13+
COPY . ./
14+
CMD ["gunicorn", "--bind=:8080", "--workers=1", "--threads=8", "--timeout=0", "precommit_server:app"]
15+
16+
# EOF

0 commit comments

Comments
 (0)