forked from hasura/ci-info-hs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f8b1da3
commit d593f91
Showing
3 changed files
with
92 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,51 @@ | ||
{-# LANGUAGE OverloadedStrings #-} | ||
{-# LANGUAGE TemplateHaskell #-} | ||
{-# LANGUAGE TemplateHaskell #-} | ||
|
||
module CI ( Types.CI(..), isCI, getCI ) where | ||
module CI (Types.CI(..), isCI, getCI) where | ||
|
||
import CI.TH ( getVendors ) | ||
import CI.TH (getVendors) | ||
import qualified CI.Types as Types | ||
|
||
import Control.Arrow ( (***) ) | ||
|
||
import Data.Bool ( bool ) | ||
import Data.Foldable ( find ) | ||
import Control.Arrow ((***)) | ||
import Data.Bool (bool) | ||
import Data.Foldable (find) | ||
import qualified Data.HashMap.Strict as HashMap | ||
import Data.Maybe ( isJust ) | ||
import Data.Maybe (isJust) | ||
import qualified Data.Text as T | ||
|
||
import System.Environment ( getEnvironment ) | ||
import System.Environment (getEnvironment) | ||
|
||
vendors :: [Types.Vendor] | ||
vendors = $(getVendors) | ||
|
||
getCI :: IO (Maybe Types.CI) | ||
getCI = do | ||
env <- mkEnvMap <$> getEnvironment | ||
let maybeVendor = find (checkVendor env) vendors | ||
return $ case maybeVendor of | ||
Nothing -> bool Nothing (Just Types.CI_UNKNOWN_VENDOR) $ | ||
checkUnknownVendor env | ||
Just vendor -> Just $ Types.vendorConstant vendor | ||
env <- mkEnvMap <$> getEnvironment | ||
let maybeVendor = find (checkVendor env) vendors | ||
return | ||
$ case maybeVendor of | ||
Nothing -> bool Nothing (Just Types.CI_UNKNOWN_VENDOR) | ||
$ checkUnknownVendor env | ||
Just vendor -> Just $ Types.vendorConstant vendor | ||
where | ||
checkVendor env vendor = case Types.vendorEnv vendor of | ||
(Types.VendorEnvString text) -> HashMap.member text env | ||
(Types.VendorEnvList list) -> all (`HashMap.member` env) list | ||
(Types.VendorEnvObject hashMap) -> | ||
all (\(k, v) -> HashMap.lookup k env == Just v) $ | ||
HashMap.toList hashMap | ||
(Types.VendorEnvString text) -> HashMap.member text env | ||
(Types.VendorEnvList list) -> all (`HashMap.member` env) list | ||
(Types.VendorEnvObject hashMap) -> all | ||
(\(k, v) -> HashMap.lookup k env == Just v) | ||
$ HashMap.toList hashMap | ||
|
||
-- check vendor neutral environment variables | ||
checkUnknownVendor env = any (`HashMap.member` env) unknownVendorEnvVars | ||
|
||
unknownVendorEnvVars = | ||
map Types.EnvVarName | ||
[ "CI" -- Travis CI, CircleCI, Cirrus CI, Gitlab CI, Appveyor, CodeShip, dsari | ||
, "CONTINUOUS_INTEGRATION" -- Travis CI, Cirrus CI | ||
, "BUILD_NUMBER" -- Jenkins, TeamCity | ||
, "RUN_ID" -- TaskCluster, dsari | ||
] | ||
unknownVendorEnvVars = map | ||
Types.EnvVarName | ||
[ "CI" -- Travis CI, CircleCI, Cirrus CI, Gitlab CI, Appveyor, CodeShip, dsari | ||
, "CONTINUOUS_INTEGRATION" -- Travis CI, Cirrus CI | ||
, "BUILD_NUMBER" -- Jenkins, TeamCity | ||
, "RUN_ID" -- TaskCluster, dsari | ||
] | ||
|
||
mkEnvMap = HashMap.fromList | ||
. map (Types.EnvVarName . T.pack *** Types.EnvVarValue . T.pack) | ||
. map (Types.EnvVarName . T.pack *** Types.EnvVarValue . T.pack) | ||
|
||
isCI :: IO Bool | ||
isCI = isJust <$> getCI |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters