summaryrefslogtreecommitdiffhomepage
path: root/android/build.sh
blob: ab0a591869b01004963d7c35ca117859598c2a05 (plain)
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/usr/bin/env bash

set -eu

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd "$SCRIPT_DIR"

GRADLE_BUILD_TYPE="release"
GRADLE_TASKS=(createOssProdReleaseDistApk createPlayProdReleaseDistApk)
BUILD_BUNDLE="no"
BUNDLE_TASKS=(createPlayProdReleaseDistBundle)
RUN_PLAY_PUBLISH_TASKS="no"
PLAY_PUBLISH_TASKS=()

while [ -n "${1:-""}" ]; do
    if [[ "${1:-""}" == "--dev-build" ]]; then
        GRADLE_BUILD_TYPE="debug"
        GRADLE_TASKS=(createOssProdDebugDistApk)
        BUNDLE_TASKS=(createOssProdDebugDistBundle)
    elif [[ "${1:-""}" == "--fdroid" ]]; then
        GRADLE_BUILD_TYPE="fdroid"
        GRADLE_TASKS=(createOssProdFdroidDistApk)
        BUNDLE_TASKS=(createOssProdFdroidDistBundle)
    elif [[ "${1:-""}" == "--app-bundle" ]]; then
        BUILD_BUNDLE="yes"
    elif [[ "${1:-""}" == "--enable-play-publishing" ]]; then
        RUN_PLAY_PUBLISH_TASKS="yes"
    fi

    shift 1
done

function assert_clean_working_directory {
    if [[ -n "$(git status --porcelain)" ]]; then
        echo "Dirty working directory! Will not accept that for an official release."
        exit 1
    fi
}

if [[ "$GRADLE_BUILD_TYPE" == "release" ]]; then
    assert_clean_working_directory

    if [ ! -f "$SCRIPT_DIR/credentials/keystore.properties" ]; then
        echo "ERROR: No keystore.properties file found" >&2
        echo "       Please configure the signing keys as described in the README" >&2
        exit 1
    fi
fi

echo "Computing build version..."
echo ""
PRODUCT_VERSION=$(cargo run -q --bin mullvad-version versionName)
echo "Building Mullvad VPN $PRODUCT_VERSION for Android"
echo ""

if [[ "$GRADLE_BUILD_TYPE" == "release" ]]; then
    if [[ "$PRODUCT_VERSION" == *"-alpha"* || "$PRODUCT_VERSION" == *"-dev-"* ]]; then
        GRADLE_TASKS+=(
            createPlayDevmoleReleaseDistApk
            createPlayStagemoleReleaseDistApk
        )
        BUNDLE_TASKS+=(
            createPlayDevmoleReleaseDistBundle
            createPlayStagemoleReleaseDistBundle
        )
    fi

    if [[ "$PRODUCT_VERSION" != *"-dev-"* ]]; then
        PLAY_PUBLISH_TASKS+=(
            publishPlayProdReleaseBundle
        )
        if [[ "$PRODUCT_VERSION" == *"-alpha"* ]]; then
            PLAY_PUBLISH_TASKS+=(
                publishPlayDevmoleReleaseBundle
                publishPlayStagemoleReleaseBundle
            )
        fi
    fi
fi

# Fallback to the system-wide gradle command if the gradlew script is removed.
# It is removed by the F-Droid build process before the build starts.
if [ -f "gradlew" ]; then
    GRADLE_CMD="./gradlew"
elif which gradle > /dev/null; then
    GRADLE_CMD="gradle"
else
    echo "ERROR: No gradle command found" >&2
    echo "       Please either install gradle or restore the gradlew file" >&2
    exit 2
fi

$GRADLE_CMD --console plain clean

$GRADLE_CMD --console plain "${GRADLE_TASKS[@]}"

if [[ "$BUILD_BUNDLE" == "yes" ]]; then
    $GRADLE_CMD --console plain "${BUNDLE_TASKS[@]}"
fi

# When building releases, we check that the working directory is clean before building,
# further up. Now verify that this is still true. The build process should never make the
# working directory dirty.
# This could for example happen if lockfiles are outdated, and the build process updates them.
if [[ "$GRADLE_BUILD_TYPE" == "release" ]]; then
    assert_clean_working_directory
fi

if [[ "$RUN_PLAY_PUBLISH_TASKS" == "yes" && "${#PLAY_PUBLISH_TASKS[@]}" -ne 0 ]]; then
    $GRADLE_CMD --console plain "${PLAY_PUBLISH_TASKS[@]}"
fi

echo "**********************************"
echo ""
echo " The build finished successfully! "
echo " You have built:"
echo ""
echo " $PRODUCT_VERSION"
echo ""
echo " Build checksums:"
sha256sum ../dist/MullvadVPN-"$PRODUCT_VERSION"* | sed 's/^/ /'
echo ""
echo "**********************************"