-
Notifications
You must be signed in to change notification settings - Fork 139
217 lines (190 loc) · 7.55 KB
/
test-pr.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
name: build
on:
push:
branches: [ main, v5.2.x ]
pull_request:
branches: [ main, v5.2.x ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
inputs:
pr:
description: "PR to test"
required: true
jobs:
Model_Testing:
strategy:
fail-fast: false
matrix:
configuration: [nwm_ana, nwm_long_range, gridded, reach]
runs-on: ubuntu-latest
env:
MPI_HOME: /usr/share/miniconda
NETCDF: /usr/share/miniconda
NETCDF_INCLUDES: /usr/share/miniconda/include
NETCDF_LIBRARIES: /usr/share/miniconda/lib
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Checkout candidate (pull request / push)
if: ${{ github.event_name == 'pull_request' || github.event_name == 'push' }}
uses: actions/checkout@v4
with:
path: candidate
- name: Checkout candidate (manual)
if: ${{ github.event_name == 'workflow_dispatch' }}
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
run: gh repo clone ${{ github.repository }} candidate && cd candidate && gh pr checkout -R ${{ github.repository }} ${{ github.event.inputs.pr }}
- name: Checkout reference (pull request)
if: ${{ github.event_name == 'pull_request' }}
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.base.ref }}
path: reference
- name: Checkout reference (push)
if: ${{ github.event_name == 'push' }}
uses: actions/checkout@v4
with:
ref: ${{ github.event.before }}
path: reference
- name: Checkout reference (manual)
if: ${{ github.event_name == 'workflow_dispatch' }}
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
run: gh repo clone ${{ github.repository }} reference && cd reference && git checkout origin/$(gh pr view ${{ github.event.inputs.pr }} --json baseRefName --jq '.baseRefName')
- name: Install dependencies with apt-get
run: |
sudo apt-get update \
&& sudo apt-get install -yq --no-install-recommends \
wget \
curl \
bzip2 \
ca-certificates \
libhdf5-dev \
gfortran \
g++ \
m4 \
make \
libswitch-perl \
git \
bc \
openmpi-bin openmpi-common libopenmpi-dev \
libxml2-dev \
libnetcdf-dev \
libnetcdff-dev
- name: Install dependencies with pip
run: |
python3 -m pip install matplotlib numpy xarray dask netCDF4 pygithub
- name: Compile reference
run: |
cd $GITHUB_WORKSPACE/reference
cmake -B build
make -C build -j
- name: Compile candidate
run: |
cd $GITHUB_WORKSPACE/candidate
cmake -B build
make -C build -j
- name: Run reference model
run: |
cd $GITHUB_WORKSPACE/reference/build/Run
make run-croton-${{ matrix.configuration }}
- name: Run candidate model
run: |
cd $GITHUB_WORKSPACE/candidate/build/Run
make run-croton-${{ matrix.configuration }}
- name: Compare HYDRO_RST.* output with xrcmp
if: ${{ always() }}
run: |
cd $GITHUB_WORKSPACE/candidate/build/Run
for file in output_${{ matrix.configuration }}/HYDRO_RST.*; do\
python ${GITHUB_WORKSPACE}/candidate/tests/utils/xrcmp.py \
--candidate $file \
--reference $GITHUB_WORKSPACE/reference/build/Run/$file \
--log_file $file_diff.txt \
--n_cores 1; \
done
- name: Compare RESTART.* output with xrcmp
if: ${{ always() }}
run: |
cd $GITHUB_WORKSPACE/candidate/build/Run
for file in output_${{ matrix.configuration }}/RESTART.*; do\
python ${GITHUB_WORKSPACE}/candidate/tests/utils/xrcmp.py \
--candidate $file \
--reference $GITHUB_WORKSPACE/reference/build/Run/$file \
--log_file $file_diff.txt \
--n_cores 1; \
done
- name: Compare last *.CHANOBS_DOMAIN1 output with xrcmp
if: ${{ always() }}
run: |
cd $GITHUB_WORKSPACE/candidate/build/Run
file=$(ls -t output_${{ matrix.configuration }}/*.CHANOBS_DOMAIN1 | head -n 1)
python ${GITHUB_WORKSPACE}/candidate/tests/utils/xrcmp.py \
--candidate $file \
--reference $GITHUB_WORKSPACE/reference/build/Run/$file \
--log_file $file_diff.txt \
--n_cores 1; \
- name: Compare last *.CHRTOUT_DOMAIN1 output with xrcmp
if: ${{ always() }}
run: |
cd $GITHUB_WORKSPACE/candidate/build/Run
file=$(ls -t output_${{ matrix.configuration }}/*.CHRTOUT_DOMAIN1 | head -n 1)
python ${GITHUB_WORKSPACE}/candidate/tests/utils/xrcmp.py \
--candidate $file \
--reference $GITHUB_WORKSPACE/reference/build/Run/$file \
--log_file $file_diff.txt \
--n_cores 1; \
- name: Compare last *.LSMOUT_DOMAIN1 output with xrcmp
if: ${{ always() }}
run: |
cd $GITHUB_WORKSPACE/candidate/build/Run
file=$(ls -t output_${{ matrix.configuration }}/*.LSMOUT_DOMAIN1 | head -n 1)
python ${GITHUB_WORKSPACE}/candidate/tests/utils/xrcmp.py \
--candidate $file \
--reference $GITHUB_WORKSPACE/reference/build/Run/$file \
--log_file $file_diff.txt \
--n_cores 1; \
- name: Compare last *.RTOUT_DOMAIN1 output with xrcmp
if: ${{ always() }}
run: |
cd $GITHUB_WORKSPACE/candidate/build/Run
file=$(ls -t output_${{ matrix.configuration }}/*.RTOUT_DOMAIN1 | head -n 1)
python ${GITHUB_WORKSPACE}/candidate/tests/utils/xrcmp.py \
--candidate $file \
--reference $GITHUB_WORKSPACE/reference/build/Run/$file \
--log_file $file_diff.txt \
--n_cores 1; \
- name: Compare output with compare_output
if: ${{ always() }}
run: |
cd $GITHUB_WORKSPACE/candidate/build/Run
mkdir output_diff
python -c \
"import sys; \
sys.path.append('${GITHUB_WORKSPACE}/candidate/tests/utils'); \
import compare_output; \
from pathlib import Path; \
compare_output.plot_diffs('${GITHUB_WORKSPACE}/candidate/build/Run/output_diff', \
'${GITHUB_WORKSPACE}/candidate/build/Run/output_${{ matrix.configuration }}/', \
'${GITHUB_WORKSPACE}/reference/build/Run/output_${{ matrix.configuration }}/', \
'${{ matrix.configuration }}')"
- name: Copy test results from container
if: ${{ always() }}
run: |
mkdir -p $GITHUB_WORKSPACE/test_report
cp -r $GITHUB_WORKSPACE/candidate/build/Run/output_diff/diff_plots/* $GITHUB_WORKSPACE/test_report/
- name: Attach diff plots to PR
if: ${{ failure() }}
run: |
cd $GITHUB_WORKSPACE/candidate/tests/local/utils
bash attach_all_plots.bash $(jq --raw-output .pull_request.number "$GITHUB_EVENT_PATH") ${{ matrix.configuration }}
- name: Archive test results to GitHub
if: ${{ failure() }}
uses: actions/upload-artifact@v4
with:
name: test-reports
path: |
${{ github.workspace }}/test_report/*