forked from ePages-de/restdocs-api-spec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ci_publish_java.sh
executable file
·102 lines (83 loc) · 2.86 KB
/
ci_publish_java.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
#!/bin/bash
set -e # Exit with nonzero exit code if anything fails
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
SECRET_KEYS_FILE="${SCRIPT_DIR}/secret-keys.gpg"
###############################################################################
# Parameter handling
###############################################################################
usage () {
cat << EOF
DESCRIPTION:
The script publishes the Java libraries of this project to Sonatype or
Maven Local (default).
SYNOPSIS:
$0 [-s] [-h]
OPTIONS:
-s Publish to Sonatype (Default: off)
-h Show this message.
-? Show this message.
REQUIRED ENVIRONMENT VARIABLES:
- FILE_ENCRYPTION_PASSWORD: Passphrase for decrypting the signing keys
- SIGNING_KEY_ID
- SIGNING_PASSWORD
- SONATYPE_USERNAME
- SONATYPE_PASSWORD
DEPENDENCIES:
- gpg: https://help.ubuntu.com/community/GnuPrivacyGuardHowto
EOF
}
while getopts "s h ?" option ; do
case $option in
s) PUBLISH_TO_SONATYPE='true'
;;
h ) usage
exit 0;;
? ) usage
exit 0;;
esac
done
###############################################################################
# Env variables and dependencies
###############################################################################
function check_variable_set() {
_VARIABLE_NAME=$1
_VARIABLE_VALUE=${!_VARIABLE_NAME}
if [[ -z ${_VARIABLE_VALUE} ]]; then
echo "Missing env variable ${_VARIABLE_NAME}"
exit 1
fi
}
check_variable_set FILE_ENCRYPTION_PASSWORD
check_variable_set SIGNING_KEY_ID
check_variable_set SIGNING_PASSWORD
check_variable_set SONATYPE_USERNAME
check_variable_set SONATYPE_PASSWORD
if ! command -v gpg &> /dev/null; then
echo "gpg not installed. See https://help.ubuntu.com/community/GnuPrivacyGuardHowto"
exit 1
fi
###############################################################################
# Parameter handling
###############################################################################
# Decrypt signing key
gpg --quiet --batch --yes --decrypt --passphrase="${FILE_ENCRYPTION_PASSWORD}" \
--output ${SECRET_KEYS_FILE} secret-keys.gpg.enc
if [[ ! -f "${SECRET_KEYS_FILE}" ]]; then
echo "File ${SECRET_KEYS_FILE} does not exist"
exit 1
fi
# Determine where to publish the Java archives
if [[ "${PUBLISH_TO_SONATYPE}" == "true" ]]; then
PUBLISH_GRADLE_TASK="publishToSonatype"
else
PUBLISH_GRADLE_TASK="publishToMavenLocal"
fi
# Publish
./gradlew ${PUBLISH_GRADLE_TASK} \
--info \
--exclude-task :restdocs-api-spec-gradle-plugin:publishToSonatype \
-Dorg.gradle.project.sonatypeUsername="${SONATYPE_USERNAME}" \
-Dorg.gradle.project.sonatypePassword="${SONATYPE_PASSWORD}" \
-Dorg.gradle.project.signing.keyId="${SIGNING_KEY_ID}" \
-Dorg.gradle.project.signing.password="${SIGNING_PASSWORD}" \
-Dorg.gradle.project.signing.secretKeyRingFile="${SECRET_KEYS_FILE}"