Skip to content

Commit 8009b16

Browse files
author
Luke Bakken
committed
add initial generic publish script
add code to upload release assets if present
1 parent 7b4b423 commit 8009b16

File tree

3 files changed

+82
-16
lines changed

3 files changed

+82
-16
lines changed

Makefile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.PHONY: release
2+
3+
release:
4+
ifeq ($(VERSION),)
5+
$(error VERSION must be set to deploy this code)
6+
endif
7+
ifeq ($(RELEASE_GPG_KEYNAME),)
8+
$(error RELEASE_GPG_KEYNAME must be set to deploy this code)
9+
endif
10+
./build/publish $(VERSION) validate
11+
git tag --sign -a "$(VERSION)" -m "riak-client-tools $(VERSION)" --local-user "$(RELEASE_GPG_KEYNAME)"
12+
git push --tags
13+
./build/publish $(VERSION) 'Riak Client Tools' 'riak-client-tools' 'master'

RELNOTES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
Release Notes
22
=============
33

4+
* [1.1.0](https://github.com/basho/riak-client-tools/issues?q=milestone%3Ariak-client-tools-1.1.0)
5+
* [1.0.3](https://github.com/basho/riak-client-tools/issues?q=milestone%3Ariak-client-tools-1.0.3)
6+
* [1.0.2](https://github.com/basho/riak-client-tools/issues?q=milestone%3Ariak-client-tools-1.0.2)
47
* [1.0.1](https://github.com/basho/riak-client-tools/issues?q=milestone%3Ariak-client-tools-1.0.1)
58
* [1.0.0](https://github.com/basho/riak-client-tools/issues?q=milestone%3Ariak-client-tools-1.0.0)

build/publish

Lines changed: 66 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ function onexit
6565
fi
6666
}
6767

68-
function gh_publish
69-
{
68+
function gh_publish {
7069
if [[ -z $version_string ]]
7170
then
7271
errexit 'gh_publish: version_string required'
@@ -75,8 +74,8 @@ function gh_publish
7574
# NB: we use a X.Y.Z tag
7675
local -r release_json="{
7776
\"tag_name\" : \"$version_string\",
78-
\"name\" : \"Riak Client Tools $version_string\",
79-
\"body\" : \"riak-client-tools $version_string\nhttps://github.com/basho/riak-client-tools/blob/master/RELNOTES.md\",
77+
\"name\" : \"$client_name $version_string\",
78+
\"body\" : \"$client_slug $version_string\nhttps://github.com/basho/$client_slug/blob/$client_default_branch/RELNOTES.md\",
8079
\"draft\" : false,
8180
\"prerelease\" : $is_prerelease
8281
}"
@@ -89,7 +88,7 @@ function gh_publish
8988

9089
curl -4so $curl_content_file -w '%{http_code}' -XPOST \
9190
-H "Authorization: token $(< $github_api_key_file)" -H 'Content-type: application/json' \
92-
'https://api.github.com/repos/basho/riak-client-tools/releases' -d "$release_json" 1> "$curl_stdout_file" 2> "$curl_stderr_file"
91+
"https://api.github.com/repos/basho/$client_slug/releases" -d "$release_json" 1> "$curl_stdout_file" 2> "$curl_stderr_file"
9392
if [[ $? != 0 ]]
9493
then
9594
errexit "curl error exited with code: '$?' see '$curl_stderr_file'"
@@ -101,7 +100,7 @@ function gh_publish
101100
pwarn "Release in GitHub already exists! (http code: '$curl_rslt')"
102101
curl -4so $curl_content_file -w '%{http_code}' -XGET \
103102
-H "Authorization: token $(< $github_api_key_file)" -H 'Content-type: application/json' \
104-
"https://api.github.com/repos/basho/riak-client-tools/releases/tags/$version_string" 1> "$curl_stdout_file" 2> "$curl_stderr_file"
103+
"https://api.github.com/repos/basho/$client_slug/releases/tags/$version_string" 1> "$curl_stdout_file" 2> "$curl_stderr_file"
105104
if [[ $? != 0 ]]
106105
then
107106
errexit "curl error exited with code: '$?' see '$curl_stderr_file'"
@@ -110,6 +109,47 @@ function gh_publish
110109
then
111110
errexit "Creating release in GitHub failed with http code '$curl_rslt'"
112111
fi
112+
113+
if [[ -z $client_package_file ]]
114+
then
115+
pinfo 'No release assets to upload, exiting.'
116+
exit 0
117+
fi
118+
119+
if [[ -s $client_package_file ]]
120+
then
121+
pinfo "Uploading release assets file: $client_package_file"
122+
else
123+
exit 0
124+
fi
125+
126+
if [[ ! -s $curl_content_file ]]
127+
then
128+
errexit 'no release info to parse for asset uploads'
129+
fi
130+
131+
# "upload_url": "https://uploads.github.com/repos/basho/$client_slug/releases/1115734/assets{?name,label}"
132+
# https://uploads.github.com/repos/basho/$client_slug/releases/1115734/assets{?name,label}
133+
local -r upload_url_with_name=$(perl -ne 'print qq($1\n) and exit if /"upload_url"[ :]+"(https:\/\/[^"]+)"/' "$curl_content_file")
134+
local -r upload_url="${upload_url_with_name/\{?name,label\}/?name=$client_package_name}"
135+
136+
curl_content_file="$(make_temp_file)"
137+
curl_stdout_file="$(make_temp_file)"
138+
curl_stderr_file="$(make_temp_file)"
139+
140+
curl -4so $curl_content_file -w '%{http_code}' -XPOST \
141+
-H "Authorization: token $(< $github_api_key_file)" -H 'Content-type: application/x-compressed, application/x-tar' \
142+
"$upload_url" --data-binary "@$client_package_file" 1> "$curl_stdout_file" 2> "$curl_stderr_file"
143+
if [[ $? != 0 ]]
144+
then
145+
errexit "curl error exited with code: '$?' see '$curl_stderr_file'"
146+
fi
147+
148+
curl_rslt="$(< $curl_stdout_file)"
149+
if (( curl_rslt != 201 ))
150+
then
151+
errexit "Uploading release assets to GitHub failed with http code '$curl_rslt'"
152+
fi
113153
}
114154

115155
trap onexit EXIT
@@ -132,9 +172,9 @@ fi
132172

133173
declare -r current_branch="$(git rev-parse --abbrev-ref HEAD)"
134174

135-
if [[ $debug == 'false' && $is_prerelease == 'false' && $current_branch != 'master' ]]
175+
if [[ $debug == 'false' && $is_prerelease == 'false' && $current_branch != $client_default_branch ]]
136176
then
137-
errexit 'publish must be run on master branch'
177+
errexit "publish must be run on $client_default_branch branch"
138178
fi
139179

140180
declare -r github_api_key_file="$HOME/.ghapi"
@@ -155,15 +195,25 @@ then
155195
exit 0
156196
fi
157197

158-
set +o nounset
159-
release_gpg_name="${RELEASE_GPG_NAME:-$2}"
160-
if [[ -z $release_gpg_name ]]
198+
declare -r client_name="${2:-''}"
199+
if [[ -z $client_name ]]
161200
then
162-
errexit '$RELEASE_GPG_NAME must be set, or key name passed as second arg'
201+
errexit 'second argument must be client name ("Riak Java Client")'
163202
fi
164-
set -o nounset
165203

166-
git tag --sign -a "$version_string" -m "riak-client-tools $version_string" --local-user "$release_gpg_name"
167-
git push --tags
168-
sleep 5
204+
declare -r client_slug="${3:-''}"
205+
if [[ -z $client_slug ]]
206+
then
207+
errexit 'third argument must be client slug ("riak-java-client")'
208+
fi
209+
210+
declare -r client_default_branch="${4:-''}"
211+
if [[ -z $client_default_branch ]]
212+
then
213+
errexit 'fourth argument must be client default branch ("master")'
214+
fi
215+
216+
declare -r client_package_file="${5:-''}"
217+
declare -r client_package_name="${6:-''}"
218+
169219
gh_publish

0 commit comments

Comments
 (0)