forked from libos-nuse/rumprun-packages
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path.travis-script.sh
148 lines (119 loc) · 3.83 KB
/
.travis-script.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/bin/bash
BINARY=(
"nginx nginx"
"python3 python"
"netperf netperf"
"sqlite-bench sqlite-bench"
"nodejs node"
"named named"
)
# upload built binaries to github releases
upload_a_file_to_github() {
FILE=$1
DEST_FILE=$2
TAG=dev
ACCEPT_HEADER="Accept: application/vnd.github.jean-grey-preview+json"
TOKEN_HEADER="Authorization: token $GITHUB_TOKEN"
ENDPOINT="https://api.github.com/repos/$TRAVIS_REPO_SLUG/releases"
echo "Creating new release as version ${TAG}..."
REPLY=$(curl -s -H "${ACCEPT_HEADER}" -H "${TOKEN_HEADER}" -d "{\"tag_name\": \"${TAG}\", \"name\": \"${TAG}\"}" "${ENDPOINT}")
# Check error
RELEASE_ID=$(echo "${REPLY}" | jq .id)
# retry for pre-existing tag case
if [ "${RELEASE_ID}" = "null" ] || [ "${RELEASE_ID}" = "" ] ; then
RELEASE_ID=$(curl -H "${TOKEN_HEADER}" ${ENDPOINT} | jq -r ".[] | select(.tag_name == \"$TAG\") | .id")
fi
if [ "${RELEASE_ID}" = "null" ]; then
echo "Failed to create release. Please check your configuration. Github replies:"
echo "${REPLY}"
exit 1
fi
echo "Github release created as ID: ${RELEASE_ID}"
RELEASE_URL="https://uploads.github.com/repos/$TRAVIS_REPO_SLUG/releases/${RELEASE_ID}/assets"
# Uploads artifacts
MIME=$(file -b --mime-type "${FILE}")
# delete previous asset
ASSET_ID=$(curl -s -H "${TOKEN_HEADER}" ${ENDPOINT} | jq -r ".[] | select(.tag_name == \"$TAG\") | .assets | .[] | select(.name == \"$DEST_FILE\") | .id")
echo "Deleting previous assets ${DEST_FILE} if any..."
curl \
-X DELETE \
-H "${TOKEN_HEADER}" \
-H "Accept: application/vnd.github.v3+json" \
"${ENDPOINT}/assets/"$ASSET_ID || true
echo "Uploading assets ${DEST_FILE} as ${MIME}..."
curl -v \
-H "${ACCEPT_HEADER}" \
-H "${TOKEN_HEADER}" \
-H "Content-Type: ${MIME}" \
--data-binary "@${FILE}" \
"${RELEASE_URL}?name=${DEST_FILE}"
echo "Finished."
}
upload_binary_to_github() {
local PUB_SUFFIX=$1
local bin=""
for i in "${BINARY[@]}"
do
pkg_bin=(${i[@]})
pkg=${pkg_bin[0]}
if [ "$pkg" == "${PACKAGE}" ] ; then
bin=${pkg_bin[1]}
break
fi
done
if [ -z "$bin" ] ; then
return
fi
# fixup arch name
if [ $TRAVIS_ARCH == "amd64" ] ; then
export ARCH=amd64
elif [ $TRAVIS_ARCH == "aarch64" ] ; then
export ARCH=${ARCH:-arm64}
fi
if [ -n "$PUB_SUFFIX" ] ; then
strip bin/$bin -o bin/$bin$PUB_SUFFIX
fi
echo "==== copying $bin ===="
upload_a_file_to_github "bin/$bin$PUB_SUFFIX" "$bin-$TRAVIS_OS_NAME-$ARCH$PUB_SUFFIX"
# additional installation
if [ "${PACKAGE}" == "nginx" ]; then
upload_a_file_to_github "images/data.iso" "data-$TRAVIS_OS_NAME-$ARCH.iso"
fi
if [ "${PACKAGE}" == "python3" ]; then
if [ "$TRAVIS_OS_NAME" == "linux" ] && [ "$TRAVIS_ARCH" == "amd64" ]; then
upload_a_file_to_github "images/python.img" "python-$TRAVIS_OS_NAME-$ARCH.img"
fi
upload_a_file_to_github "images/python.iso" "python-$TRAVIS_OS_NAME-$ARCH.iso"
fi
if [ "${PACKAGE}" == "netperf" ]; then
upload_a_file_to_github "build/src/netserver" "netserver-$TRAVIS_OS_NAME-$ARCH$PUB_SUFFIX"
fi
if [ "${PACKAGE}" == "named" ]; then
if [ "$TRAVIS_OS_NAME" == "linux" ] && [ "$TRAVIS_ARCH" == "amd64" ]; then
upload_a_file_to_github "images/named.img" "named-$TRAVIS_OS_NAME-$ARCH.img"
fi
fi
}
# Builds one specific package, specified by $PACKAGE
if [ -z "${PACKAGE}" ]; then
echo "PACKAGE is not set"
exit 1
fi
cd ${PACKAGE}
# Openjdk make should not be used with option -j
if [ "${PACKAGE}" == "openjdk8" ]; then
MKARG=""
# redis conflicts with ARCH env variable
elif [ "${PACKAGE}" == "redis" ]; then
MKARG="ARCH= -j2"
else
MKARG="-j2"
fi
make distclean || true
make clean || true
make $MKARG > $HOME/make.log
upload_binary_to_github
# create slim image
make clean || true
PATH=/opt/rump-tiny/bin:$PATH make $MKARG > $HOME/make-tiny.log
upload_binary_to_github "-slim"