blob: 9af50a91535d0254ef5bd4bd9d456cd71c901281 (
plain)
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
|
#!/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 [<PROJECT> [<CI JOBS>]]
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
|