-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
trigger-docker-vsi.sh
executable file
·98 lines (93 loc) · 2.12 KB
/
trigger-docker-vsi.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
91
92
93
94
95
96
97
98
#!/bin/bash
RED='\033[1;31m'
NC='\033[0m' # No Color
usage()
{
echo -e "Triggers the 'vsi' docker image build."
echo -e "Usage: $0 [options]"
echo -e " -h, --help\t\t\tDisplay help"
echo -e "\t--token [ACCESS_TOKEN]\tTravis access token"
echo -e "\t--tag [TAG]\t\tBuild tag"
echo ""
}
parse()
{
if [[ -z $1 ]]; then
usage
exit
fi
while [[ -n $1 ]]; do
PARAM=`echo $1 | awk -F= '{print $1}'`
VALUE=`echo $1 | awk -F= '{print $2}'`
if [[ -z $VALUE ]]; then
VALUE=$2
if [[ -z $VALUE ]] || [[ $VALUE == -* ]]; then
echo -e "${RED}ERROR: Missing value for parameter \"$PARAM\"${NC}"
exit 1
fi
shift
fi
case $PARAM in
-h | --help)
usage
exit
;;
--token)
TOKEN=$VALUE
;;
--tag)
TAG=$VALUE
;;
*)
echo -e "${RED}ERROR: Unknown parameter \"$PARAM\"${NC}"
exit 1
;;
esac
shift
done
}
parse $*
VSI_TAG="latest"
if [[ $TAG =~ ^v([0-9.]+-*[a-zA-Z0-9]*) ]]; then
VSI_TAG=${BASH_REMATCH[1]};
fi
OWNER="vscode-icons"
REPO="docker"
REPO_SLUG_URLENCODED="$OWNER%2F$REPO"
BODY='{
"request": {
"message": "Triggering build of vsi:'$VSI_TAG'",
"branch": "master",
"config": {
"env": {
"VSI_TAG": "'$VSI_TAG'"
}
}
}
}'
echo $(jq -r ".request.message" <<< $BODY)
RESPONSE=$(curl -s -X POST \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-H "Travis-API-Version: 3" \
-H "Authorization: token $TOKEN" \
-d "$BODY" \
https://api.travis-ci.com/repo/$REPO_SLUG_URLENCODED/requests)
echo ""
if jq -e . >/dev/null 2>&1 <<< $RESPONSE ; then
TYPE=$(jq -r '.["@type"]' <<< $RESPONSE)
case $TYPE in
error)
ERROR_TYPE=$(jq -r ".error_type" <<< $RESPONSE)
ERROR_MESSAGE=$(jq -r ".error_message" <<< $RESPONSE)
echo "$TYPE::$ERROR_TYPE::$ERROR_MESSAGE"
exit 1
;;
pending)
echo "Request accepted"
exit
;;
esac
fi
echo $RESPONSE
exit 1