-
Notifications
You must be signed in to change notification settings - Fork 3
/
build
executable file
·80 lines (69 loc) · 1.81 KB
/
build
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
#!/usr/bin/env bash
build() {
declare build_files="${*:-versions/**/options}"
[[ "$BUILDER_IMAGE" ]] || {
BUILDER_IMAGE="phan-builder-php8"
docker build -t "$BUILDER_IMAGE" builder
}
for file in $build_files; do
(
source "$file"
local version_dir
version_dir="$(dirname "$file")"
: "${TAGS:?}" "${BUILD_OPTIONS:?}" "${RELEASE:?}"
docker run -e "TRACE=$TRACE" --rm "$BUILDER_IMAGE" "${BUILD_OPTIONS[@]}" \
> "$version_dir/rootfs.tar.gz"
for tag in "${TAGS[@]}"; do
docker build -t "$tag" "$version_dir"
done
)
done
}
push() {
declare build_files="${*:-versions/**/options}"
for file in $build_files; do
(
source "$file"
for tag in "${TAGS[@]}"; do
if docker history "$tag" &> /dev/null; then
docker push "$tag"
fi
done
exit 0
)
done
}
run_tests() {
declare build_files="${*:-versions/**/options}"
declare -a test_files
for file in $build_files; do
source "$file"
local tag
tag="${TAGS[0]}" tag="${tag//:/-}" tag="${tag//\//_}"
test_files+=("test/test_${tag}.bats")
done
bats "${test_files[@]}"
}
new_version() {
declare version=$1
declare ast=${2:-1.0.10}
declare template_files="${4:-templates/}"
mkdir -p "versions/${version}"
for file in $template_files/versions/*; do
(
sed "s:{{.VERSION}}:${version}:g;s:{{.AST}}:${ast}:g"<"$file">"versions/${version}/$(basename "$file")"
)
done
sed "s:{{.VERSION}}:${version}:g"<"templates/test/test_phanphp_phan.bats">"test/test_phanphp_phan-${version}.bats"
}
main() {
set -eo pipefail; [[ "$TRACE" ]] && set -x
declare cmd="$1"
case "$cmd" in
test) shift; run_tests "$@";;
push) shift; push "$@";;
version) shift; new_version "$@";;
*) build "$@";;
esac
}
main "$@"