|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +set -eo pipefail |
| 4 | + |
| 5 | +SELF_ROOT=$(cd $(dirname "$0") && pwd) |
| 6 | + |
| 7 | +function call_sed(){ |
| 8 | +PATTERN="$1" |
| 9 | +FILENAME="$2" |
| 10 | + |
| 11 | +# Mac needs a space between sed's inplace flag and extension |
| 12 | +if [ "$(uname)" == "Darwin" ]; then |
| 13 | + sed -E -i '' "$PATTERN" "$FILENAME" |
| 14 | +else |
| 15 | + sed -E -i "$PATTERN" "$FILENAME" |
| 16 | +fi |
| 17 | +} |
| 18 | + |
| 19 | +FILE_BUILD_GRADLE="$SELF_ROOT/algoliasearch/common.gradle" |
| 20 | +FILE_API_CLIENT="$SELF_ROOT/algoliasearch/src/main/java/com/algolia/search/saas/Client.java" |
| 21 | + |
| 22 | +if [ $# -ne 1 ]; then |
| 23 | + echo "$0 | A script to release new versions automatically" |
| 24 | + echo "Usage: $0 VERSION_CODE" |
| 25 | + exit -1 |
| 26 | +fi |
| 27 | + |
| 28 | +VERSION_CODE=$1 |
| 29 | + |
| 30 | +$SELF_ROOT/tools/update-version.sh $VERSION_CODE |
| 31 | + |
| 32 | +for flavor in online offline |
| 33 | +do |
| 34 | + echo "==================== Processing flavor '$flavor' ====================" |
| 35 | + $SELF_ROOT/select-flavor.sh $flavor |
| 36 | + $SELF_ROOT/gradlew clean |
| 37 | + |
| 38 | + # Test publication locally. |
| 39 | + echo "-------------------- Publishing locally --------------------" |
| 40 | + $SELF_ROOT/gradlew testUploadArchives |
| 41 | + if [[ $flavor = "online" ]]; then |
| 42 | + module_name="algoliasearch-android" |
| 43 | + elif [[ $flavor = "offline" ]]; then |
| 44 | + module_name="algoliasearch-offline-android" |
| 45 | + fi |
| 46 | + # Dump the contents that has been published, just for the sake of manual checking. |
| 47 | + $SELF_ROOT/tools/dump-local-mvnrep.sh $module_name |
| 48 | + echo "-------------------- Testing publication --------------------" |
| 49 | + $SELF_ROOT/tools/test-publication.sh $module_name $VERSION_CODE |
| 50 | + |
| 51 | + # Perform the actual publication. |
| 52 | + echo "-------------------- Publishing remotely --------------------" |
| 53 | + $SELF_ROOT/gradlew uploadArchives |
| 54 | +done |
| 55 | + |
| 56 | +# Revert flavor to original. |
| 57 | +git checkout $SELF_ROOT/algoliasearch/build.gradle |
| 58 | + |
| 59 | +echo "SUCCESS!" |
| 60 | + |
| 61 | +# NOTE: We don't automatically publish nor Git push. Why? |
| 62 | +# - We cannot be sure what the state of the staging repository was at the beginning of the script. So publishing |
| 63 | +# without controlling it manually is risky. |
| 64 | +# - We don't want to push to Git before the release is actually available on Maven Central, which can take a few hours |
| 65 | +# after the staging repository has been promoted. |
| 66 | +# |
| 67 | +cat <<EOF |
| 68 | +Next steps: |
| 69 | +- Check the staging repository on Sonatype. |
| 70 | +- If everything is OK: close, release and drop the staging repository. |
| 71 | +- Git commit. |
| 72 | +- When the release is available on Maven Central: Git push. |
| 73 | +EOF |
0 commit comments