WIP automatic release
[openjpeg.git] / tools / travis-ci / run.sh
index eaa8d45ae39b92baaea53c4e52983a3dfee3648b..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
@@ -24,9 +19,9 @@ set -o pipefail  ## Fail on error in pipe
 function opjpath ()
 {
        if [ "${OPJ_CI_IS_CYGWIN:-}" == "1" ]; then
-               cygpath -m "$1"
+               cygpath $1 "$2"
        else
-               echo "$1"
+               echo "$2"
        fi
 }
 
@@ -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,17 +176,50 @@ 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=${OPJ_SOURCE_DIR}
+export OPJ_SOURCE_DIR=$(opjpath -m ${OPJ_SOURCE_DIR})
+export OPJ_BINARY_DIR=$(opjpath -m ${PWD}/build)
 export OPJ_BUILD_CONFIGURATION=${OPJ_CI_BUILD_CONFIGURATION}
 export OPJ_DO_SUBMIT=${OPJ_DO_SUBMIT}
 
-ctest -S $(opjpath ${OPJ_SOURCE_DIR}/tools/ctest_scripts/travis-ci.cmake) -V || true
+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
 
+# 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
 
 echo "
@@ -217,11 +270,11 @@ if [ "${OPJ_CI_SKIP_TESTS:-}" != "1" ]; then
                        awk -F: '{ print $2 }' ${OPJ_FAILEDTEST_LOG} > failures.txt
                        while read FAILEDTEST; do
                                # Start with common errors
-                               if grep -x "${FAILEDTEST}" ${OPJ_SOURCE_DIR}/tools/travis-ci/knownfailures-all.txt > /dev/null; then
+                               if grep -x "${FAILEDTEST}" $(opjpath -u ${OPJ_SOURCE_DIR})/tools/travis-ci/knownfailures-all.txt > /dev/null; then
                                        continue
                                fi
-                               if [ -f ${OPJ_SOURCE_DIR}/tools/travis-ci/knownfailures-${OPJ_BUILDNAME_TEST}.txt ]; then
-                                       if grep -x "${FAILEDTEST}" ${OPJ_SOURCE_DIR}/tools/travis-ci/knownfailures-${OPJ_BUILDNAME_TEST}.txt > /dev/null; then
+                               if [ -f $(opjpath -u ${OPJ_SOURCE_DIR})/tools/travis-ci/knownfailures-${OPJ_BUILDNAME_TEST}.txt ]; then
+                                       if grep -x "${FAILEDTEST}" $(opjpath -u ${OPJ_SOURCE_DIR})/tools/travis-ci/knownfailures-${OPJ_BUILDNAME_TEST}.txt > /dev/null; then
                                                continue
                                        fi
                                fi