Index: bin/autobuild ================================================================== --- bin/autobuild +++ bin/autobuild @@ -11,10 +11,14 @@ if [ -z "${fossilCIDir}" ]; then fossilCIDir='.fossil-ci' fi +# 0. Resolve paths +repository="$(cd "$(dirname "${repository}")" && echo "$(pwd)/$(basename "${repository}")")" || exit 1 +workdir="$(mkdir -p "${workdir}" && cd "${workdir}" && pwd)" || exit 1 + # 1. Register cleanup tmpdir='' function cleanup() { if [ -n "${tmpdir}" ]; then rm -rf "${tmpdir}" @@ -34,24 +38,28 @@ ## 2.d. Sane umask umask 022 # 3. Update the Fossil repository -fossil pull -R "${repository}" || : +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 excludedBranches='' buildCommands=('./autogen.sh || :' ./configure make) +testCommands=() +releaseCommands=() builderID='' projectName="$(fossil info -R "${repository}" | awk '/^project-name:/{ sub(/^project-name: */, ""); gsub(/ /, ""); print; }')" +tagSuffix='' +tagPrefix='' ## 5.b. Read config -config="$(fossil cat -R "${repository}" -r trunk "${fossilCIDir}/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 @@ -59,10 +67,17 @@ eval "${config}" if [ -f ~/.fossil-ci/"${projectName}"/config ]; then . ~/.fossil-ci/"${projectName}"/config fi + +## 5.d. Post-process config +if [ -z "${tagSuffix}" ]; then + if [ -n "${builderID}" ]; then + tagSuffix="-${builderID}" + fi +fi # 6. For each branch, attempt to build for branch in "${branches[@]}"; do ## 6.a. Ignore excluded branches case "${branch}" in @@ -102,28 +117,51 @@ build_pass='1' ( cd "${branchdir}" || exit 1 for cmd in "${buildCommands[@]}"; do - eval "set -x; ${cmd}" || exit 1 + ( eval "set -x; ${cmd}" ) || exit 1 done ) > "${builddir}/build.log" 2>&1 || build_pass='0' ### 6.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 + ( eval "set -x; ${cmd}" ) || exit 1 done ) > "${builddir}/test.log" 2>&1 || tests_pass='0' fi - ### 6.h. Tag the branch + ### 6.h. Tag the branch with + tagsToAdd=() + if [ "${build_pass}" = '1' ]; then + tagsToAdd=("${tagsToAdd[@]}" build-pass) + + if [ "${tests_pass}" = '1' ]; then + tagsToAdd=("${tagsToAdd[@]}" tests-pass) + 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 + ### 6.i. Upload the logs somewhere if requested + #### XXX:TODO + ### 6.j. Upload build artifacts somewhere if requested + #### XXX:TODO done # 7. Clean up any branches that no longer exist +## XXX:TODO