forked from d2iq-archive/dcos-commons
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrelease.sh
executable file
·102 lines (90 loc) · 3.44 KB
/
release.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
# --
# Builds and uploads a release of the SDK against a release-specific tag.
# This does NOT create releases of individual services in the repo, just the SDK itself.
# --
syntax() {
echo "Syntax: ./release.sh -r <tagname or 'snapshot'> [-f]"
echo "Arguments:"
echo " -r: The version string of the SDK to be used in gradle and in the tag name, or '-r snapshot' to publish a snapshot of master."
echo " -f: Force the tag creation if the tag already exists. (not applicable to '-r snapshot')"
}
# Exit immediately on failure:
set -e
REPO_ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd $REPO_ROOT_DIR
GRADLE_BUILD_FILE=$REPO_ROOT_DIR/build.gradle
FLAG_RELEASE=""
FLAG_FORCE="false"
while getopts "r:f" opt; do
case $opt in
r)
FLAG_RELEASE=${OPTARG,,} # to lowercase
;;
f)
FLAG_FORCE="true"
;;
\?)
syntax
exit 1
;;
esac
done
if [ -z "$FLAG_RELEASE" ]; then
echo "Missing required tag argument (-r <tagname or 'snapshot'>)"
syntax
exit 1
fi
echo "Settings: tag=$FLAG_RELEASE force=$FLAG_FORCE"
export SDK_VERSION=$(egrep "version = '(.*)'" $GRADLE_BUILD_FILE | cut -d "'" -f2)
if [ -z "$SDK_VERSION" ]; then
echo "Unable to extract SDK version from $GRADLE_BUILD_FILE"
exit 1
fi
echo "Current gradle version: $SDK_VERSION"
if [ "x${FLAG_RELEASE}" = "xsnapshot" ]; then
# Sanity check: Validate that build.gradle already has a '-SNAPSHOT' version (case sensitive comparison)
if [[ "$SDK_VERSION" != *"-SNAPSHOT"* ]]; then
echo "SDK version in $GRADLE_BUILD_FILE doesn't contain '-SNAPSHOT'."
echo "The master branch must only have snapshot builds."
exit 1
fi
else
# Uploading a release: Create and publish the release tag, which contains a commit updating build.gradle.
# Sanity check: Tagged releases of snapshots is disallowed (case insensitive comparison)
if [[ "${FLAG_RELEASE^^}" = *"SNAPSHOT"* ]]; then
echo "Requested tag release version may not contain 'SNAPSHOT'."
exit 1
fi
sed -i "s/version = '${SDK_VERSION}'/version = '${FLAG_RELEASE}'/" $GRADLE_BUILD_FILE
export SDK_VERSION=$FLAG_RELEASE
git add $GRADLE_BUILD_FILE
git commit -m "Automated cut of $FLAG_RELEASE"
if [ "x$FLAG_FORCE" = "xtrue" ]; then
git tag -f "$FLAG_RELEASE"
git push origin -f "$FLAG_RELEASE"
else
FAILED=""
git tag "$FLAG_RELEASE" || FAILED="true"
# Jump through hoops to avoid conflicts with 'set -e':
if [ -n "$FAILED" ]; then
echo "Tag named '$FLAG_RELEASE' already exists locally. Use '-f' to overwrite the current tag."
exit 1
fi
git push origin "$FLAG_RELEASE" || FAILED="true"
if [ -n "$FAILED" ]; then
echo "Tag named '$FLAG_RELEASE' already exists in remote repo. Use '-f' to overwrite the current tag."
exit 1
fi
fi
fi
# Build and upload Java library to Maven repo:
./build.sh
./gradlew publish
# Scripts below expect an S3_BUCKET env var. To be supplied by Jenkins.
# INFINITY-1208: Disable build and publish for now as it requires changes coming in
# the self-hosted branch. 3-27-17 bwood
# ./tools/build_publishable.sh
# ./tools/release_artifacts.sh
# Note: We *don't* run /tools/release.sh here, and instead have CI run it manually.
# This ensures that builds against different tags don't step on each other.