-
Notifications
You must be signed in to change notification settings - Fork 0
/
upload.sh
executable file
·91 lines (76 loc) · 2.76 KB
/
upload.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
#!/bin/bash
# Upload script for Maven Central Repository
# Uses OSS Nexus as the interface to expose the artifacts. After successful end, all artifacts are prepared inside
# a newly created staging repository; the user's responsibility is to close and release it manually.
# "5ae9af53a3aeee" for net.kozelka
stagingProfileId=$1
function createStagedRepository() {
local stagingProfileId=$1
local description=$2
local stagedRepositoryId
echo "Creating staged repository for profile $stagingProfileId" >&2
stagedRepositoryId=$($CURL -X POST $OSSRH_STAGING/profiles/${stagingProfileId}/start \
-H Content-Type:application/xml \
--data "
<promoteRequest>
<data>
<description>$description</description>
</data>
</promoteRequest>" | sed -n '/<stagedRepositoryId>/{s:stagedRepositoryId::g;s:[[:space:]<>/]::g;p;}')
echo "Created staging repository: $stagedRepositoryId" >&2
echo "$stagedRepositoryId"
test -n "$stagedRepositoryId"
}
function finishStagedRepository() {
local stagingProfileId=${1}
local stagedRepositoryId=${2}
echo "Closing staged repository '$stagedRepositoryId' for profile $stagingProfileId" >&2
$CURL -X POST $OSSRH_STAGING/profiles/${stagingProfileId}/finish \
-H Content-Type:application/xml \
--data "
<promoteRequest>
<data>
<stagedRepositoryId>${stagedRepositoryId}</stagedRepositoryId>
</data>
</promoteRequest>"
}
# Upload current directory which must have the structure of maven repo into Nexus
function uploadMavenRepository() {
local stagedRepositoryId=$1
for G in $(find * -name '*.pom' -printf '%h\n'); do
echo "Signing files in $G"
# sign all files that need to be signed
rm -f $G/*.asc
/bin/ls -1 $G/* | grep -v '\.md5$\|\.sha1$' | xargs -L 1 gpg -ab
# upload everything in the directory
FILES=$(find $G -type f -printf ',%f')
FILES="{${FILES:1}}"
local url
if [ -z "$stagedRepositoryId" ]; then
url=$OSSRH_STAGING/deploy/maven2/$G/
else
url=$OSSRH_STAGING/deployByRepositoryId/$stagedRepositoryId/$G/
fi
echo "Uploading files to $url : $FILES"
$CURL "$url" --upload-file "$G/$FILES" || return 1
done
}
function publishRelease() {
if [ -n "$stagingProfileId" ]; then
stagedRepositoryId=$(createStagedRepository "$stagingProfileId" "$PWD")
[ -z "$stagedRepositoryId" ] && return 1
fi
uploadMavenRepository "$stagedRepositoryId" || return 1
if [ -n "$stagedRepositoryId" ]; then
finishStagedRepository "$stagingProfileId" "$stagedRepositoryId" || return 1
fi
}
#### MAIN ####
if [ -z "${OSSRH_AUTH}" ]; then
echo "ERROR: Missing OSSRH_AUTH" >&2
exit 1
fi
OSSRH_STAGING="https://oss.sonatype.org/service/local/staging"
CURL="curl -u $OSSRH_AUTH --fail"
cd target/release-package/maven-repository || exit 1
publishRelease