buildAndDeployFrameworks.sh 7.65 KB
Newer Older
1
#!/usr/bin/env bash
Soomin Lee's avatar
Soomin Lee committed
2 3 4 5 6 7

set -e

CLEAN=yes
DEPLOY_MOBILEVLCKIT=no
DEPLOY_TVVLCKIT=no
8
DEPLOY_MACOSVLCKIT=no
9
TEST_MODE=no
Soomin Lee's avatar
Soomin Lee committed
10 11

BUILD_MOBILEVLCKIT="./buildMobileVLCKit.sh -vf"
12
CREATE_DISTRIBUTION_PACKAGE="./create-distributable-package.sh"
13
STABLE_UPLOAD_URL="https://download.videolan.org/cocoapods/unstable/"
14 15
MOBILE_PODSPEC="MobileVLCKit-unstable.podspec"
TV_PODSPEC="TVVLCKit-unstable.podspec"
16
MACOS_PODSPEC="VLCKit.podspec"
Soomin Lee's avatar
Soomin Lee committed
17

18 19 20
# Note: create-distributable-package script is building VLCKit(s) if not found.
# Note: by default, VLCKit will be build if no option is passed.

Soomin Lee's avatar
Soomin Lee committed
21 22 23
usage()
{
cat << EOF
24
usage: $0 [options]
Soomin Lee's avatar
Soomin Lee committed
25 26 27 28 29

OPTIONS
    -d      Disable cleaning of build directory
    -m      Deploy MobileVLCKit
    -t      Deploy TVVLCKit
30
    -x      Deploy VLCKit for macOS
31
    -l      Start test for build phases
Soomin Lee's avatar
Soomin Lee committed
32 33 34
EOF
}

35
while getopts "hdmtlx" OPTION
Soomin Lee's avatar
Soomin Lee committed
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
do
     case $OPTION in
         h)
            usage
            exit 1
            ;;
         d)
            CLEAN=no
            ;;
         m)
            DEPLOY_MOBILEVLCKIT=yes
            ;;
         t)
            DEPLOY_TVVLCKIT=yes
            ;;
51 52 53
         x)
            DEPLOY_MACOSVLCKIT=yes
            ;;
54 55 56
         l)
            TEST_MODE=yes
            ;;
Soomin Lee's avatar
Soomin Lee committed
57 58 59 60 61 62
         \?)
            usage
            exit 1
            ;;
     esac
done
63
shift "$((OPTIND-1))"
Soomin Lee's avatar
Soomin Lee committed
64

65
VERSION=""
Carola Nitz's avatar
Carola Nitz committed
66
VERSION_DELIMITER="3.0.1a"
67
ROOT_DIR="$(dirname "$(pwd)")"
Soomin Lee's avatar
Soomin Lee committed
68 69 70 71 72
UPLOAD_URL=""
VLC_HASH=""
VLCKIT_HASH=""
DISTRIBUTION_PACKAGE=""
DISTRIBUTION_PACKAGE_SHA=""
73
TARGET=""
Soomin Lee's avatar
Soomin Lee committed
74 75 76 77 78 79 80

##################
# Helper methods #
##################

spushd()
{
81
    pushd $1 2>&1> /dev/null
Soomin Lee's avatar
Soomin Lee committed
82 83 84 85 86 87 88 89 90
}

spopd()
{
    popd 2>&1> /dev/null
}

log()
{
91 92 93 94
    local green='\033[1;32m'
    local orange='\033[1;91m'
    local red='\033[1;31m'
    local normal='\033[0m'
Soomin Lee's avatar
Soomin Lee committed
95 96 97 98 99 100 101 102 103 104
    local color=$green
    local msgType=$1

    if [ "$1" = "Warning" ]; then
        color=$orange
        msgType="Warning"
    elif [ "$1" = "Error" ]; then
        color=$red
        msgType="Error"
    fi
105
    echo -e "[${color}${msgType}${normal}] $2"
Soomin Lee's avatar
Soomin Lee committed
106 107 108 109
}

clean()
{
110
    log "Info" "Starting cleaning..."
Soomin Lee's avatar
Soomin Lee committed
111 112 113
    if [ -d "build" ]; then
        rm -rf "$ROOT_DIR/build"
    else
114
        log "Warning" "Build directory not found!"
Soomin Lee's avatar
Soomin Lee committed
115 116 117 118 119 120
    fi
    log "Info" "Build directory cleaned"
}

buildMobileVLCKit()
{
121
    log "Info" "Starting MobileVLCKit build..."
122 123 124 125 126 127 128 129

    local option="$1"

    if [ "$DEPLOY_MOBILEVLCKIT" = "yes" ]; then
        option=""
    fi

    if ! $BUILD_MOBILEVLCKIT $option; then
130
        log "Error" "MobileVLCKit build failed"
131
        rm -fr "build/"
Soomin Lee's avatar
Soomin Lee committed
132 133 134 135 136 137 138
        exit 1
    fi
    log "Info" "MobileVLCKit build finished!"
}

getVLCHashes()
{
139
    VLCKIT_HASH=$(git rev-parse --short HEAD)
140
    VERSION=$(git describe --tags HEAD)
141
    VLC_HASH=`awk -F'"' '/TESTEDHASH=/ {print $2}' buildMobileVLCKit.sh`
Soomin Lee's avatar
Soomin Lee committed
142 143 144 145 146
}

renamePackage()
{
    if [ "$1" = "-m" ]; then
147
        TARGET="MobileVLCKit"
148
    elif [ "$1" = "-t" ]; then
149
        TARGET="TVVLCKit"
150 151
    elif [ "$1" = "-x" ]; then
        TARGET="VLCKit"
Soomin Lee's avatar
Soomin Lee committed
152 153 154
    fi
    getVLCHashes

155
    local packageName="${TARGET}-REPLACEWITHVERSION.tar.xz"
156

Soomin Lee's avatar
Soomin Lee committed
157
    if [ -f $packageName ]; then
158
        DISTRIBUTION_PACKAGE="${TARGET}-${VERSION}-${VLCKIT_HASH}-${VLC_HASH}.tar.xz"
159
        mv $packageName "$DISTRIBUTION_PACKAGE"
160
        log "Info" "Finished renaming package with name: ${DISTRIBUTION_PACKAGE}"
Soomin Lee's avatar
Soomin Lee committed
161 162 163 164 165 166
    fi
}

packageBuild()
{
    spushd "Packaging"
167
        if ! $CREATE_DISTRIBUTION_PACKAGE "$1"; then
Soomin Lee's avatar
Soomin Lee committed
168 169 170 171 172 173 174 175
            log "Error" "Failed to package!"
            exit 1
        fi
    spopd #Packaging
}

getSHA()
{
176 177
    DISTRIBUTION_PACKAGE_SHA=$(shasum -a 256 "$DISTRIBUTION_PACKAGE" | cut -d " " -f 1)
    log "Info" "Distribution package checksum: ${DISTRIBUTION_PACKAGE_SHA}"
Soomin Lee's avatar
Soomin Lee committed
178 179
}

180
bumpPodspec()
Soomin Lee's avatar
Soomin Lee committed
181 182 183 184 185
{
    local podVersion="s.version   = '${VERSION}'"
    local uploadURL=":http => '${UPLOAD_URL}${DISTRIBUTION_PACKAGE}'"
    local podSHA=":sha256 => '${DISTRIBUTION_PACKAGE_SHA}'"

186 187 188
    perl -i -pe's#s.version.*#'"${podVersion}"'#g' $1
    perl -i -pe's#:http.*#'"${uploadURL},"'#g' $1
    perl -i -pe's#:sha256.*#'"${podSHA}"'#g' $1
Soomin Lee's avatar
Soomin Lee committed
189 190
}

191 192
gitCommit()
{
193
    local podspec="$1"
194

195
    git add "$podspec"
196
    git commit -m "${podspec}: Update version to ${VERSION}"
197 198
}

199
startPodTesting()
200 201 202 203 204 205 206 207 208 209 210 211 212
{
    # Testing on a side even though it ressembles podDeploy() for future tests.
    log "Info" "Starting local tests..."
    spushd "Packaging/podspecs"
        if bumpPodspec $CURRENT_PODSPEC && \
           pod spec lint --verbose $CURRENT_PODSPEC ; then
            log "Info" "Testing succesfull!"
        else
            log "Error" "Testing failed."
        fi
        git checkout $CURRENT_PODSPEC
   spopd #Packaging/podspecs
   rm ${DISTRIBUTION_PACKAGE}
213
   rm -rf ${TARGET}-binary
214 215 216
   log "Warning" "All files generated during tests have been removed."
}

Soomin Lee's avatar
Soomin Lee committed
217 218
podDeploy()
{
219
   log "Info" "Starting podspec operations..."
Soomin Lee's avatar
Soomin Lee committed
220
    spushd "Packaging/podspecs"
221 222 223
        if bumpPodspec $CURRENT_PODSPEC && \
           pod spec lint --verbose $CURRENT_PODSPEC && \
           pod trunk push $CURRENT_PODSPEC && \
224
           gitCommit $CURRENT_PODSPEC; then
225 226
            log "Info" "Podpsec operations successfully finished!"
        else
227
            git checkout $CURRENT_PODSPEC
228
            log "Error" "Podspec operations failed."
229
        fi
230
    spopd #Packaging/podspecs
Soomin Lee's avatar
Soomin Lee committed
231 232 233 234
}

checkIfExistOnRemote()
{
235
    if ! curl --head --silent "$1" | head -n 1 | grep -q 404; then
Soomin Lee's avatar
Soomin Lee committed
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250
        return 0
    else
        return 1
    fi
}

uploadPackage()
{
    # handle upload of distribution package.

    if [ "$DISTRIBUTION_PACKAGE" = "" ]; then
        log "Error" "Distribution package not found!"
        exit 1
    fi

251
    while read -r -n 1 -p "The package is ready please upload it to \"${UPLOAD_URL}\", press a key to continue when uploaded [y,a,r]: " response
Soomin Lee's avatar
Soomin Lee committed
252
    do
253
        printf '\r'
Soomin Lee's avatar
Soomin Lee committed
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272
        case $response in
            y)
                log "Info" "Checking for: '${UPLOAD_URL}${DISTRIBUTION_PACKAGE}'..."
                if checkIfExistOnRemote "${UPLOAD_URL}${DISTRIBUTION_PACKAGE}"; then
                    log "Info" "Package found on ${UPLOAD_URL}!"
                    break
                fi
                log "Warning" "Package not found on ${UPLOAD_URL}!"
                ;;
            a)
                log "Warning" "Aborting deployment process!"
                exit 1
                ;;
            *)
                ;;
        esac
    done
}

273 274 275 276 277 278 279
setCurrentPodspec()
{
    # Addded extra precision of target to protect against future targets
    if [ "$DEPLOY_MOBILEVLCKIT" = "yes" ]; then
        CURRENT_PODSPEC=$MOBILE_PODSPEC
    elif [ "$DEPLOY_TVVLCKIT" = "yes" ]; then
        CURRENT_PODSPEC=$TV_PODSPEC
280 281
    elif [ "DEPLOY_MACOSVLCKIT" = "yes" ]; then
        CURRENT_PODSPEC=$MACOS_PODSPEC
282 283 284
    fi
}

285
podOperations()
286
{
287
    if [ "$TEST_MODE" = "yes" ]; then
288 289 290
        startPodTesting
    else
        podDeploy
291
        log "Info" "Removing distribution package ${DISTRIBUTION_PACKAGE} and build directory ${TARGET}-binary."
292 293 294 295
        rm ${DISTRIBUTION_PACKAGE}
        rm -rf ${TARGET}-binary
    fi
}
Soomin Lee's avatar
Soomin Lee committed
296 297 298 299
##################
# Command Center #
##################

300 301 302 303 304 305
# Currently, mobile and tv cannot be deployed at the same time.
if [ "$DEPLOY_MOBILEVLCKIT" = "yes" ] && [ "$DEPLOY_TVVLCKIT" = "yes" ]; then
    log "Error" "Cannot depoy MobileVLCKit and TVVLCKit at the same time!"
    exit 1
fi

Soomin Lee's avatar
Soomin Lee committed
306 307 308 309
if [ "$CLEAN" = "yes" ]; then
    clean
fi

310
# Used to send parameter to the other scripts.
Soomin Lee's avatar
Soomin Lee committed
311 312 313 314 315
options=""
if [ "$DEPLOY_MOBILEVLCKIT" = "yes" ]; then
    options="-m"
elif [ "$DEPLOY_TVVLCKIT" = "yes" ]; then
    options="-t"
316 317
elif [ "$DEPLOY_MACOSVLCKIT" = "yes" ]; then
    options="-x"
Soomin Lee's avatar
Soomin Lee committed
318 319
fi

320
UPLOAD_URL=${STABLE_UPLOAD_URL}
Soomin Lee's avatar
Soomin Lee committed
321

322
spushd "$ROOT_DIR"
323
    buildMobileVLCKit $options
324
    setCurrentPodspec
Soomin Lee's avatar
Soomin Lee committed
325 326 327
    packageBuild $options
    renamePackage $options
    getSHA
328 329 330
    # Note: Disable uploading and podoperations for now.
    #uploadPackage
    #podOperations
331
spopd #ROOT_DIR