File: sonatype-upload.sh

package info (click to toggle)
grpc-java 1.26.0%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid
  • size: 11,852 kB
  • sloc: java: 146,813; cpp: 1,174; xml: 1,037; sh: 662; makefile: 40; python: 40
file content (110 lines) | stat: -rwxr-xr-x 3,567 bytes parent folder | download
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
#!/bin/bash
# Copyright 2017 The gRPC Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -eu -o pipefail

if [ $# -ne 2 ]; then
  cat <<EOF
Usage: $0 PROFILEID DIR
  PROFILEID The Sonatype profile to use for staging repository
            Obtain profile ID from https://oss.sonatype.org:
             * Build Promotion > Staging Profiles
             * Select profile based on name (e.g., 'io.grpc')
             * Copy hex identifier from URL after "#stagingProfiles;"
  DIR       Directory to upload to Sonatype as a new staging repository

~/.config/sonatype-upload: Configuration file for Sonatype username and password
  USERNAME=yourusername
  PASSWORD=yourpass

Sonatype provides a "user token" that is a randomly generated username/password.
It does allow access to your account, however. You can create one via:
 * Log in to https://oss.sonatype.org
 * Click your username at the top right and click to Profile
 * Change the drop-down from "Summary" to "User Token"
 * Click "Access User Token"
EOF
  exit 1
fi

PROFILE_ID="$1"
DIR="$2"
if [ -z "$DIR" ]; then
  echo "Must specify non-empty directory name"
  exit 1
fi

CONF="$HOME/.config/sonatype-upload"
[ -f "$CONF" ] && . "$CONF"

USERNAME="${USERNAME:-}"
PASSWORD="${PASSWORD:-}"

if [ -z "$USERNAME" -o -z "$PASSWORD" ]; then
  # TODO(ejona86): if people would use it, could prompt for values to avoid
  # having passwords in plain-text.
  echo "You must create '$CONF' with keys USERNAME and PASSWORD" >&2
  exit 1
fi

STAGING_URL="https://oss.sonatype.org/service/local/staging"

# We go through the effort of using deloyByRepositoryId/ because it is
# _substantially_ faster to upload files than deploy/maven2/. When using
# deploy/maven2/ a repository is implicitly created, but the response doesn't
# provide its name.

USERPASS="$USERNAME:$PASSWORD"

# https://oss.sonatype.org/nexus-staging-plugin/default/docs/index.html
#
# Example returned data:
#   <promoteResponse>
#     <data>
#       <stagedRepositoryId>iogrpc-1082</stagedRepositoryId>
#       <description>Release upload</description>
#     </data>
#   </promoteResponse>
echo "Creating staging repo"
REPOID="$(
  XML="
  <promoteRequest>
    <data>
      <description>Release upload</description>
    </data>
  </promoteRequest>"
  curl -s -X POST -d "$XML" -u "$USERPASS" -H "Content-Type: application/xml" \
    "$STAGING_URL/profiles/$PROFILE_ID/start" |
  grep stagedRepositoryId |
  sed 's/.*<stagedRepositoryId>\(.*\)<\/stagedRepositoryId>.*/\1/'
  )"
echo "Repository id: $REPOID"

for X in $(cd "$DIR" && find -type f | cut -b 3-); do
  echo "Uploading $X"
  curl -T "$DIR/$X" -u "$USERPASS" -H "Content-Type: application/octet-stream" \
    "$STAGING_URL/deployByRepositoryId/$REPOID/$X"
done

echo "Closing staging repo"
XML="
<promoteRequest>
  <data>
    <stagedRepositoryId>$REPOID</stagedRepositoryId>
    <description>Auto-close via upload script</description>
  </data>
</promoteRequest>"
curl -X POST -d "$XML" -u "$USERPASS" -H "Content-Type: application/xml" \
  "$STAGING_URL/profiles/$PROFILE_ID/finish"