Skip to content
This repository was archived by the owner on Jan 31, 2022. It is now read-only.

Commit 513bfcd

Browse files
author
Clément Le Provost
committed
Fix Maven publishing process
- Systematically clean before building. - Test linking with the local publication before releasing. This should help identify corrupted archives. Refs #88. - Restore the automatic commit, tag and push… but make sure the working copy is clean before releasing.
1 parent 76a5f9f commit 513bfcd

File tree

4 files changed

+151
-19
lines changed

4 files changed

+151
-19
lines changed

release.sh

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,24 +27,40 @@ fi
2727

2828
VERSION_CODE=$1
2929

30-
echo "Updating version code to $VERSION_CODE..."
31-
call_sed "s/(PUBLISH_VERSION =) '.*'/\1 '$VERSION_CODE'/" $FILE_BUILD_GRADLE
32-
call_sed "s/(private final static String version =) \".*\"/\1 \"$VERSION_CODE\"/" $FILE_API_CLIENT
30+
# Check that the working repository is clean (without any changes, neither staged nor unstaged).
31+
if [[ ! -z `git status --porcelain` ]]; then
32+
echo "ERROR: Working copy not clean! Aborting." 1>&2
33+
echo "Please revert or commit any pending changes before releasing." 1>&2
34+
exit 1
35+
fi
3336

34-
git diff $FILE_BUILD_GRADLE $FILE_API_CLIENT
37+
$SELF_ROOT/tools/update-version.sh $VERSION_CODE
3538

36-
echo "Uploading flavor 'online'..."
37-
$SELF_ROOT/select-flavor.sh online
38-
$SELF_ROOT/gradlew uploadArchives 1>/dev/null
39+
for flavor in online offline
40+
do
41+
echo "========== Processing flavor '$flavor' =========="
42+
$SELF_ROOT/select-flavor.sh $flavor
43+
$SELF_ROOT/gradlew clean
44+
$SELF_ROOT/gradlew uploadArchives
45+
if [[ $flavor = "online" ]]; then
46+
module_name="algoliasearch-android"
47+
elif [[ $flavor = "offline" ]]; then
48+
module_name="algoliasearch-offline-android"
49+
fi
50+
# Dump the contents that has been published, just for the sake of manual checking.
51+
$SELF_ROOT/tools/dump-local-mvnrep.sh $module_name
52+
echo "---------- Testing publication ----------"
53+
$SELF_ROOT/tools/test-publication.sh $module_name $VERSION_CODE
54+
done
3955

40-
echo "Uploading flavor 'offline'"
41-
$SELF_ROOT/select-flavor.sh online
42-
$SELF_ROOT/gradlew uploadArchives 1>/dev/null
43-
44-
echo "Success! Closing and releasing new version..."
56+
echo "SUCCESS: closing and releasing new version..."
4557
$SELF_ROOT/gradlew closeAndPromoteRepository 1>/dev/null
4658

4759
# Revert flavor to original.
4860
git checkout $SELF_ROOT/algoliasearch/build.gradle
4961

50-
echo "IMPORANT: Remember to git commit & tag & push"
62+
# Commit to Git.
63+
git add .
64+
git commit -m "Version $VERSION_CODE"
65+
git tag $VERSION_CODE
66+
git push --tags origin master

dump-local-mvnrep.sh renamed to tools/dump-local-mvnrep.sh

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env ksh
22
# ============================================================================ #
3-
# CHECK LOCAL MVNREP #
3+
# DUMP LOCAL MVNREP #
44
# ============================================================================ #
55
# SUMMARY
66
# -------
@@ -10,10 +10,16 @@
1010

1111
# Reflection.
1212
SELF_ROOT=$(cd $(dirname "$0") && pwd)
13+
PROJECT_ROOT=`cd "$SELF_ROOT/.." && pwd`
1314

14-
MVNREP_DIR="$SELF_ROOT/algoliasearch/build/mvnrep"
15+
MVNREP_DIR="$PROJECT_ROOT/algoliasearch/build/mvnrep"
1516
COM_ALGOLIA_DIR="$MVNREP_DIR/com/algolia"
1617

18+
if [ $# -lt 1 ]; then
19+
echo "Please specify module name" 1>&2
20+
exit
21+
fi
22+
1723
# Dump the module with the specified name.
1824
dumpModule()
1925
{
@@ -44,12 +50,10 @@ dumpModule()
4450
TMP_DIR=`mktemp -d`
4551

4652
# Retrieve version number from root Gradle script.
47-
VERSION=`cat "$SELF_ROOT/algoliasearch/common.gradle" | grep -E "PUBLISH_VERSION\s*=\s*'[0-9.]+(-SNAPSHOT)?'" | cut -d "'" -f 2`
53+
VERSION=`cat "$PROJECT_ROOT/algoliasearch/common.gradle" | grep -E "PUBLISH_VERSION\s*=\s*'[0-9.]+(-SNAPSHOT)?'" | cut -d "'" -f 2`
4854
echo "Version: $VERSION"
4955

50-
# Dump online and offline flavors.
51-
dumpModule "algoliasearch-android"
52-
dumpModule "algoliasearch-offline-android"
56+
dumpModule "$1"
5357

5458
# Clean-up.
5559
rm -rf "$TMP_DIR"

tools/test-publication.sh

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/usr/bin/env ksh
2+
# ============================================================================ #
3+
# TEST PUBLICATION
4+
# ============================================================================ #
5+
# SUMMARY
6+
# -------
7+
# Test that the demo project can link against the (locally) published version.
8+
# Meant to be run before actually promoting the release.
9+
# ============================================================================ #
10+
11+
# Reflection.
12+
SELF_ROOT=`cd \`dirname "$0"\` && pwd`
13+
SELF_NAME=`basename "$0"`
14+
15+
PROJECT_ROOT=`cd "$SELF_ROOT/.." && pwd`
16+
17+
usage()
18+
{
19+
echo "Usage:"
20+
echo " $SELF_NAME <module_name> <version_no>"
21+
}
22+
23+
24+
if [[ $# -lt 2 ]]; then
25+
usage 1>&2
26+
exit 1
27+
fi
28+
29+
MODULE_NAME="$1"
30+
VERSION_NO="$2"
31+
32+
# Retrieve the latest demo sources.
33+
DEMO_DIR=`mktemp -d`
34+
DEMO_REPO="algolia/algolia-android-demo.git"
35+
git clone "[email protected]:$DEMO_REPO" "$DEMO_DIR"
36+
cd "$DEMO_DIR"
37+
38+
# Patch the version.
39+
echo "Targeting $MODULE_NAME $VERSION_NO"
40+
sed -E -i '' "s/compile 'com\.algolia:algoliasearch-android:[0-9.]+@aar'/compile 'com.algolia:${MODULE_NAME}:${VERSION_NO}@aar'/g" "app/build.gradle"
41+
42+
# Use the local repo.
43+
MVNREP_DIR="$PROJECT_ROOT/algoliasearch/build/mvnrep"
44+
echo "Targeting repository '$MVNREP'"
45+
cat >> build.gradle <<EOF
46+
allprojects {
47+
repositories {
48+
maven {
49+
url "file://$MVNREP_DIR"
50+
}
51+
}
52+
}
53+
EOF
54+
55+
# Build with the new version.
56+
echo "Building..."
57+
./gradlew assembleRelease
58+
rc=$?
59+
60+
# Clean up.
61+
rm -rf "$DEMO_DIR"
62+
63+
exit $rc

tools/update-version.sh

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env ksh
2+
# ============================================================================ #
3+
# UPDATE VERSION #
4+
# ============================================================================ #
5+
# SUMMARY
6+
# -------
7+
# Updates the version number in the sources.
8+
# ============================================================================ #
9+
10+
set -eo pipefail
11+
12+
SELF_ROOT=$(cd $(dirname "$0") && pwd)
13+
SELF_NAME=$(basename "$0")
14+
15+
function call_sed
16+
{
17+
PATTERN="$1"
18+
FILENAME="$2"
19+
20+
# Mac needs a space between sed's inplace flag and extension
21+
if [ "$(uname)" == "Darwin" ]; then
22+
sed -E -i '' "$PATTERN" "$FILENAME"
23+
else
24+
sed -E -i "$PATTERN" "$FILENAME"
25+
fi
26+
}
27+
28+
function usage
29+
{
30+
cat <<#EOF
31+
Usage:
32+
$SELF_NAME <version_no>
33+
EOF
34+
}
35+
36+
PROJECT_ROOT=`cd "$SELF_ROOT/.." && pwd`
37+
FILE_BUILD_GRADLE="$PROJECT_ROOT/algoliasearch/common.gradle"
38+
FILE_API_CLIENT="$PROJECT_ROOT/algoliasearch/src/main/java/com/algolia/search/saas/Client.java"
39+
40+
if [ $# -ne 1 ]; then
41+
usage 1>&2
42+
exit -1
43+
fi
44+
45+
VERSION_CODE=$1
46+
47+
echo "Updating version number to $VERSION_CODE..."
48+
call_sed "s/(PUBLISH_VERSION =) '.*'/\1 '$VERSION_CODE'/" $FILE_BUILD_GRADLE
49+
call_sed "s/(private final static String version =) \".*\"/\1 \"$VERSION_CODE\"/" $FILE_API_CLIENT

0 commit comments

Comments
 (0)