This repository has been archived by the owner on Nov 2, 2020. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtrigger-travis-build.sh
executable file
·90 lines (78 loc) · 1.83 KB
/
trigger-travis-build.sh
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
#!/usr/bin/env bash
usage() {
echo "Usage: $(basename "$0") [MAX_TAGS]"
}
list_targets() {
local tmpdir
tmpdir="$(mktemp -d)"
git clone -q --depth 1 https://github.com/zabbix/zabbix-docker "$tmpdir"
find "$tmpdir" -maxdepth 2 -mindepth 2 -type d | grep -v .git | \
sed -e "s|^${tmpdir}/||" -e 's|/|-|' | sort | \
grep -v "agent2"
# shellcheck disable=2064
trap "rm -rf \"$tmpdir\"" EXIT
}
list_remote_tags() {
git ls-remote --tags "$1" | \
awk '{print $2}' | \
sed 's|refs/tags/||' | \
sort -r
}
travis_build() {
local target
local git_tags
local git_tag
local jobs_def=""
local tmp
local tags_limit="${1:-1}"
git_tags=$(list_remote_tags https://github.com/zabbix/zabbix-docker)
# Limit to latest X tags
git_tags=$(head -n "$tags_limit" <<< "$git_tags")
for target in $(list_targets)
do
for git_tag in $git_tags
do
tmp='"TARGET='"$target"' GIT_TAG='"$git_tag"'"'
if [[ -n "$jobs_def" ]]
then
jobs_def="$jobs_def, $tmp"
else
jobs_def="$tmp"
fi
done
done
local body
body='{
"request": {
"message": "'"$(git show -s --format=%s)"'",
"branch": "'"$(git rev-parse --abbrev-ref HEAD)"'",
"config": {
"env": {
"jobs": ['"$jobs_def"']
}
}
}}'
curl -s -X POST \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-H "Travis-API-Version: 3" \
-H "Authorization: token $TRAVIS_TOKEN" \
-d "$body" \
https://api.travis-ci.com/repo/pschmitt%2Fzabbix-docker-multiarch/requests
}
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]
then
if [[ -z "$TRAVIS_TOKEN" ]]
then
echo "TRAVIS_TOKEN is not set." >&2
echo "You can retrieve it with $ travis token --com" >&2
exit 2
fi
case "$1" in
help|h|-h|--help)
usage
exit 0
;;
esac
travis_build "$@"
fi