Newer
Older
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
#!/usr/bin/env bash
set -euxo pipefail
if [[ $# != 1 ]];
then
cat <<EOF
usage: $0 <plugin> | all
$0 all run CI on all plugins
$0 <plugin_name> run CI only on this plugins
EOF
exit 2
fi
# all plugins to check
all_plugins=(Volatile)
if [[ "$1" = "all" ]];
then plugins=("${all_plugins[@]}")
else plugins=("$1")
fi
# prints "$2" if it is a branch name in remote $1, or master otherwise
get_matching_branch () {
if git ls-remote --quiet --exit-code "$1" "$2" >/dev/null 2>/dev/null;
then echo "$2"
else echo master
fi
}
curdir="$(dirname "$(readlink -f "$0")")"
git_current_branch="$(git branch --show-current)"
: "${git_current_branch:=${CI_COMMIT_BRANCH:-}}"
echo "currently on branch $git_current_branch"
[[ -n $git_current_branch ]]
plugin_repo=
cleanup () {
if [[ -n $plugin_repo ]];
then rm -rf "$plugin_repo"
fi
}
trap cleanup EXIT
do_plugin () {
OPTS="--arg frama-c-repo $curdir"
plugin=$1
cd "$(mktemp -d)"
# the hash of the derivation depends on the directory name
mkdir "$plugin"
cd "$plugin"
plugin_repo="$(readlink -f .)"
plugin_url="git@git.frama-c.com:frama-c/$plugin.git"
plugin_branch="$(get_matching_branch "$plugin_url" "$git_current_branch")"
echo "using branch $plugin_branch of $plugin_url"
git clone --depth=1 --branch="$plugin_branch" "$plugin_url" .
declare -A deps=( )
declare -A dirs=( )
if [[ -f "./nix/dependencies" ]]; then
while read -r var value; do
deps[$var]=$value
done < "./nix/dependencies"
for repo in ${!deps[@]}; do
# the hash of the derivation depends on the directory name
mkdir "../$repo"
directory="$(readlink -f ../$repo)"
dirs[$repo]=$directory
url=${deps[$repo]}
branch="$(get_matching_branch "$url" "$git_current_branch")"
echo "using branch $branch of $repo at $directory"
# clone
git clone --depth=1 --branch="$branch" "$url" "$directory"
OPTS="$OPTS --arg $repo $directory"
done
fi
# run the build
nix-build --no-out-link "./nix/pkgs.nix" $OPTS -A ocamlPackages."$plugin"
cd "$curdir"
for repo in ${!dirs[@]}; do
if [[ -n ${dirs[$repo]} ]];
then rm -rf "${dirs[$repo]}"
fi
done
rm -rf "$plugin_repo"
}
for plugin in "${plugins[@]}"; do
do_plugin $plugin
done