-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathreleases.sh
executable file
·94 lines (78 loc) · 2.5 KB
/
releases.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
#!/bin/bash
. $(dirname $0)/common/source.sh
# source common scripts
source_common
# update the repo
update_repo
GITHUB_REPO=releases
GITHUB_RELEASE=${script_dir}/tools/github-release
function create_release() {
$GITHUB_RELEASE info -s $GITHUB_TOKEN --user $GITHUB_USER --repo $GITHUB_REPO --tag $TAG
if [ "$?" != "0" ]; then
$GITHUB_RELEASE release -s $GITHUB_TOKEN --user $GITHUB_USER --repo $GITHUB_REPO --tag $TAG --name $RELEASE_NAME
echo "Release $RELEASE_NAME created"
else
echo "Release $RELEASE_NAME already exists"
fi
}
function upload_artifact() {
# first arg - artifact
local artifact_file=$1
local artifact_name=`basename $artifact_file`
local sync_count=1
$GITHUB_RELEASE upload -s $GITHUB_TOKEN --user $GITHUB_USER --repo $GITHUB_REPO --tag $TAG --name $artifact_name --file $artifact_file
sync_exit_error=$?
while [ $sync_exit_error -ne 0 ] && [ $sync_count -le 3 ]; do
echo "Failed to upload artifact ${artifact_name}. Retrying..."
$GITHUB_RELEASE upload -s $GITHUB_TOKEN --user $GITHUB_USER --repo $GITHUB_REPO --tag $TAG --name $artifact_name --file $artifact_file --replace
sync_exit_error=$?
sync_count=$((sync_count+1))
done
echo "Uploaded artifact ${artifact_name} to repo ${GITHUB_REPO} under release ${RELEASE_NAME}."
}
function print_help() {
echo "Usage: `basename $0` [OPTIONS] "
echo " -a | --artifact File/directory to upload"
echo " -t | --tag Git tag name"
echo " -n | --name Release name"
echo " -h | --help Print this message"
exit 0
}
if [ "x$1" == "x" ]; then
print_help
fi
while [ "$1" != "" ]; do
case $1 in
-a | --artifact) shift
ARTIFACT=$1
;;
-n | --name) shift
RELEASE_NAME=$1
;;
-t | --tag) shift
TAG=$1
;;
*) print_help
;;
esac
shift
done
if [ "x$TAG" == "x" ]; then
echo "No tag specified."
print_help
fi
if [ "x$RELEASE_NAME" == "x" ]; then
RELEASE_NAME=$TAG
fi
if [ "x$ARTIFACT" == "x" ]; then
echo "No artifact(s) specified"
print_help
fi
create_release
if [ -d "$ARTIFACT" ]; then
for file in `find $ARTIFACT -type f`; do
upload_artifact $file
done
elif [ -f "$ARTIFACT" ]; then
upload_artifact $ARTIFACT
fi