deployVLCKit.sh 5.82 KB
Newer Older
Carola Nitz's avatar
Carola Nitz committed
1
#!/usr/bin/env bash
Soomin Lee's avatar
Soomin Lee committed
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

set -e

ARCH="all"
CLEAN=yes
VERBOSE=no
DEPLOY_MOBILEVLCKIT=no
DEPLOY_TVVLCKIT=no

BUILD_MOBILEVLCKIT="./buildMobileVLCKit.sh -vf"
CREATE_DISTRIBUTION_PACKAGE="./create-distributable-package.sh -z"
STABLE_UPLOAD_URL="https://download.videolan.org/cocoapods/prod/"

usage()
{
cat << EOF
usage: $0 [options] version

OPTIONS
    -d      Disable cleaning of build directory
    -m      Deploy MobileVLCKit
    -t      Deploy TVVLCKit
    -a      Build *VLCKit* for specific arch (all|i386|x86_64|armv7|armv7s|aarch64)
EOF
}

# Note: Need argument error handling on: version option, the options are ignored
29
while getopts "hdmta:" OPTION
Soomin Lee's avatar
Soomin Lee committed
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 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
do
     case $OPTION in
         h)
            usage
            exit 1
            ;;
         d)
            CLEAN=no
            ;;
         m)
            DEPLOY_MOBILEVLCKIT=yes
            ;;
         t)
            DEPLOY_TVVLCKIT=yes
            ;;
         a)
            ARCH=$OPTARG
            ;;
         \?)
            usage
            exit 1
            ;;
     esac
done
shift $(($OPTIND-1))

VERSION=$1
if [[ -z $VERSION ]]; then
    echo "Please specify a version."
    exit 1
fi

ROOT_DIR="`dirname $(pwd)`"
UPLOAD_URL=""
VLC_HASH=""
VLCKIT_HASH=""
DISTRIBUTION_PACKAGE=""
DISTRIBUTION_PACKAGE_SHA=""

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

spushd()
{
    pushd "$1" 2>&1> /dev/null
}

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

log()
{
    local green="\033[1;32m"
    local orange="\033[1;91m"
    local red="\033[1;31m"
    local normal="\033[0m"
    local color=$green
    local msgType=$1

    if [ "$1" = "Warning" ]; then
        color=$orange
        msgType="Warning"
    elif [ "$1" = "Error" ]; then
        color=$red
        msgType="Error"
    fi
    echo "[${color}${msgType}${normal}] $2"
}

getActualArch()
{
    if [ "$1" = "aarch64" ]; then
        echo "arm64"
    else
        echo "$1"
    fi
}

clean()
{
    log "Info" "Starting the build purge..."
    pwd
    if [ -d "build" ]; then
        rm -rf "$ROOT_DIR/build"
    else
        log "warning" "Build directory not found!"
    fi
    log "Info" "Build directory cleaned"
}

buildMobileVLCKit()
{
    log "Info" "Staring MobileVLCKit build..."
    if ! $BUILD_MOBILEVLCKIT; then
        log "error" "MobileVLCKit build failed"
        exit 1
    fi
    log "Info" "MobileVLCKit build finished!"
}

getVLCHashes()
{
    VLC_HASH=""
    VLCKIT_HASH=`git rev-parse --short HEAD`

    spushd "libvlc/vlc"
        VLC_HASH=`git rev-parse --short HEAD`
    spopd #libvlc/vlc
}

renamePackage()
{
    local target=""

    if [ "$1" = "-m" ]; then
        target="MobileVLCKit"
    else
        target="TVVLCKit"
    fi

    getVLCHashes

    local packageName="${target}-REPLACEWITHVERSION.zip"
    # git rev-parse --short HEAD in vlckit et vlc
    if [ -f $packageName ]; then
158
        DISTRIBUTION_PACKAGE="${target}-${VERSION}-${VLCKIT_HASH}-${VLC_HASH}.zip"
Soomin Lee's avatar
Soomin Lee committed
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
        mv $packageName $DISTRIBUTION_PACKAGE
        log "Info" "Finished renaming package!"
    fi
}

packageBuild()
{
    spushd "Packaging"
        if ! $CREATE_DISTRIBUTION_PACKAGE $1; then
            log "Error" "Failed to package!"
            exit 1
        fi
    spopd #Packaging
}

getSHA()
{
    log "Info" "Getting SHA from distrubition package..."
    DISTRIBUTION_PACKAGE_SHA=`shasum -a 256 $DISTRIBUTION_PACKAGE | cut -d " " -f 1 `
}

bumpPodSpec()
{
    local podVersion="s.version   = '${VERSION}'"
    local uploadURL=":http => '${UPLOAD_URL}${DISTRIBUTION_PACKAGE}'"
    local podSHA=":sha256 => '${DISTRIBUTION_PACKAGE_SHA}'"

    # NOTE: sed -i '' because macOS
    `sed -i '' 's#.*s.version.*#'"  ${podVersion}"'#' $1`
    `sed -i '' 's#.*:http.*#'"    ${uploadURL}",'#' $1`
    `sed -i '' 's#.*sha256.*#'"    ${podSHA}"'#' $1`
}

192 193 194 195 196 197 198 199 200

gitCommit()
{
    local podspec=$1

    git add $podspec
    git commit -m "Update podspecs"
}

Soomin Lee's avatar
Soomin Lee committed
201 202 203 204 205
podDeploy()
{
    local podspec=""

    if [ "$DEPLOY_MOBILEVLCKIT" = "yes" ]; then
206
        podspec="MobileVLCKit.podspec"
Soomin Lee's avatar
Soomin Lee committed
207 208 209 210 211 212 213 214 215
    else
        podspec="TVVLCKit.podspec"
    fi

    spushd "Packaging/podspecs"
        log "Info" "Starting podspec update..."
        bumpPodSpec $podspec
        log "Info" "Starting pod spec lint..."
        pod spec lint $podspec
216 217 218
        log "Info" "Starting pod trunk push..."
        pod trunk push $podspec
        gitCommit $podspec
Soomin Lee's avatar
Soomin Lee committed
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276
    spopd #Packaging/podspecs
}

checkIfExistOnRemote()
{
    if ! `curl --head --silent "$1" | head -n 1 | grep -q 404`; then
        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

    while read  -n 1 -p "The package is ready please upload it to "${UPLOAD_URL}", press a key to continue when uploaded [y,a,r]: " response
    do
        echo '\r'
        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
}

##################
# Command Center #
##################

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

options=""
if [ "$DEPLOY_MOBILEVLCKIT" = "yes" ]; then
    options="-m"
elif [ "$DEPLOY_TVVLCKIT" = "yes" ]; then
    options="-t"
fi

277
UPLOAD_URL=${STABLE_UPLOAD_URL}
Soomin Lee's avatar
Soomin Lee committed
278 279 280 281 282 283 284 285 286 287 288


spushd $ROOT_DIR
    # Note: the current packaging script is building vlckit(s) if not found.
    buildMobileVLCKit
    packageBuild $options
    renamePackage $options
    getSHA
    uploadPackage
    podDeploy

289
spopd #ROOT_DIR