#!/usr/local/bin/zsh # Run CI jobs for repositories on git.fmsbw.de. # It can be scheduled as a cronjob. # This requires Podman on FreeBSD. #./ci.sh [ []] set -e cd /var/git projects=${1:-`echo *`} for project in $projects; do test -d $project || continue cd $project # We are scheduled by a cronjob, so don't repeat builds that # have already been tried (whether successful or not). # We use a tag to keep track of this. # You can remove this tag to force a rebuild: # git push origin --delete master-fmsbw-ci branch=`git rev-parse --abbrev-ref HEAD` test "`git rev-parse -q --verify $branch-fmsbw-ci || true`" != "`git rev-parse $branch`" || continue # The runner can leave the website and other build artifacts there: htdocs="/var/www/htdocs/projects/$project" ci_scripts=${2:-`git ls-tree --name-only HEAD .fmsbw/`} for ci_script in $ci_scripts; do # Extract OCI image name by stripping any leading number used for sorting # FIXME: This will cause problems for fully qualified image names. # In practice, you need to prepare images to preinstall stuff anyway, so # short names will be sufficient. # If it turns out to be too inflexible, we could also extract the image name # from an `IMAGE: ...` comment in the file itself. ci_image="`basename $ci_script | sed 's/^[0-9]*\-//'`" # Would it make any sense to create a ZFS volume? working_copy="`mktemp -d /var/ci/working-copy.XXXX`" git clone --recurse-submodules . $working_copy mkdir -p "$htdocs" ci_log="/var/ci/$project:$branch-`basename $ci_script`.log" echo "[$project:$branch] Running $ci_script..." # NOTE: The operating system should be guessed. set +e podman run -t --rm -v $working_copy:/opt/build -v "$htdocs":/opt/htdocs \ -w /opt/build -e FMSBW_CI=1 "$ci_image" "$ci_script" 2>&1 >"$ci_log" rc=$? set -e if [ "$rc" != 0 ]; then echo "[$project:$branch] CI FAILED. See $ci_log" rm -rf $working_copy # The next ci_scripts in the series could depend on build artifacts, # so abort here. break fi rm -rf $working_copy done # Update the CI tag. # But avoid creating it for repos without any CI configured. test -z "`git ls-tree --name-only HEAD .fmsbw/`" || git tag -f $branch-fmsbw-ci $branch # Regenerate index.htmls generate-index-html -R "$htdocs/downloads" || true # Make sure the build artifacts are readable by httpd. chown -R www:www "$htdocs" || true cd .. done