-
Notifications
You must be signed in to change notification settings - Fork 216
/
trigger.sh
113 lines (89 loc) · 2.89 KB
/
trigger.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/bin/bash
# Trigger builds on travis using GitHub username and password
# https://docs.travis-ci.com/api?http#creating-a-temporary-github-token
#
# For example, to build arduino:
# bash <(curl -s https://raw.githubusercontent.com/AppImage/AppImages/master/trigger.sh) arduino
[[ -z "$1" ]] && echo "Argument missing. Which AppImage do you want to build?" && exit 1
set +e
USERNAME=probonopd
ORGANIZATION=AppImage
PROJECT=pkg2appimage
USER_AGENT='Travis/1.8.0 (Compatible; curl '$(curl --version | head -n 1 | cut -d " " -f 1-4)')'
echo $@
MATRIX=""
for RECIPE in $@ ; do
MATRIX="\"RECIPE=$RECIPE\",$MATRIX"
done
MATRIX=$(echo -n $MATRIX | head -c -1 ) # Remove extra comma at the end
read -s -p "GitHub Password: " PASSWORD
if [ "$PASSWORD" == "" ] ; then
exit 1
else
echo ""
fi
#########################################################
echo "Delete the GitHub authorization at the end"
#########################################################
trap atexit EXIT
atexit()
{
set +e
RESL=$(curl -u $USERNAME:$PASSWORD -k -s -X DELETE \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
$GH_AUTH_URL)
echo $RESL
}
#########################################################
echo "Create a temporary GitHub authorization"
#########################################################
body='{
"scopes": [
"read:org", "user:email", "repo_deployment",
"repo:status", "write:repo_hook"
],
"note": "temporary token to auth against travis"
}'
RES1=$(curl -k -u $USERNAME:$PASSWORD -s -X POST \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d "$body" \
https://api.github.com/authorizations)
echo $RES1
GH_TOKEN=$(echo $RES1 | grep -Po '"token":.*?[^\\]",' | cut -d '"' -f 4 | head -n 1)
GH_AUTH_URL=$(echo $RES1 | grep -Po '"url":.*?[^\\]",' | cut -d '"' -f 4| head -n 1)
#########################################################
echo "Get a travis token using the GitHub token"
#########################################################
RES2=$(curl -A "$USER_AGENT" -k -s -X POST \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d '{"github_token":"'$GH_TOKEN'"}' \
https://api.travis-ci.org/auth/github)
echo $RES2
TRAVIS_TOKEN=$(echo $RES2 | cut -d '"' -f 4 | head -n 1)
echo $TRAVIS_TOKEN
[ $TRAVIS_TOKEN == "error" ] && exit 1
#########################################################
echo "Trigger a build"
#########################################################
body='{
"request": {
"message": "Build triggered by api request",
"branch":"master",
"config": {
"env": {
"matrix": ['$MATRIX']
}
}
}
}'
echo $body
curl -A "$USER_AGENT" -k -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.org/repo/$ORGANIZATION%2F$PROJECT/requests