-
Notifications
You must be signed in to change notification settings - Fork 0
/
check.sh
executable file
·205 lines (148 loc) · 5.97 KB
/
check.sh
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
#!/bin/bash
#: relevant files
ufs_hashfile=$PWD/"hashfiles/hashfile_ufs" #: on Github cache
fms_hashfile=$PWD/"hashfiles/hashfile_fms" #: on Github cache
nceplib_hashfile=$PWD/"LIB_HASHFILE" #: in branch build_libs
logfile=$PWD/LOG
#: repositories
ufs_upstream='https://github.com/ufs-community/ufs-weather-model.git'
fms_upstream='https://github.com/NOAA-GFDL/FMS.git'
#: branches
ufs_branch="develop" ; ufs_hashtag="refs/heads/$ufs_branch"
fms_branch="master" ; fms_hashtag='HEAD'
#: nceplibs hash
curr_ncep=$( grep -m 1 "NCEPLIBS" $nceplib_hashfile | awk '{print $3}' )
#: default build to be true ; force build set to false
ufs_build='true' ; ufs_override='false'
fms_build='true' ; fms_override='false'
#: restart hashfiles
ufs_cleanhashfile='false'
fms_cleanhashfile='false'
#: number of hashes to check
fms_nhash=$3
#: remove existing hashfiles if cleanhasfile set to true
[ $ufs_cleanhashfile == 'true' ] && rm $ufs_hashfile
[ $fms_cleanhashfile == 'true' ] && rm $fms_hashfile
#: make hashfiles if they don't exist
[ ! -f $ufs_hashfile ] && touch -a $ufs_hashfile
[ ! -f $fms_hashfile ] && touch -a $fms_hashfile
#: need to push image to Docker Hub
docker_username=$1
docker_password=$2
#: ncep image has been pulled or not
ncep_dockerpulled='false'
#: get curr hashes
curr_ufs=$( git ls-remote $ufs_upstream | grep "$ufs_hashtag" | awk '{print $1}' )
curr_fms=$( git ls-remote $fms_upstream | grep "$fms_hashtag" | awk '{print $1}' )
#: echo to log
echo `date` > $logfile
echo "UFS REPOSITORY $ufs_upstream" >> $logfile
echo "FMS REPOSITORY $fms_upstream" >> $logfile
echo '' >> $logfile
echo "UFS BRANCH $ufs_branch" >> $logfile
echo "FMS BRANCH $fms_branch" >> $logfile
echo '' >> $logfile
echo "UFS NEW HASH $curr_ufs" >> $logfile
echo "FMS NEW HASH $curr_fms" >> $logfile
echo '' >> $logfile
#: build ufs if log cannot be found
if [ $( grep -c "PASSED $curr_ufs" $ufs_hashfile ) -ne 0 ] ; then
ufs_build='false'
echo "UFS $curr_ufs passed already"
echo "UFS $curr_ufs passed already" >> $logfile
fi
#: build fms if log cannot be found
if [ $( grep -c "PASSED $curr_fms" $fms_hashfile ) -ne 0 ] ; then
fms_build='false'
echo "FMS $curr_fms passed already"
echo "FMS $curr_fms passed already" >> $logfile
fi
#: override
[ $ufs_override == 'true' ] && ufs_build='true'
[ $fms_override == 'true' ] && fms_build='true'
#: compile UFS if UFS has been updated
if [ $ufs_build == 'true' ] ; then
echo "**************************"
echo "COMPILING UFS $curr_ufs"
echo "**************************"
if [ $ncep_dockerpulled == 'false' ] ; then
docker pull mklee03/nceplibs:$curr_ncep
ncep_dockerpulled='true'
fi
git clone --recursive --branch $ufs_branch $ufs_upstream
cd ufs-weather-model && git checkout $curr_ufs
sed -i "s/CHANGEME/$curr_ncep/" ../UFS_Dockerfile
docker build -f ../UFS_Dockerfile -t ufs:$curr_ufs .
if [ $? -ne 0 ] ; then
echo -e "FAILED $curr_ufs `date`\n $(cat $ufs_hashfile)" > $ufs_hashfile
echo "***********************************"
echo "UFS FAILED UFS FAILED UFS FAILED"
echo "***********************************"
cat $logfile
echo "(FAILED) COMMIT MESSAGE"
git show -s $curr_ufs
exit $?
else
echo -e "PASSED $curr_ufs `date`\n $(cat $ufs_hashfile)" > $ufs_hashfile
echo "(PASSED) UFS COMMIT MESSAGE" >> $logfile
git show -s $curr_ufs >> $logfile
echo "***********************" >> $logfile
fi
fms_build = 'true'
fi
if [ $fms_build == 'true' ] ; then
echo "**************************"
echo "COMPILING FMS"
echo "**************************"
#: get UFS if it hasn't been cloned already
if [ $ufs_build == 'false' ] ; then
git clone --recursive --branch $ufs_branch $ufs_upstream
cd ufs-weather-model && git checkout $curr_ufs
sed -i "s/CHANGEME/$curr_ncep/" ../UFS_Dockerfile
fi
#: pull nceplib image if it hasn't been pulled already
if [ $ncep_dockerpulled == 'false' ] ; then
docker pull mklee03/nceplibs:$curr_ncep
ncep_dockerpulled='true'
fi
#: get FMS latest commits
cd FMS && git checkout $fms_branch
git log --max-count=$fms_nhash --pretty=oneline > ../FMS_TMP
cd ..
for (( ihash=1 ; ihash<=$fms_nhash ; ihash++ )) ; do
curr_fms=$( sed -n "${ihash}p" FMS_TMP | awk '{print $1}' )
echo "*********************************"
echo "$ihash $curr_fms"
echo "*********************************"
cd FMS && git checkout $curr_fms && cd ..
ncount=$( grep -c "PASSED $curr_fms" $fms_hashfile )
[ $fms_build == 'true' ] && ncount=0
if [ $ncount -eq 0 ] ; then
docker build -f ../UFS_Dockerfile -t fms:$curr_fms .
if [ $? -ne 0 ] ; then
echo -e "FAILED $curr_fms `date`\n $(cat $fms_hashfile)" > $fms_hashfile
echo "***********************************"
echo "FMS FAILED FMS FAILED FMS FAILED"
echo "***********************************"
cat $logfile
echo "(FAILED) COMMIT MESSAGE"
git show -s $curr_fms
exit $?
else
echo -e "PASSED $curr_fms `date`\n $(cat $fms_hashfile)" > $fms_hashfile
echo "(PASSED) FMS COMMIT MESSAGE" >> $logfile
cd FMS
git show -s $curr_fms >> $logfile
echo "***********************" >> $logfile
cd ../
fi
fi
done
fi
cd ..
echo -e "**********************\n\n" >> $logfile
echo "UFS HASHFILE" >> $logfile
cat $ufs_hashfile >> $logfile
echo -e "**********************\n\n" >> $logfile
echo "FMS HASHFILE" >> $logfile
cat $fms_hashfile >> $logfile