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
|
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
|
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
|
fossil sync -R "${repository}" >/dev/null 2>/dev/null || :
# 4. Get a list of branches
branches=( $(fossil branch -R "${repository}" list) )
# 5. Get Fossil CI configuration from the trunk branch
## 5.a. Set default config
### 5.a.i. Set default variables
excludedBranches=()
includedBranches=('')
buildCommands=('./autogen.sh || :' ./configure make)
initCommands=()
postCommands=()
branchPostCommands=()
testCommands=()
builderID=''
projectName="$(fossil info -R "${repository}" | awk '/^project-name:/{ sub(/^project-name: */, ""); gsub(/ /, ""); print; }')"
tagSuffix=''
tagPrefix=''
tagOmitRedundant='0'
tagOmitPass='0'
# tagOmit='all|pass|redundant|none'
tagOmit='none'
# buildResultsUpload='fail|all|none'
buildResultsUpload='fail'
# testResultsUpload='fail|all|none'
testResultsUpload='fail'
### 5.a.ii. Default functions
function uploadBuildResults() {
### XXX:TODO
:
}
function uploadTestResults() {
### XXX:TODO
:
}
function uploadBuildArtifacts() {
### XXX:TODO
:
}
function fossilSetWikiPage() {
### XXX:TODO
:
}
function fossilUploadUV() {
### XXX:TODO
:
}
## 5.b. Read config
config="$(fossil cat -R "${repository}" -r trunk "${fossilCIDir}/config" 2>/dev/null)" || :
## 5.c Load config
if [ -f ~/.fossil-ci/config ]; then
. ~/.fossil-ci/config
fi
eval "${config}"
if [ -f ~/.fossil-ci/"${projectName}"/config ]; then
. ~/.fossil-ci/"${projectName}"/config
fi
## 5.d. Post-process config
### 5.d.i. Add builderID as a tag suffix if none was given
if [ -z "${tagSuffix}" ]; then
if [ -n "${builderID}" ]; then
tagSuffix="-${builderID}"
fi
fi
# 6. Perform any configured initialization
for cmd in "${initCommands[@]}"; do
eval "${cmd}" >/dev/null 2>/dev/null || :
done
# 7. For each branch, attempt to build
for branch in "${branches[@]}"; do
|
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
|
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
|
+
-
-
+
+
+
+
+
-
+
+
-
-
+
+
+
+
+
-
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
|
for cmd in "${buildCommands[@]}"; do
( eval "set -x; ${cmd}" ) || exit 1
done
) > "${builddir}/build.log" 2>&1 || build_pass='0'
### 7.g. Test the branch
tests_pass='-1'
if [ "${build_pass}" = '1' ]; then
tests_pass='1'
(
cd "${branchdir}" || exit 1
for cmd in "${testCommands[@]}"; do
( eval "set -x; ${cmd}" ) || exit 1
done
) > "${builddir}/test.log" 2>&1 || tests_pass='0'
fi
### 7.h. Tag the branch with
tagsToAdd=()
if [ "${build_pass}" = '1' ]; then
if [ "${tagOmitRedundant}" != '1' -a "${tagOmitPass}" != '1' ]; then
tagsToAdd=("${tagsToAdd[@]}" build-pass)
case "${tagOmit}" in
all|pass|redundant)
;;
*)
tagsToAdd=("${tagsToAdd[@]}" build-pass)
fi
;;
esac
if [ "${tests_pass}" = '1' ]; then
if [ "${tagOmitPass}" != '1' ]; then
tagsToAdd=("${tagsToAdd[@]}" tests-pass)
case "${tagOmit}" in
all|pass)
;;
*)
tagsToAdd=("${tagsToAdd[@]}" tests-pass)
fi
;;
esac
else
tagsToAdd=("${tagsToAdd[@]}" tests-fail)
fi
else
tagsToAdd=("${tagsToAdd[@]}" build-fail)
fi
tagsToAddOpts=()
for tag in "${tagsToAdd[@]}"; do
tagsToAddOpts=("${tagsToAddOpts[@]}" --tag "${tagPrefix}${tag}${tagSuffix}")
done
fossil amend -R "${repository}" "${branch}" "${tagsToAddOpts[@]}" > "${builddir}/update.log" 2>&1
### 7.i. Upload the logs somewhere if requested
uploadBuildResults='0'
case "${buildResultsUpload}-${build_pass}" in
all-0|all-1|fail-0|pass-1)
uploadBuildResults='1'
;;
esac
#### XXX:TODO
uploadTestResults='0'
case "${buildResultsUpload}-${tests_pass}" in
all-0|all-1|fail-0|pass-1)
uploadTestResults='1'
;;
esac
if [ "${uploadBuildResults}" ]; then
uploadBuildResults "${branch}" "${checkout}" "${builddir}/build.log" || :
fi
if [ "${uploadBuildResults}" ]; then
uploadTestResults "${branch}" "${checkout}" "${builddir}/test.log" || :
fi
### 7.j. Upload build artifacts somewhere if requested
#### XXX:TODO
uploadBuildArtifacts "${branch}" "${checkout}" "${branchdir}" || :
### 7.k. Get a list of tags
tags=( $(fossil tag -R "${repository}" list "${branch}") )
# 8. Perform post-build work (e.g., for release engineering)
(
cd "${branchdir}" || exit 1
|