Skip to content

Commit 419dbc5

Browse files
authored
Merge pull request #18 from basho/features/lrb/add-publish-script-gh-17
Add generic publish script
2 parents 7b4b423 + bf779b8 commit 419dbc5

File tree

3 files changed

+87
-22
lines changed

3 files changed

+87
-22
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) master 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) master 'Riak Client Tools' 'riak-client-tools'

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: 71 additions & 22 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,12 +109,59 @@ 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
116156

117157
declare -r version_string="${1:-unknown}"
118158

159+
declare -r client_default_branch="${2:-''}"
160+
if [[ -z $client_default_branch ]]
161+
then
162+
errexit 'second argument must be default git branch ("master")'
163+
fi
164+
119165
if [[ ! $version_string =~ ^[0-9].[0-9].[0-9](-[a-z]+[0-9]+)?$ ]]
120166
then
121167
errexit 'first argument must be valid version string in X.Y.Z format'
@@ -130,40 +176,43 @@ else
130176
pinfo "publishing version $version_string"
131177
fi
132178

133-
declare -r current_branch="$(git rev-parse --abbrev-ref HEAD)"
134-
135-
if [[ $debug == 'false' && $is_prerelease == 'false' && $current_branch != 'master' ]]
136-
then
137-
errexit 'publish must be run on master branch'
138-
fi
139-
140179
declare -r github_api_key_file="$HOME/.ghapi"
141180
if [[ ! -s $github_api_key_file ]]
142181
then
143182
errexit "please save your GitHub API token in $github_api_key_file"
144183
fi
145184

185+
declare -r current_branch="$(git rev-parse --abbrev-ref HEAD)"
186+
if [[ $debug == 'false' && $is_prerelease == 'false' && $current_branch != $client_default_branch ]]
187+
then
188+
errexit "publish must be run on $client_default_branch branch"
189+
fi
190+
146191
# Validate commands
147192
if ! hash curl 2>/dev/null
148193
then
149194
errexit "'curl' must be in your PATH"
150195
fi
151196

152-
validate=${2:-''}
197+
validate=${3:-''}
153198
if [[ $validate == 'validate' ]]
154199
then
155200
exit 0
156201
fi
157202

158-
set +o nounset
159-
release_gpg_name="${RELEASE_GPG_NAME:-$2}"
160-
if [[ -z $release_gpg_name ]]
203+
declare -r client_name="${3:-''}"
204+
if [[ -z $client_name ]]
161205
then
162-
errexit '$RELEASE_GPG_NAME must be set, or key name passed as second arg'
206+
errexit 'third argument must be client name ("Riak Java Client")'
163207
fi
164-
set -o nounset
165208

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
209+
declare -r client_slug="${4:-''}"
210+
if [[ -z $client_slug ]]
211+
then
212+
errexit 'fourth argument must be client slug ("riak-java-client")'
213+
fi
214+
215+
declare -r client_package_file="${5:-''}"
216+
declare -r client_package_name="${6:-''}"
217+
169218
gh_publish

0 commit comments

Comments
 (0)