-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate-final-public-release.sh
executable file
·159 lines (132 loc) · 4.97 KB
/
create-final-public-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
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
149
150
151
152
153
154
155
156
157
158
159
#!/usr/bin/env bash
# set -o pipefail # exit if pipe command fails
[ -z "$DEBUG" ] || set -x
set -e
##
RELEASE="springernature-custom-alerts-dashboards"
DESCRIPTION="Bosh release add-on for prometheus-boshrelease to add custom resources: alerts, dashboards, etc"
GITHUB_REPO="SpringerPE/springernature-custom-alerts-dashboards-boshrelease"
###
BOSH_CLI=${BOSH_CLI:-bosh}
S3CMD=${S3CMD:-s3cmd}
JQ=jq
CURL="curl -s"
SHA1="sha1sum -b"
RE_VERSION_NUMBER='^[0-9]+([0-9\.]*[0-9]+)*$'
# Create a personal github token to use this script
if [ -z "$GITHUB_TOKEN" ]
then
echo "Github TOKEN not defined!"
echo "See https://help.github.com/articles/creating-an-access-token-for-command-line-use/"
exit 1
fi
# You need bosh installed and with you credentials
if ! [ -x "$(command -v $BOSH_CLI)" ]
then
echo "ERROR: $BOSH_CLI command not found! Please install it and make it available in the PATH"
exit 1
fi
# You need jq installed
if ! [ -x "$(command -v $JQ)" ]
then
echo "ERROR: $JQ command not found! Please install it and make it available in the PATH"
exit 1
fi
# You need sha1sum installed (brew md5sha1sum)
if ! [ -x "$(command -v $SHA1)" ]
then
echo "ERROR: $SHA1 command not found! Please install it and make it available in the PATH"
exit 1
fi
case $# in
0)
echo "*** Creating a new release. Automatically calculating next release version number"
;;
1)
if [ $1 == "-h" ] || [ $1 == "--help" ]
then
echo "Usage: $0 [version-number]"
echo " Creates a new boshrelease, commits the changes to this repository using tags and uploads "
echo " the release to Github releases. It also adds comments based on previous git commits and "
echo " calculates the sha1 checksum."
exit 0
else
version=$1
if ! [[ $version =~ $RE_VERSION_NUMBER ]]
then
echo "ERROR: Incorrect version number!"
exit 1
fi
echo "*** Creating a new release. Using release version number $version."
fi
;;
*)
echo "ERROR: incorrect argument. See '$0 --help'"
exit 1
;;
esac
# Get the last git commit made by this script
lastcommit=$(git log --format="%h" --grep="$RELEASE v*" | head -1)
echo "* Changes since last version with commit $lastcommit: "
git_changes=$(git log --pretty="%h %aI %s (%an)" $lastcommit..@ | sed 's/^/- /')
if [ -z "$git_changes" ]
then
echo "Error, no commits since last release with commit $lastcommit!. Please "
echo "commit your changes to create and publish a new release!"
exit 1
fi
echo "$git_changes"
# Uploading blobs
echo "* Uploading blobs to the blobstore ..."
$BOSH_CLI upload-blobs
# Creating the release
if [ -z "$version" ]
then
echo "* Creating final release ..."
$BOSH_CLI create-release --force --final --tarball="/tmp/$RELEASE-$$.tgz" --name "$RELEASE"
# Get the version of the release
version=$(ls releases/$RELEASE/$RELEASE-*.yml | sed 's/.*\/.*-\(.*\)\.yml$/\1/' | sort -t. -k 1,1nr -k 2,2nr | head -1)
else
echo "* Creating final release version $version ..."
$BOSH_CLI create-release --force --final --tarball="/tmp/$RELEASE-$$.tgz" --name "$RELEASE" --version "$version"
fi
# Create a new tag and update the changes
echo "* Commiting git changes ..."
git add .final_builds releases/$RELEASE/index.yml "releases/$RELEASE/$RELEASE-$version.yml" blobstore
git commit -m "$RELEASE v$version Boshrelease"
git push
git push --tags
# Create a release in Github
echo "* Creating a new release in Github ... "
sha1=$($SHA1 "/tmp/$RELEASE-$$.tgz" | cut -d' ' -f1)
description=$(cat <<EOF
# $RELEASE version $version
$DESCRIPTION
## Changes since last version
$git_changes
## Using in a bosh Deployment
releases:
- name: $RELEASE
url: https://github.com/${GITHUB_REPO}/releases/download/v${version}/${RELEASE}.tgz
version: $version
sha1: $sha1
or to always point to latest release:
releases:
- name: $RELEASE
url: https://github.com/${GITHUB_REPO}/releases/latest/download/${RELEASE}.tgz
version: latest
EOF
)
printf -v DATA '{"tag_name": "v%s","target_commitish": "master","name": "v%s","body": %s,"draft": false, "prerelease": false}' "$version" "$version" "$(echo "$description" | $JQ -R -s '@text')"
releaseid=$($CURL -H "Authorization: token $GITHUB_TOKEN" -H "Content-Type: application/json" -XPOST --data "$DATA" "https://api.github.com/repos/$GITHUB_REPO/releases" | $JQ '.id')
# Upload the release
echo "* Uploading tarball to Github releases section ... "
echo -n " URL: "
$CURL -H "Authorization: token $GITHUB_TOKEN" -H "Content-Type: application/octet-stream" --data-binary @"/tmp/$RELEASE-$$.tgz" "https://uploads.github.com/repos/$GITHUB_REPO/releases/$releaseid/assets?name=$RELEASE.tgz" | $JQ -r '.browser_download_url'
# Delete the release
rm -f "/tmp/$RELEASE-$$.tgz"
echo
echo "*** Description https://github.com/$GITHUB_REPO/releases/tag/v$version: "
echo
echo "$description"
exit 0