WIP automatic release
[openjpeg.git] / tools / travis-ci / run.sh
index ba4e6da32612da0da19efa2474d5b9051c3da8db..782622b505c855eb5ff1ff02ee9e5bd3f2d1d32a 100755 (executable)
@@ -8,13 +8,8 @@ case ${MACHTYPE} in
        *) ;;
 esac
 
-if [ "${OPJ_CI_IS_CYGWIN:-}" == "1" ]; then
-       # Hack for appveyor
-       if ! which wget; then
-               # PATH is not yet set up
-               export PATH=$PATH:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
-       fi
-fi
+# Hack for appveyor to get GNU find in path before windows one.
+export PATH=$(dirname ${BASH}):$PATH
 
 # Set-up some bash options
 set -o nounset   ## set -u : exit the script if you try to use an uninitialised variable
@@ -50,6 +45,12 @@ if [ "${TRAVIS_REPO_SLUG:-}" != "" ]; then
        if [ "${OPJ_OWNER}" == "uclouvain" ]; then
                OPJ_DO_SUBMIT=1
        fi
+elif [ "${APPVEYOR_REPO_NAME:-}" != "" ]; then
+       OPJ_OWNER=$(echo "${APPVEYOR_REPO_NAME}" | sed 's/\(^.*\)\/.*/\1/')
+       OPJ_SITE="${OPJ_OWNER}.appveyor.com"
+       if [ "${OPJ_OWNER}" == "uclouvain" ]; then
+               OPJ_DO_SUBMIT=1
+       fi
 else
        OPJ_SITE="$(hostname)"
 fi
@@ -67,7 +68,9 @@ if [ "${TRAVIS_OS_NAME:-}" == "" ]; then
                fi
        elif uname -s | grep -i CYGWIN &> /dev/null; then
                TRAVIS_OS_NAME=windows
-       elif uname -s | grep -i MINGW32 &> /dev/null; then
+       elif uname -s | grep -i MINGW &> /dev/null; then
+               TRAVIS_OS_NAME=windows
+       elif [ "${APPVEYOR:-}" == "True" ]; then
                TRAVIS_OS_NAME=windows
        else
                echo "Failed to guess OS"; exit 1
@@ -100,7 +103,24 @@ elif [ "${TRAVIS_OS_NAME}" == "linux" ]; then
        fi
 elif [ "${TRAVIS_OS_NAME}" == "windows" ]; then
        OPJ_OS_NAME=windows
-       OPJ_CC_VERSION=vs2015
+       if which cl > /dev/null; then
+               OPJ_CL_VERSION=$(cl 2>&1 | grep Version | sed 's/.*Version \([0-9]*\).*/\1/')
+               if [ ${OPJ_CL_VERSION} -eq 19 ]; then
+                       OPJ_CC_VERSION=vs2015
+               elif [ ${OPJ_CL_VERSION} -eq 18 ]; then
+                       OPJ_CC_VERSION=vs2013
+               elif [ ${OPJ_CL_VERSION} -eq 17 ]; then
+                       OPJ_CC_VERSION=vs2012
+               elif [ ${OPJ_CL_VERSION} -eq 16 ]; then
+                       OPJ_CC_VERSION=vs2010
+               elif [ ${OPJ_CL_VERSION} -eq 15 ]; then
+                       OPJ_CC_VERSION=vs2008
+               elif [ ${OPJ_CL_VERSION} -eq 14 ]; then
+                       OPJ_CC_VERSION=vs2005
+               else
+                       OPJ_CC_VERSION=vs????
+               fi
+       fi
 else
        echo "OS not supported: ${TRAVIS_OS_NAME}"; exit 1
 fi
@@ -156,6 +176,7 @@ set -x
 # travis-ci doesn't dump cmake version in system info, let's print it 
 cmake --version
 
+export TRAVIS_OS_NAME=${TRAVIS_OS_NAME}
 export OPJ_SITE=${OPJ_SITE}
 export OPJ_BUILDNAME=${OPJ_BUILDNAME}
 export OPJ_SOURCE_DIR=$(opjpath -m ${OPJ_SOURCE_DIR})
@@ -166,7 +187,38 @@ export OPJ_DO_SUBMIT=${OPJ_DO_SUBMIT}
 ctest -S ${OPJ_SOURCE_DIR}/tools/ctest_scripts/travis-ci.cmake -V || true
 # ctest will exit with various error codes depending on version.
 # ignore ctest exit code & parse this ourselves
-#set +x
+set +x
+
+# Deployment if needed
+#---------------------
+if [ "${TRAVIS_TAG:-}" != "" ]; then
+               OPJ_TAG_NAME=${TRAVIS_TAG}
+       elif [ "${APPVEYOR_REPO_TAG:-}" == "true" ]; then
+               OPJ_TAG_NAME=${APPVEYOR_REPO_TAG_NAME}
+       else
+               OPJ_TAG_NAME=""
+       fi
+if [ "${OPJ_CI_INCLUDE_IF_DEPLOY:-}" == "1" ] && [ "${OPJ_TAG_NAME:-}" != "" ]; then
+#if [ "${OPJ_CI_INCLUDE_IF_DEPLOY:-}" == "1" ]; then
+       OPJ_CI_DEPLOY=1         # unused for now
+       OPJ_CUR_DIR=${PWD}
+       if [ "${TRAVIS_OS_NAME:-}" == "linux" ]; then
+               OPJ_PACK_GENERATOR="TGZ" # ZIP generator currently segfaults on linux
+       else
+               OPJ_PACK_GENERATOR="ZIP"
+       fi
+       OPJ_PACK_NAME="openjpeg-${OPJ_TAG_NAME}-${TRAVIS_OS_NAME}-${OPJ_CI_ARCH}"
+       cd ${OPJ_BINARY_DIR}
+       cmake -D CPACK_GENERATOR:STRING=${OPJ_PACK_GENERATOR} -D CPACK_PACKAGE_FILE_NAME:STRING=${OPJ_PACK_NAME} ${OPJ_SOURCE_DIR}
+       cd ${OPJ_CUR_DIR}
+       cmake --build ${OPJ_BINARY_DIR} --target package
+       echo "ready to deploy $(ls ${OPJ_BINARY_DIR}/${OPJ_PACK_NAME}*) to GitHub releases"
+       if [ "${APPVEYOR_REPO_TAG:-}" == "true" ]; then
+               appveyor PushArtifact "${OPJ_BINARY_DIR}/${OPJ_PACK_NAME}.zip"
+       fi
+else
+       OPJ_CI_DEPLOY=0
+fi
 
 # let's parse configure/build/tests for failure
 
@@ -175,9 +227,6 @@ Parsing logs for failures
 "
 OPJ_CI_RESULT=0
 
-ls -l build
-ls -l build/Testing
-
 # 1st configure step
 OPJ_CONFIGURE_XML=$(find build -path 'build/Testing/*' -name 'Configure.xml')
 if [ ! -f "${OPJ_CONFIGURE_XML}" ]; then