forked from ufs-community/ufs-weather-model
-
Notifications
You must be signed in to change notification settings - Fork 2
230 lines (186 loc) · 6.53 KB
/
build_test.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
name: Pull Request Tests
on:
push:
branches: ['develop']
pull_request:
branches: ['develop']
env:
app: Accept:application/vnd.github.v3+json
jobs:
repocheck:
name: Check if repos are up to date
runs-on: ubuntu-20.04
outputs:
current: ${{ steps.check.outputs.current }}
steps:
- uses: actions/checkout@v2
- name: Wait for caching source
run: sleep 30
- uses: actions/cache@v2
with:
path: ~/id_file
key: helperid-${{ github.run_id }}
- name: Wait until repocheck in aux is complete
run: |
helper_id=$(cat ~/id_file)
cd ${{ github.workspace }}/tests/ci
jobs_url=$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/actions/runs/$helper_id/jobs
conclusion=$(echo $jobs_url | ./check_status.py completion "Repo check")
if [[ $conclusion == "failure" ]]; then
exit 1
fi
- uses: actions/cache@v2
with:
path: ~/repocheck_file
key: repocheck-${{ github.run_id }}
- name: Set repocheck currency flag
id: check
run: |
repocheck_result=$(cat ~/repocheck_file)
if [[ $repocheck_result == success ]]; then
echo "::set-output name=current::yes"
elif [[ $repocheck_result == failure ]]; then
echo "::set-output name=current::no"
fi
runcheck:
name: Check if run-ci is requested
runs-on: ubuntu-20.04
outputs:
cirun: ${{ steps.check.outputs.cirun }}
steps:
- name: Check
id: check
run: |
if [[ ${{github.event_name}} == pull_request ]]; then
sha=${{github.event.pull_request.head.sha}}
url=$(echo ${{github.event.pull_request.head.repo.git_commits_url}} \
| sed "s:{/sha}:/$sha:")
elif [[ ${{github.event_name}} == push ]]; then
sha=${{github.event.after}}
url=$(echo ${{github.event.repository.git_commits_url}} | sed "s:{/sha}:/$sha:")
fi
message="$(curl -sS -H "$app" $url | jq '.message')"
echo $message | grep run-ci >/dev/null 2>&1 && d=$? || d=$?
if [[ $d -eq 0 ]]; then
echo "::set-output name=cirun::yes"
elif [[ $d -eq 1 ]]; then
echo "::set-output name=cirun::no"
fi
printf "Commit message is %s\n" "$message"
setup:
name: Configure cases to run
needs: [repocheck,runcheck]
runs-on: ubuntu-20.04
if: needs.repocheck.outputs.current == 'yes' && needs.runcheck.outputs.cirun == 'yes'
outputs:
bld: ${{ steps.parse.outputs.bld }}
test: ${{ steps.parse.outputs.test }}
img: ${{ steps.parse.outputs.img }}
steps:
- uses: actions/checkout@v2
- name: Collect cases to run
id: parse
run: |
cd ${{ github.workspace }}/tests/ci
IFS='|'; parsed_output=( $(./setup.py cases) )
bld_=${parsed_output[0]}
test_=${parsed_output[1]}
img_=ci-test-weather
echo "::set-output name=bld::$bld_"
echo "::set-output name=test::$test_"
echo "::set-output name=img::$img_"
echo "build set : $bld_"
echo "test set : $test_"
echo "image name: $img_"
echo "repocheck: ${{needs.repocheck.outputs.current}}"
echo "runcheck: ${{needs.runcheck.outputs.cirun}}"
build:
name: Build ${{ matrix.bld_set }}
needs: setup
runs-on: ubuntu-20.04
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.setup.outputs.bld) }}
steps:
- uses: actions/checkout@v2
with:
submodules: recursive
- name: Build
run: |
printf '{\n "experimental": true\n}' | sudo tee /etc/docker/daemon.json >/dev/null
sudo systemctl restart docker
sleep 10
cd tests/ci && ./ci.sh -n ${{ matrix.name }} -b ${{ matrix.case }}
- name: Free up disk space
run: |
sudo docker rmi $(sudo docker image ls | grep -E -m1 '<none>' | awk '{ print $3 }')
sudo docker rmi $(sudo docker image ls | awk '/ubuntu-hpc/ { print $3 }')
- name: Prepare artifacts
run: |
cd tests/ci
sudo docker save ${{ needs.setup.outputs.img }} \
| gzip >${{ needs.setup.outputs.img }}.tar.gz
tar cvjf artifact.tar.bz2 ${{ needs.setup.outputs.img }}.tar.gz ci.sh ci.test
- uses: actions/upload-artifact@v2
with:
name: ${{ matrix.bld_set }}.artifact.tar.bz2
path: tests/ci/artifact.tar.bz2
wait:
name: Wait for ec2 instances to start
needs: build
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v2
with:
path: ~/id_file
key: helperid-${{ github.run_id }}
- name: Check if ec2 instances started
run: |
cd ${{ github.workspace }}/tests/ci
helper_id=$(cat ~/id_file)
url=$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/actions/runs/$helper_id/jobs
ec2_started=$(echo -n $url | ./check_status.py completion "Start runners")
if [ $ec2_started != 'success' ]; then
echo "ec2 instances did not start"
exit 1
fi
utest:
name: Test ${{ matrix.test_set }}
needs: [setup,build,wait]
runs-on: self-hosted
#runs-on: ubuntu-20.04
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.setup.outputs.test) }}
steps:
- name: Clean up in case of left-over files
run: |
rm -f artifact.tar.bz2 ${{ needs.setup.outputs.img }}.tar.gz
docker ps -a --filter "name=my-container" | grep my-container >/dev/null 2>&1 \
&& docker rm my-container >/dev/null 2>&1 && d=$? || d=$?
docker image ls | grep ${{ needs.setup.outputs.img }} >/dev/null 2>&1 \
&& docker rmi ${{ needs.setup.outputs.img }} >/dev/null 2>&1 && d=$? || d=$?
- uses: actions/download-artifact@v2
with:
name: ${{ matrix.artifact }}.artifact.tar.bz2
- name: Prepare artifacts
run: |
tar xvjf artifact.tar.bz2 && rm -f artifact.tar.bz2
docker load --input ${{ needs.setup.outputs.img }}.tar.gz \
&& rm -f ${{ needs.setup.outputs.img }}.tar.gz
- name: Run utest
run: ./ci.sh -n ${{ matrix.name }} -r ${{ matrix.case }}
- uses: actions/upload-artifact@v2
if: ${{ always() }}
with:
name: memory_stat_${{ matrix.test_set }}
path: memory_stat
- name: Clean up
if: ${{ always() }}
run: |
rm -f ci.sh ci.test
docker stop my-container && docker rm my-container \
&& docker rmi ${{ needs.setup.outputs.img }}:latest
docker volume rm DataVolume
rm -f memory_stat