Skip to content

Commit 4f4cedf

Browse files
authored
build: Support uploading releases separately from building
1 parent ebf8a63 commit 4f4cedf

File tree

3 files changed

+139
-2
lines changed

3 files changed

+139
-2
lines changed

build.gradle

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,12 @@ subprojects {
317317
authentication(userName: rootProject.ossrhUsername, password: rootProject.ossrhPassword)
318318
}
319319
}
320-
repository(url: stagingUrl, configureAuth)
321-
snapshotRepository(url: 'https://oss.sonatype.org/content/repositories/snapshots/', configureAuth)
320+
if (rootProject.hasProperty('repositoryDir')) {
321+
repository(url: new File(rootProject.repositoryDir).toURI())
322+
} else {
323+
repository(url: stagingUrl, configureAuth)
324+
snapshotRepository(url: 'https://oss.sonatype.org/content/repositories/snapshots/', configureAuth)
325+
}
322326
}
323327
uploadArchives.onlyIf { !name.contains("grpc-gae-interop-testing") }
324328

buildscripts/sign-local-repo.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/bash
2+
# Copyright 2017, gRPC Authors All rights reserved.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
set -e
17+
18+
if [ $# -ne 1 ]; then
19+
cat <<EOF
20+
Usage: $0 DIR
21+
DIR Local repository with files needing to be signed
22+
EOF
23+
exit 1
24+
fi
25+
26+
find "$1" -type f | egrep -v '\.(md5|sha1)$' | grep -v maven-metadata.xml | xargs gpg -ab

buildscripts/sonatype-upload.sh

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
#!/bin/bash
2+
# Copyright 2017, gRPC Authors All rights reserved.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
set -e
17+
18+
if [ $# -ne 2 ]; then
19+
cat <<EOF
20+
Usage: $0 PROFILEID DIR
21+
PROFILEID The Sonatype profile to use for staging repository
22+
Obtain profile ID from https://oss.sonatype.org:
23+
* Build Promotion > Staging Profiles
24+
* Select profile based on name (e.g., 'io.grpc')
25+
* Copy hex identifier from URL after "#stagingProfiles;"
26+
DIR Directory to upload to Sonatype as a new staging repository
27+
28+
~/.config/sonatype-upload: Configuration file for Sonatype username and password
29+
USERNAME=yourusername
30+
PASSWORD=yourpass
31+
32+
Sonatype provides a "user token" that is a randomly generated username/password.
33+
It does allow access to your account, however. You can create one via:
34+
* Log in to https://oss.sonatype.org
35+
* Click your username at the top right and click to Profile
36+
* Change the drop-down from "Summary" to "User Token"
37+
* Click "Access User Token"
38+
EOF
39+
exit 1
40+
fi
41+
42+
PROFILE_ID="$1"
43+
DIR="$2"
44+
if [ -z "$DIR" ]; then
45+
echo "Must specify non-empty directory name"
46+
exit 1
47+
fi
48+
49+
[ -f "$CONF" ] && . "$CONF"
50+
51+
if [ -z "$USERNAME" -o -z "$PASSWORD" ]; then
52+
# TODO(ejona86): if people would use it, could prompt for values to avoid
53+
# having passwords in plain-text.
54+
echo "You must create '$CONF' with keys USERNAME and PASSWORD" >&2
55+
exit 1
56+
fi
57+
58+
CONF="$HOME/.config/sonatype-upload"
59+
STAGING_URL="https://oss.sonatype.org/service/local/staging"
60+
61+
# We go through the effort of using deloyByRepositoryId/ because it is
62+
# _substantially_ faster to upload files than deploy/maven2/. When using
63+
# deploy/maven2/ a repository is implicitly created, but the response doesn't
64+
# provide its name.
65+
66+
USERPASS="$USERNAME:$PASSWORD"
67+
68+
# https://oss.sonatype.org/nexus-staging-plugin/default/docs/index.html
69+
#
70+
# Example returned data:
71+
# <promoteResponse>
72+
# <data>
73+
# <stagedRepositoryId>iogrpc-1082</stagedRepositoryId>
74+
# <description>Release upload</description>
75+
# </data>
76+
# </promoteResponse>
77+
echo "Creating staging repo"
78+
REPOID="$(
79+
XML="
80+
<promoteRequest>
81+
<data>
82+
<description>Release upload</description>
83+
</data>
84+
</promoteRequest>"
85+
curl -s -X POST -d "$XML" -u "$USERPASS" -H "Content-Type: application/xml" \
86+
"$STAGING_URL/profiles/$PROFILE_ID/start" |
87+
grep stagedRepositoryId |
88+
sed 's/.*<stagedRepositoryId>\(.*\)<\/stagedRepositoryId>.*/\1/'
89+
)"
90+
echo "Repository id: $REPOID"
91+
92+
for X in $(cd "$DIR" && find -type f | cut -b 3-); do
93+
echo "Uploading $X"
94+
curl -T "$DIR/$X" -u "$USERPASS" -H "Content-Type: application/octet-stream" \
95+
"$STAGING_URL/deployByRepositoryId/$REPOID/$X"
96+
done
97+
98+
echo "Closing staging repo"
99+
XML="
100+
<promoteRequest>
101+
<data>
102+
<stagedRepositoryId>$REPOID</stagedRepositoryId>
103+
<description>Auto-close via upload script</description>
104+
</data>
105+
</promoteRequest>"
106+
curl -X POST -d "$XML" -u "$USERPASS" -H "Content-Type: application/xml" \
107+
"$STAGING_URL/profiles/$PROFILE_ID/finish"

0 commit comments

Comments
 (0)