git.iko.soy/typeable/servant
on master help sign in
Merge pull request #120 from haskell-servant/jkarni/travis_retry

travis retry - for a less lame CI story!

commitdfa30e890c3357330373cb5bf988b41cf5e007cf authorAlp Mestanogullari <alpmestan@gmail.com> dateFri 12 Jun 2015, 15:35 (11 years ago) parentab19ea8bef0e88
3 files changed+33−4
scripts/lib/common.sh+24 scripts/test-all.sh+5−1 servant/test/Servant/API/ContentTypesSpec.hs+4−3
scripts/lib/common.sh+24
@@ -15,6 +15,7 @@ DRY_RUN=false
1515POSITION="none"
1616SOURCES_TXT="$( dirname $DIR)/sources.txt"
1717CABAL=${CABAL:-cabal}
18+TRAVIS=${TRAVIS:-false}
1819
1920declare -a SOURCES
2021readarray -t SOURCES < "$SOURCES_TXT"
@@ -29,3 +30,26 @@ versions_equal () {
2930 echo "versions of packages are not all the same!" && exit 1
3031 fi
3132}
33+
34+travis_retry() {
35+ # From
36+ # https://github.com/travis-ci/travis-build/blob/18bd04e965b9bfaa49cd6bdcd8dcb1513b8d2fcd/lib/travis/build/templates/header.sh
37+ local result=0
38+ local count=1
39+ while [ $count -le 3 ]; do
40+ [ $result -ne 0 ] && {
41+ echo -e "\n${ANSI_RED}The command \"$@\" failed. Retrying, $count of 3.${ANSI_RESET}\n" >&2
42+ }
43+ "$@"
44+ result=$?
45+ [ $result -eq 0 ] && break
46+ count=$(($count + 1))
47+ sleep 1
48+ done
49+
50+ [ $count -gt 3 ] && {
51+ echo -e "\n${ANSI_RED}The command \"$@\" failed 3 times.${ANSI_RESET}\n" >&2
52+ }
53+
54+ return $result
55+}
scripts/test-all.sh+5−1
@@ -24,7 +24,11 @@ prepare_sandbox () {
2424 for s in ${SOURCES[@]} ; do
2525 (cd "$s" && $CABAL sandbox init --sandbox=../.cabal-sandbox/ && $CABAL sandbox add-source .)
2626 done
27− $CABAL install --enable-tests ${SOURCES[@]}
27+ if $TRAVIS ; then
28+ travis_retry $CABAL install -v --enable-tests ${SOURCES[@]}
29+ else
30+ $CABAL install --enable-tests ${SOURCES[@]}
31+ fi
2832}
2933
3034test_each () {
servant/test/Servant/API/ContentTypesSpec.hs+4−3
@@ -12,8 +12,6 @@ import Data.Monoid
1212#endif
1313import Control.Arrow
1414import Data.Aeson
15−import Data.Aeson.Parser (jstring)
16−import Data.Attoparsec.ByteString (parseOnly)
1715import Data.Either
1816import Data.Function (on)
1917import Data.Proxy
@@ -164,11 +162,14 @@ spec = describe "Servant.API.ContentTypes" $ do
164162
165163 describe "eitherDecodeLenient" $ do
166164
165+ -- aeson >= 0.9 decodes top-level strings
166+#if MIN_VERSION_aeson(0,9,0)
167167 it "parses top-level strings" $ do
168168 let toMaybe = either (const Nothing) Just
169169 -- The Left messages differ, so convert to Maybe
170170 property $ \x -> toMaybe (eitherDecodeLenient x)
171− `shouldBe` toMaybe (parseOnly jstring $ cs x)
171+ `shouldBe` (decode x :: Maybe String)
172+#endif
172173
173174
174175data SomeData = SomeData { record1 :: String, record2 :: Int }