-
Notifications
You must be signed in to change notification settings - Fork 0
/
maven-central-deploy.sh
executable file
·153 lines (121 loc) · 4.02 KB
/
maven-central-deploy.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
#!/bin/sh
fatal()
{
echo "fatal: $1" 1>&2
exit 1
}
info()
{
echo "info: $1" 1>&2
sleep 5
}
if [ $# -ne 2 ]
then
echo "usage: username password" 1>&2
exit 1
fi
MAVEN_CENTRAL_USERNAME="$1"
shift
MAVEN_CENTRAL_PASSWORD="$1"
shift
MAVEN_CENTRAL_STAGING_PROFILE_ID="a56bb91d0cd124"
which wget || fatal "Please install wget"
which openssl || fatal "Please install OpenSSL"
which java || fatal "Please install java"
#------------------------------------------------------------------------
# Download Brooklime if necessary.
#
BROOKLIME_URL="https://repo1.maven.org/maven2/com/io7m/brooklime/com.io7m.brooklime.cmdline/0.1.1/com.io7m.brooklime.cmdline-0.1.1-main.jar"
BROOKLIME_SHA256_EXPECTED="efce745f90741aa18c9751c5707580abc123088a8de6d6081fff58f8533f9d8e"
if [ ! -f "brooklime.jar" ]
then
wget -O "brooklime.jar" "${BROOKLIME_URL}" || fatal "could not download brooklime"
fi
BROOKLIME_SHA256_RECEIVED=$(openssl sha256 "brooklime.jar" | awk '{print $NF}') || fatal "could not checksum brooklime.jar"
if [ "${BROOKLIME_SHA256_EXPECTED}" != "${BROOKLIME_SHA256_RECEIVED}" ]
then
fatal "brooklime.jar checksum does not match.
Expected: ${BROOKLIME_SHA256_EXPECTED}
Received: ${BROOKLIME_SHA256_RECEIVED}"
fi
#------------------------------------------------------------------------
# Deploy artifacts to a temporary directory.
#
TIMESTAMP=$(date "+%Y%m%d-%H%M%S") || fatal "could not create timestamp"
TEMPORARY_DIRECTORY="/tmp/irradia-${TIMESTAMP}"
info "Artifacts will temporarily be deployed to ${TEMPORARY_DIRECTORY}"
rm -rf "${TEMPORARY_DIRECTORY}" || fatal "could not ensure temporary directory is clean"
mkdir -p "${TEMPORARY_DIRECTORY}" || fatal "could not create a temporary directory"
info "Calling Gradle to publish to temporary directory"
./gradlew -Pone.irradia.directory.publish="${TEMPORARY_DIRECTORY}" clean assemble publish || fatal "could not publish to directory"
#------------------------------------------------------------------------
# Create a staging repository on Maven Central.
#
info "Creating a staging repository on Maven Central"
(cat <<EOF
create
--description
Simplified ${TIMESTAMP}
--stagingProfileId
${MAVEN_CENTRAL_STAGING_PROFILE_ID}
--user
${MAVEN_CENTRAL_USERNAME}
--password
${MAVEN_CENTRAL_PASSWORD}
EOF
) > args.txt || fatal "Could not write argument file"
MAVEN_CENTRAL_STAGING_REPOSITORY_ID=$(java -jar brooklime.jar @args.txt) || fatal "Could not create staging repository"
#------------------------------------------------------------------------
# Upload content to the staging repository on Maven Central.
#
info "Uploading content to repository ${MAVEN_CENTRAL_STAGING_REPOSITORY_ID}"
(cat <<EOF
upload
--stagingProfileId
${MAVEN_CENTRAL_STAGING_PROFILE_ID}
--user
${MAVEN_CENTRAL_USERNAME}
--password
${MAVEN_CENTRAL_PASSWORD}
--directory
${TEMPORARY_DIRECTORY}
--repository
${MAVEN_CENTRAL_STAGING_REPOSITORY_ID}
EOF
) > args.txt || fatal "Could not write argument file"
java -jar brooklime.jar @args.txt || fatal "Could not upload content"
#------------------------------------------------------------------------
# Close the staging repository.
#
info "Closing repository ${MAVEN_CENTRAL_STAGING_REPOSITORY_ID}. This can take a few minutes."
(cat <<EOF
close
--stagingProfileId
${MAVEN_CENTRAL_STAGING_PROFILE_ID}
--user
${MAVEN_CENTRAL_USERNAME}
--password
${MAVEN_CENTRAL_PASSWORD}
--repository
${MAVEN_CENTRAL_STAGING_REPOSITORY_ID}
EOF
) > args.txt || fatal "Could not write argument file"
java -jar brooklime.jar @args.txt || fatal "Could not close staging repository"
#------------------------------------------------------------------------
# Release the staging repository.
#
info "Releasing repository ${MAVEN_CENTRAL_STAGING_REPOSITORY_ID}"
(cat <<EOF
release
--stagingProfileId
${MAVEN_CENTRAL_STAGING_PROFILE_ID}
--user
${MAVEN_CENTRAL_USERNAME}
--password
${MAVEN_CENTRAL_PASSWORD}
--repository
${MAVEN_CENTRAL_STAGING_REPOSITORY_ID}
EOF
) > args.txt || fatal "Could not write argument file"
java -jar brooklime.jar @args.txt || fatal "Could not release staging repository"
info "Release completed"