-
Notifications
You must be signed in to change notification settings - Fork 229
383 lines (347 loc) · 16.3 KB
/
CI.yml
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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
# CI.yml
# This file contains the script used by GitHub actions to execute the Continuous Integration (CI)
# for RMG-Py. This includes building RMG and its dependencies, executing the unit tests,
# functional tests, database tests, and regression tests.
#
# This will run automatically on any push to any branch, but will only run one instance of
# itself at a time per branch (to avoid spawning tons of runners, which prevents them from
# executing).
#
# In the regression testing section of the action the term "Stable" or "Reference" refers to
# the 'correct answers' to the regression tests, i.e. the way that the main branch executes
# them. These 'answers' are re-generated daily, or on any push to main, and retrieved whenever
# a push is made to a non-main branch. The new proposed changes are referred to as "Dynamic".
#
#
# Changelog:
# 2023-04 - Jackson Burns - Added this header, regression tests, cleanup of action in
# in general, and documentation throughout the file.
# 2023-05 - added Docker build steps
# 2023-05-12 - added changes to allow running on forks
# 2023-06-06 - added matrix build for libstdcxx-ng versions 12 and 13 on ubuntu. Only expect 12 to work.
# 2023-06-07 - updated regression testing. Now fails if significant changes are detected.
# 2023-06-15 - revert changes from 06-06, both now work
# 2023-06-27 - add option to run from RMG-database with GitHub resuable workflows
# 2023-07-17 - made it pass by default
# 2023-07-21 - upload the regression results summary as artifact (for use as a comment on PRs)
# 2023-07-31 - removed option to run from RMG-database with GitHub resuable workflows
# 2024-10-01 - deprecated Mambaforge with Miniforge3 for environment creation
name: Continuous Integration
on:
schedule:
# * is a special character in YAML so you have to quote this string
- cron: "0 8 * * *"
# runs on all branches on both RMG-Py and forks
push:
# runs on PRs against RMG-Py (and anywhere else, but we add this for RMG-Py)
pull_request:
# this prevents one PR from simultaneously running multiple runners, which will clog up the queue
# and prevent other PRs from running the CI
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
# if running on RMG-Py but requiring changes on an un-merged branch of RMG-database, replace
# main with the name of the branch
RMG_DATABASE_BRANCH: main
jobs:
build-and-test:
strategy:
fail-fast: false
matrix:
python-version: ["3.9"]
os: [macos-13, macos-latest, ubuntu-latest]
test_julia: [yes, no]
runs-on: ${{ matrix.os }}
name: ${{ matrix.os }} Build and Test Python ${{ matrix.python-version }} (Julia? ${{ matrix.test_julia }})
# skip scheduled runs from forks
if: ${{ !( github.repository != 'ReactionMechanismGenerator/RMG-Py' && github.event_name == 'schedule' ) }}
env:
# This is true only if this is a reference case for the regression testing:
REFERENCE_JOB: ${{ github.ref == 'refs/heads/main' && github.repository == 'ReactionMechanismGenerator/RMG-Py' }}
defaults:
run:
shell: bash -l {0}
steps:
- name: Checkout RMG-Py
uses: actions/checkout@v4
# Step to create a custom condarc.yml before setting up conda
- name: Create custom condarc.yml
run: |
RUNNER_CWD=$(pwd)
echo "channels:" > $RUNNER_CWD/condarc.yml
echo " - conda-forge" >> $RUNNER_CWD/condarc.yml
echo " - rmg" >> $RUNNER_CWD/condarc.yml
echo " - cantera" >> $RUNNER_CWD/condarc.yml
echo "show_channel_urls: true" >> $RUNNER_CWD/condarc.yml
# configures the mamba environment manager and builds the environment
- name: Setup Mambaforge Python ${{ matrix.python-version }}
uses: conda-incubator/setup-miniconda@v3
with:
environment-file: environment.yml
miniforge-variant: Miniforge3
miniforge-version: latest
python-version: ${{ matrix.python-version }}
condarc-file: condarc.yml
activate-environment: rmg_env
use-mamba: true
# list the environment for debugging purposes
- name: mamba info
run: |
mamba info
mamba list
# Clone RMG-database
- name: Clone RMG-database
run: |
cd ..
git clone -b $RMG_DATABASE_BRANCH https://github.com/ReactionMechanismGenerator/RMG-database.git
# modify env variables as directed in the RMG installation instructions
- name: Set Environment Variables
run: |
RUNNER_CWD=$(pwd)
echo "PYTHONPATH=$RUNNER_CWD/RMG-Py:$PYTHONPATH" >> $GITHUB_ENV
echo "$RUNNER_CWD/RMG-Py" >> $GITHUB_PATH
# RMG build step
- name: make RMG
run: |
make clean
make
# Setup Juliaup
- name: Set Julia paths
if: ${{ matrix.test_julia }} == "yes"
run: |
# echo "JULIAUP_DEPOT_PATH=$CONDA/envs/rmg_env/.julia" >> $GITHUB_ENV
# echo "JULIAUP_DEPOT_PATH=$CONDA/envs/rmg_env/.julia" >> $GITHUB_PATH
# echo "JULIA_DEPOT_PATH=$CONDA/envs/rmg_env/.julia" >> $GITHUB_ENV
# echo "JULIA_DEPOT_PATH=$CONDA/envs/rmg_env/.julia" >> $GITHUB_PATH
# echo "JULIA_CONDAPKG_EXE=$CONDA/condabin/mamba" >> $GITHUB_ENV
# echo "JULIA_CONDAPKG_EXE=$CONDA/condabin/mamba" >> $GITHUB_PATH
# echo "JULIA_CONDAPKG_EXE=$CONDA/condabin/mamba" >> $GITHUB_ENV
# echo "JULIA_CONDAPKG_EXE=$CONDA/condabin/mamba" >> $GITHUB_PATH
echo "JULIA_CONDAPKG_BACKEND=Current" >> $GITHUB_ENV
# echo "JULIA_CONDAPKG_BACKEND=Current" >> $GITHUB_PATH
- name: Setup Juliaup
if: ${{ matrix.test_julia }} == "yes"
uses: julia-actions/install-juliaup@v2
with:
channel: '1.9'
- name: Check Julia version
if: ${{ matrix.test_julia }} == "yes"
run: julia --version
# RMS installation and linking to Julia
- name: Install and link Julia dependencies
if: ${{ matrix.test_julia }} == "yes"
timeout-minutes: 120 # this usually takes 20-45 minutes (or hangs for 6+ hours).
# JULIA_CONDAPKG_EXE points to the existing conda/mamba to avoid JuliaCall from installing their own. See https://juliapy.github.io/PythonCall.jl/stable/pythoncall/#If-you-already-have-a-Conda-environment.
run: |
mamba install conda-forge::pyjuliacall
julia -e 'using Pkg; Pkg.add(Pkg.PackageSpec(name="ReactionMechanismSimulator", url="https://github.com/hwpang/ReactionMechanismSimulator.jl.git", rev="fix_installation")); using ReactionMechanismSimulator'
- name: Install Q2DTor
run: echo "" | make q2dtor
# non-regression testing
- name: Run Unit, Functional, and Database Tests
# aggregate into one command so we only have to eat the collection time once
run: make test-all
# Regression Testing - Test Execution
- name: Regression Tests - Execution
id: regression-execution
timeout-minutes: 60
run: |
for regr_test in aromatics liquid_oxidation nitrogen oxidation sulfur superminimal RMS_constantVIdealGasReactor_superminimal RMS_CSTR_liquid_oxidation RMS_liquidSurface_ch4o2cat fragment RMS_constantVIdealGasReactor_fragment minimal_surface;
do
if python rmg.py test/regression/"$regr_test"/input.py; then
echo "$regr_test" "Executed Successfully"
else
echo "$regr_test" "Failed to Execute" | tee -a $GITHUB_STEP_SUMMARY
export FAILED=Yes
fi
done
if [[ ${FAILED} ]]; then
echo "One or more regression tests could not be executed." | tee -a $GITHUB_STEP_SUMMARY
echo "Please download the failed results or check the above log to see why." | tee -a $GITHUB_STEP_SUMMARY
exit 1
fi
# Upload Regression Results as Failed if above step failed
- name: Upload Failed Results
if: ${{ failure() && steps.regression-execution.conclusion == 'failure' }}
uses: actions/upload-artifact@v4
with:
name: failed_regression_results
path: |
test/regression
# Upload Regression Results as Stable if Scheduled or Push to Main
- name: Upload Results as Reference
# upload the results for scheduled CI (on main) and pushes to main
if: ${{ env.REFERENCE_JOB == 'true' }}
uses: actions/upload-artifact@v4
with:
name: stable_regression_results
path: |
test/regression
# Upload Regression Results as Dynamic if Push to non-main Branch
- name: Upload Results as Dynamic
if: ${{ env.REFERENCE_JOB == 'false' }}
uses: actions/upload-artifact@v4
with:
name: dynamic_regression_results
path: |
test/regression
- name: mkdir stable_regression_results
if: ${{ env.REFERENCE_JOB == 'false' }}
run: mkdir stable_regression_results
# Retrieve Stable Results for reference
- name : Find ID of Reference Results
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# this will search for the last successful execution of CI on main
run: |
run_id=$(gh run list -R ReactionMechanismGenerator/RMG-Py --workflow="Continuous Integration" --branch main --limit 15 --json databaseId,conclusion --jq 'map(select(.conclusion == "success")) | .[0].databaseId')
echo "CI_RUN_ID=$run_id" >> $GITHUB_ENV
- name: Retrieve Stable Regression Results
if: ${{ env.REFERENCE_JOB == 'false' }}
uses: actions/download-artifact@v4
with:
# download stable regression results
run-id: ${{ env.CI_RUN_ID }}
repository: ReactionMechanismGenerator/RMG-Py
github-token: ${{ secrets.GITHUB_TOKEN }}
name: stable_regression_results
path: stable_regression_results
# Regression Testing - Actual Comparisons
- name: Regression Tests - Compare to Baseline
id: regression-comparison
if: ${{ env.REFERENCE_JOB == 'false' }}
env:
REFERENCE: stable_regression_results
run: |
exec 2> >(tee -a regression.stderr >&2) 1> >(tee -a regression.stdout)
mkdir -p "test/regression-diff"
for regr_test in aromatics liquid_oxidation nitrogen oxidation sulfur superminimal RMS_constantVIdealGasReactor_superminimal RMS_CSTR_liquid_oxidation fragment RMS_constantVIdealGasReactor_fragment minimal_surface;
do
echo ""
echo "### Regression test $regr_test:"
# Memory Usage and Execution Time
echo -n 'Reference: '
grep "Execution time" $REFERENCE/"$regr_test"/RMG.log | tail -1
echo -n 'Current: '
grep "Execution time" test/regression/"$regr_test"/RMG.log | tail -1
echo -n 'Reference: '
grep "Memory used:" $REFERENCE/"$regr_test"/RMG.log | tail -1
echo -n 'Current: '
grep "Memory used:" test/regression/"$regr_test"/RMG.log | tail -1
echo "<details>"
# Compare the edge and core
if python scripts/checkModels.py \
"$regr_test-core" \
$REFERENCE/"$regr_test"/chemkin/chem_annotated.inp \
$REFERENCE/"$regr_test"/chemkin/species_dictionary.txt \
test/regression/"$regr_test"/chemkin/chem_annotated.inp \
test/regression/"$regr_test"/chemkin/species_dictionary.txt
then
echo "<summary>$regr_test Passed Core Comparison ✅</summary>"
else
echo "<summary>$regr_test Failed Core Comparison ❌</summary>"
cp "$regr_test-core.log" test/regression-diff/
export FAILED=Yes
fi
echo "" # blank line so next block is interpreted as markdown
cat "$regr_test-core.log"
echo "</details>"
echo "<details>"
if python scripts/checkModels.py \
"$regr_test-edge" \
$REFERENCE/"$regr_test"/chemkin/chem_edge_annotated.inp \
$REFERENCE/"$regr_test"/chemkin/species_edge_dictionary.txt \
test/regression/"$regr_test"/chemkin/chem_edge_annotated.inp \
test/regression/"$regr_test"/chemkin/species_edge_dictionary.txt
then
echo "<summary>$regr_test Passed Edge Comparison ✅</summary>"
else
echo "<summary>$regr_test Failed Edge Comparison ❌</summary>"
cp "$regr_test-edge.log" test/regression-diff/
export FAILED=Yes
fi
echo "" # blank line so next block is interpreted as markdown
cat "$regr_test-edge.log"
echo "</details>"
# Check for Regression between Reference and Dynamic (skip superminimal)
if [ -f test/regression/"$regr_test"/regression_input.py ];
then
echo "<details>"
if python rmgpy/tools/regression.py \
test/regression/"$regr_test"/regression_input.py \
$REFERENCE/"$regr_test"/chemkin \
test/regression/"$regr_test"/chemkin
then
echo "<summary>$regr_test Passed Observable Testing ✅</summary>"
else
echo "<summary>$regr_test Failed Observable Testing ❌</summary>"
export FAILED=Yes
fi
echo "</details>"
fi
echo ""
done
if [[ ${FAILED} ]]; then
echo "⚠️ One or more regression tests failed." | tee -a $GITHUB_STEP_SUMMARY >&2
echo "Please download the failed results and run the tests locally or check the log to see why." | tee -a $GITHUB_STEP_SUMMARY >&2
fi
- name: Prepare Results for PR Comment
if: ${{ env.REFERENCE_JOB == 'false' }}
env:
PR_NUMBER: ${{ github.event.number || github.event.after || github.event_name }}
run: |
echo $PR_NUMBER > summary.txt
echo "## Regression Testing Results" >> summary.txt
cat regression.stderr >> summary.txt
echo "<details>" >> summary.txt
echo "<summary>Detailed regression test results.</summary>" >> summary.txt
cat regression.stdout >> summary.txt
echo "</details>" >> summary.txt
echo "" >> summary.txt
echo "_beep boop this comment was written by a bot_ :robot:" >> summary.txt
cat summary.txt > $GITHUB_STEP_SUMMARY
- name: Upload regression summary artifact
# the annotate workflow uses this artifact to add a comment to the PR
uses: actions/upload-artifact@v3
if : ${{ github.event_name == 'pull_request' }}
with:
name: regression_summary
path: summary.txt
- name: Upload Comparison Results
uses: actions/upload-artifact@v3
with:
name: regression_test_comparison_results
path: |
test/regression-diff
# Install and Call codecov only if the tests were successful (permitting failures in the regression comparison tests)
- name: Code coverage install and run
if: success() || ( failure() && steps.regression-execution.conclusion == 'success' )
run: |
mamba install -y -c conda-forge codecov
codecov
build-and-push-docker:
# after testing and on pushes to main, build and push docker image
# technically we could live without the 'needs' since _in theory_
# nothing will ever be merged into main that fails the tests, but
# who knows ¯\_(ツ)_/¯
#
# taken from https://github.com/docker/build-push-action
needs: build-and-test
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' && github.repository == 'ReactionMechanismGenerator/RMG-Py'
steps:
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and Push
uses: docker/build-push-action@v6
with:
push: true
tags: reactionmechanismgenerator/rmg:latest