buildAndDeployFrameworks.sh 7.25 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
TEST_MODE=no
Soomin Lee's avatar
Soomin Lee committed
9 10

BUILD_MOBILEVLCKIT="./buildMobileVLCKit.sh -vf"
11
CREATE_DISTRIBUTION_PACKAGE="./create-distributable-package.sh"
12
STABLE_UPLOAD_URL="https://download.videolan.org/cocoapods/unstable/"
13 14
MOBILE_PODSPEC="MobileVLCKit-unstable.podspec"
TV_PODSPEC="TVVLCKit-unstable.podspec"
15

16 17
# 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
18 19 20 21

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

OPTIONS
    -d      Disable cleaning of build directory
    -m      Deploy MobileVLCKit
    -t      Deploy TVVLCKit
28
    -l      Start test for build phases
Soomin Lee's avatar
Soomin Lee committed
29 30 31
EOF
}

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

59 60
VERSION=""
VERSION_DELIMITER="3.0.0a"
61
ROOT_DIR="$(dirname "$(pwd)")"
Soomin Lee's avatar
Soomin Lee committed
62 63 64 65 66
UPLOAD_URL=""
VLC_HASH=""
VLCKIT_HASH=""
DISTRIBUTION_PACKAGE=""
DISTRIBUTION_PACKAGE_SHA=""
67
TARGET=""
Soomin Lee's avatar
Soomin Lee committed
68 69 70 71 72 73 74

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

spushd()
{
75
    pushd $1 2>&1> /dev/null
Soomin Lee's avatar
Soomin Lee committed
76 77 78 79 80 81 82 83 84
}

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

log()
{
85 86 87 88
    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
89 90 91 92 93 94 95 96 97 98
    local color=$green
    local msgType=$1

    if [ "$1" = "Warning" ]; then
        color=$orange
        msgType="Warning"
    elif [ "$1" = "Error" ]; then
        color=$red
        msgType="Error"
    fi
99
    echo -e "[${color}${msgType}${normal}] $2"
Soomin Lee's avatar
Soomin Lee committed
100 101 102 103
}

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

buildMobileVLCKit()
{
    log "Info" "Staring MobileVLCKit build..."
    if ! $BUILD_MOBILEVLCKIT; then
117
        log "Error" "MobileVLCKit build failed"
118
        rm -fr "build/"
Soomin Lee's avatar
Soomin Lee committed
119 120 121 122 123 124 125
        exit 1
    fi
    log "Info" "MobileVLCKit build finished!"
}

getVLCHashes()
{
126
    VLCKIT_HASH=$(git rev-parse --short HEAD)
Soomin Lee's avatar
Soomin Lee committed
127
    spushd "libvlc/vlc"
128
        VLC_HASH=$(git rev-parse --short HEAD)
Soomin Lee's avatar
Soomin Lee committed
129 130 131 132 133 134
    spopd #libvlc/vlc
}

renamePackage()
{
    if [ "$1" = "-m" ]; then
135
        TARGET="MobileVLCKit"
136
    elif [ "$1" = "-t" ]; then
137
        TARGET="TVVLCKit"
Soomin Lee's avatar
Soomin Lee committed
138 139 140
    fi
    getVLCHashes

141

142
    local packageName="${TARGET}-REPLACEWITHVERSION.tar.xz"
143

Soomin Lee's avatar
Soomin Lee committed
144
    if [ -f $packageName ]; then
145
        DISTRIBUTION_PACKAGE="${TARGET}-${VERSION}-${VLCKIT_HASH}-${VLC_HASH}.tar.xz"
146
        mv $packageName "$DISTRIBUTION_PACKAGE"
Soomin Lee's avatar
Soomin Lee committed
147 148 149 150 151 152 153
        log "Info" "Finished renaming package!"
    fi
}

packageBuild()
{
    spushd "Packaging"
154
        if ! $CREATE_DISTRIBUTION_PACKAGE "$1"; then
Soomin Lee's avatar
Soomin Lee committed
155 156 157 158 159 160 161 162 163
            log "Error" "Failed to package!"
            exit 1
        fi
    spopd #Packaging
}

getSHA()
{
    log "Info" "Getting SHA from distrubition package..."
164
    DISTRIBUTION_PACKAGE_SHA=$(shasum -a 256 "$DISTRIBUTION_PACKAGE" | cut -d " " -f 1 )
Soomin Lee's avatar
Soomin Lee committed
165 166
}

167
bumpPodspec()
Soomin Lee's avatar
Soomin Lee committed
168 169 170 171 172
{
    local podVersion="s.version   = '${VERSION}'"
    local uploadURL=":http => '${UPLOAD_URL}${DISTRIBUTION_PACKAGE}'"
    local podSHA=":sha256 => '${DISTRIBUTION_PACKAGE_SHA}'"

173 174 175
    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
176 177
}

178 179
gitCommit()
{
180
    local podspec="$1"
181

182
    git add "$podspec"
183
    git commit -m "${podspec}: Update version to ${VERSION}"
184 185
}

186
startPodTesting()
187 188 189 190 191 192 193 194 195 196 197 198 199
{
    # 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}
200
   rm -rf ${TARGET}-binary
201 202 203
   log "Warning" "All files generated during tests have been removed."
}

Soomin Lee's avatar
Soomin Lee committed
204 205
podDeploy()
{
206
   log "Info" "Starting podspec operations..."
Soomin Lee's avatar
Soomin Lee committed
207
    spushd "Packaging/podspecs"
208 209 210
        if bumpPodspec $CURRENT_PODSPEC && \
           pod spec lint --verbose $CURRENT_PODSPEC && \
           pod trunk push $CURRENT_PODSPEC && \
211
           gitCommit $CURRENT_PODSPEC; then
212 213
            log "Info" "Podpsec operations successfully finished!"
        else
214
            git checkout $CURRENT_PODSPEC
215
            log "Error" "Podspec operations failed."
216
        fi
217
    spopd #Packaging/podspecs
Soomin Lee's avatar
Soomin Lee committed
218 219 220 221
}

checkIfExistOnRemote()
{
222
    if ! curl --head --silent "$1" | head -n 1 | grep -q 404; then
Soomin Lee's avatar
Soomin Lee committed
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237
        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

238
    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
239
    do
240
        printf '\r'
Soomin Lee's avatar
Soomin Lee committed
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259
        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
}

260 261 262 263
getVersion()
{
    spushd "Packaging/podspecs"
        # Basing on the version of the MobileVLCKit podspec to retreive old version
264
        local oldVersion=$(grep s.version $MOBILE_PODSPEC | cut -d "'" -f 2)
265 266 267 268 269

        VERSION=$(echo $oldVersion | awk -F$VERSION_DELIMITER -v OFS=$VERSION_DELIMITER 'NF==1{print ++$NF}; NF>1{$NF=sprintf("%0*d", length($NF), ($NF+1)); print}')
    spopd #Packaging/podspecs
}

270 271 272 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
    fi
}

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

if [ "$CLEAN" = "yes" ]; then
    clean
fi

299
# Used to send parameter to the other scripts.
Soomin Lee's avatar
Soomin Lee committed
300 301 302 303 304 305 306
options=""
if [ "$DEPLOY_MOBILEVLCKIT" = "yes" ]; then
    options="-m"
elif [ "$DEPLOY_TVVLCKIT" = "yes" ]; then
    options="-t"
fi

307
UPLOAD_URL=${STABLE_UPLOAD_URL}
Soomin Lee's avatar
Soomin Lee committed
308

309
spushd "$ROOT_DIR"
Soomin Lee's avatar
Soomin Lee committed
310
    buildMobileVLCKit
311
    setCurrentPodspec
312
    getVersion
Soomin Lee's avatar
Soomin Lee committed
313 314 315 316
    packageBuild $options
    renamePackage $options
    getSHA
    uploadPackage
317
    podOperations
318
spopd #ROOT_DIR