-
Notifications
You must be signed in to change notification settings - Fork 7
/
git-release.sh
executable file
·70 lines (59 loc) · 2.37 KB
/
git-release.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
#!/bin/bash -e
# GITHUB_TOKEN = Token for updating your git repo
# RELEASE_FILE = File to release or
# RELEASE_FILES = list of files to release (strings seperated by space)
if [ -z "$GITHUB_TOKEN" ] || ([ -z "$RELEASE_FILE" ] && [ -z "$RELEASE_FILES" ]); then
echo Unable to release, missing environment variables
exit 2
fi
GITHUB_RELEASE=/tmp/linux-amd64-github-release
if [ ! -f "$GITHUB_RELEASE" ] ; then
echo Downloading github-release
wget -q -O - https://api.github.com/repos/github-release/github-release/releases/latest \
| egrep -o '/github-release/github-release/releases/download/v[0-9.]*/linux-amd64-github-release.bz2' \
| wget --base=http://github.com/ -i - -O /tmp/linux-amd64-github-release.bz2
bzip2 -dv /tmp/linux-amd64-github-release.bz2
chmod +x $GITHUB_RELEASE
fi
# https://github.com/screwdriver-cd/gitversion/releases
if [ "$SCREWDRIVER" == true ]; then
GIT_VERSION=/opt/sd/gitversion
else
GIT_VERSION=/tmp/gitversion
if [ ! -f "$GIT_VERSION" ] ; then
echo Downloading gitversion
wget -q -O - https://api.github.com/repos/screwdriver-cd/gitversion/releases/latest \
| egrep -o '/screwdriver-cd/gitversion/releases/download/v[0-9.]*/gitversion_linux_amd64' \
| wget --base=http://github.com/ -i - -O /tmp/gitversion
chmod +x $GIT_VERSION
fi
fi
GIT_ORG=`git remote -v | grep fetch | sed 's/ (fetch)//' | cut -d'/' -f4`
GIT_REPO=`git remote -v | grep fetch | sed 's/ (fetch)//' | cut -d'/' -f5`
if [ -f VERSION ] ; then
GIT_TAG=$(<VERSION)
else
GIT_TAG=`$GIT_VERSION --prefix v show`
fi
echo "Creating release $GIT_TAG for $GIT_ORG / $GIT_REPO"
$GITHUB_RELEASE --version
echo "Creating tag $GIT_TAG for $GIT_ORG / $GIT_REPO"
$GITHUB_RELEASE release --user $GIT_ORG --repo $GIT_REPO --tag $GIT_TAG --name $GIT_TAG
echo "Querying tag $GIT_TAG for $GIT_ORG / $GIT_REPO"
$GITHUB_RELEASE info --user $GIT_ORG --repo $GIT_REPO --tag $GIT_TAG
if [ ! -z "$RELEASE_FILES" ];then
files=($RELEASE_FILES)
echo "Uploading files..."
for i in "${files[@]}"
do
if [ -f $i ];then
echo "Uploading file: $i"
$GITHUB_RELEASE upload --user $GIT_ORG --repo $GIT_REPO --tag $GIT_TAG --name $i --file $i
else
echo "Unable to release, file does not exist"
fi
done
else
echo "Uploading file: $RELEASE_FILE"
$GITHUB_RELEASE upload --user $GIT_ORG --repo $GIT_REPO --tag $GIT_TAG --name $RELEASE_FILE --file $RELEASE_FILE
fi