codecov-haskell 0.3.0 → 0.4.0.2
raw patch · 6 files changed
+75/−16 lines, 6 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- CHANGELOG.md +6/−0
- README.md +46/−1
- codecov-haskell.cabal +1/−1
- src/CodecovHaskellCmdLine.hs +3/−1
- src/CodecovHaskellMain.hs +19/−11
- src/Trace/Hpc/Codecov/Types.hs +0/−2
CHANGELOG.md view
@@ -1,3 +1,9 @@++[0.4.0.2](https://github.com/guillaume-nargeot/codcov-haskell/issues?q=milestone:v0.4.0.2+is:closed)+-----+* Introduce retry policy to http requests (issue #6)+* Add support for Jenkins-CI (issue #7)+* Add support for Circle-CI (issue #8)+ +[0.3.0](https://github.com/guillaume-nargeot/codcov-haskell/issues?q=milestone:v0.3.0+is:closed) ----- * Fix coverage result response reading (issue #5)
README.md view
@@ -3,7 +3,8 @@ codecov-haskell converts and sends Haskell projects hpc code coverage to [codecov.io](http://codecov.io/). -At the moment, only [Travis CI](http://travis-ci.org) has been tested, but codecov-haskell should be compatible with other CI services in the near future.+At the moment, [Travis CI](https://travis-ci.org), [Circle CI](https://circleci.com) and [Jenkins CI](https://jenkins-ci.org) have been tested,+but codecov-haskell should be compatible with other CI services in the near future. codecov-haskell is still under development and any contributions are welcome! @@ -39,6 +40,50 @@ after_script: - cabal sandbox init && cabal install codecov-haskell - .cabal-sandbox/bin/codecov-haskell [options] [test-suite-names]+```++## Circle CI++In your test section of your `circle.yml` add the following:+```yaml+test:+ pre:+ - cabal install codecov-haskell+ - cabal configure --enable-tests --enable-library-coverage+ - cabal build+ override:+ - cabal test+ post:+ - codecov-haskell [options] [test-suite-names]+```++If your build fails during the test phase with an error message starting by "hpc:", just replace the `cabal test` command by `run-cabal-test`, as in the following example:+```yaml+test:+ pre:+ - cabal install codecov-haskell+ - cabal configure --enable-tests --enable-library-coverage+ - cabal build+ override:+ - run-cabal-test+ post:+ - codecov-haskell [options] [test-suite-names]+```+ +## Jenkins CI+In your build script add the following commands:+```bash+cabal install codecov-haskell+cabal configure --enable-tests --enable-library-coverage && cabal build && cabal test+codecov-haskell [options] [test-suite-names]+```++If your build fails during the test phase with an error message starting by "hpc:", just replace the `cabal test` command by `run-cabal-test`, as in the following example:+```bash+cabal install codecov-haskell+cabal configure --enable-tests --enable-library-coverage && cabal build+run-cabal-test [options] [cabal-test-options]+codecov-haskell [options] [test-suite-names] ``` ## The run-cabal-test command
codecov-haskell.cabal view
@@ -1,5 +1,5 @@ name: codecov-haskell-version: 0.3.0+version: 0.4.0.2 synopsis: Codecov.io support for Haskell. description: This utility converts and sends Haskell projects hpc code coverage to
src/CodecovHaskellCmdLine.hs view
@@ -9,6 +9,7 @@ data CodecovHaskellArgs = CmdMain { token :: Maybe String+ , accessToken :: Maybe String , excludeDirs :: [String] , testSuites :: [String] , displayReport :: Bool@@ -18,7 +19,8 @@ codecovHaskellArgs :: CodecovHaskellArgs codecovHaskellArgs = CmdMain- { token = Nothing &= explicit &= typDir &= name "token" &= help "Codecov token for this repository"+ { token = Nothing &= explicit &= typDir &= name "token" &= help "Codecov upload token for this repository"+ , accessToken = Nothing &= explicit &= typDir &= name "access-token" &= help "Codecov access token to retrieve reports for private repos" , excludeDirs = [] &= explicit &= typDir &= name "exclude-dir" &= help "Exclude sources files under the matching directory from the coverage report" , displayReport = False &= explicit &= name "display-report" &= help "Display the json code coverage report that will be sent to codecov.io" , printResponse = False &= explicit &= name "print-response" &= help "Prints the json reponse received from codecov.io"
src/CodecovHaskellMain.hs view
@@ -16,22 +16,28 @@ import Trace.Hpc.Codecov.Curl import Trace.Hpc.Codecov.Util -baseUrlApiV1 :: String-baseUrlApiV1 = "https://codecov.io/upload/v1"+baseUrlApiV2 :: String+baseUrlApiV2 = "https://codecov.io/upload/v2" -getUrlApiV1 :: IO String-getUrlApiV1 = do+getUrlApiV2 :: IO String+getUrlApiV2 = do env <- getEnvironment case snd <$> find (isJust . flip lookup env . fst) ciEnvVars of Just ((idParamName, idParamEnvVar), commitEnvVar, branchEnvVar) -> do idParamValue <- getEnv idParamEnvVar commit <- getEnv commitEnvVar branch <- getEnv branchEnvVar- return $ baseUrlApiV1 ++ "?" ++ idParamName ++ "=" ++ idParamValue ++ "&commit=" ++ commit ++ "&branch=" ++ branch+ return $ baseUrlApiV2 ++ "?" ++ idParamName ++ "=" ++ idParamValue ++ "&commit=" ++ commit ++ "&branch=" ++ branch _ -> error "Unsupported CI service." where ciEnvVars = [- ("TRAVIS", (("travis_job_id", "TRAVIS_JOB_ID"), "TRAVIS_COMMIT", "TRAVIS_BRANCH"))]+ ("TRAVIS", (("job", "TRAVIS_JOB_ID"), "TRAVIS_COMMIT", "TRAVIS_BRANCH")),+ ("JENKINS_HOME", (("job", "BUILD_NUMBER"), "GIT_COMMIT", "GIT_BRANCH")),+ ("CIRCLECI", (("job", "CIRCLE_BUILD_NUM"), "CIRCLE_SHA1", "CIRCLE_BRANCH"))] +getUrlWithToken :: String -> String -> Maybe String -> IO String+getUrlWithToken apiUrl _ Nothing = return apiUrl+getUrlWithToken apiUrl param (Just t) = return $ apiUrl ++ "&" ++ param ++ "=" ++ t+ getConfig :: CodecovHaskellArgs -> Maybe Config getConfig cha = Config (excludeDirs cha) <$> listToMaybe (testSuites cha) @@ -44,14 +50,16 @@ codecovJson <- generateCodecovFromTix config when (displayReport cha) $ BSL.putStrLn $ encode codecovJson unless (dontSend cha) $ do- apiUrl <- getUrlApiV1- response <- postJson (BSL.unpack $ encode codecovJson) apiUrl (printResponse cha)+ apiUrl <- getUrlApiV2+ fullUrl <- getUrlWithToken apiUrl "token" (token cha)+ response <- postJson (BSL.unpack $ encode codecovJson) fullUrl (printResponse cha) case response of- PostSuccess url waitUrl -> do- putStrLn ("URL: " ++ url)+ PostSuccess url _ -> do+ responseUrl <- getUrlWithToken url "access_token" (accessToken cha)+ putStrLn ("URL: " ++ responseUrl) -- wait 10 seconds until the page is available threadDelay (10 * 1000000)- coverageResult <- readCoverageResult waitUrl (printResponse cha)+ coverageResult <- readCoverageResult responseUrl (printResponse cha) case coverageResult of Just totalCoverage -> putStrLn ("Coverage: " ++ totalCoverage) >> exitSuccess Nothing -> putStrLn "Failed to read total coverage" >> exitSuccess
src/Trace/Hpc/Codecov/Types.hs view
@@ -1,5 +1,3 @@-{-# LANGUAGE DeriveDataTypeable #-}- -- | -- Module: Trace.Hpc.Codecov.Types -- Copyright: (c) 2014 Guillaume Nargeot