chore(tooling): import ci-info-hs into monorepo

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/9383
Co-authored-by: Shahidh K Muhammed <4124733+shahidhk@users.noreply.github.com>
Co-authored-by: Ajeet D'Souza <1777663+ajeetdsouza@users.noreply.github.com>
Co-authored-by: Brandon Simmons <210815+jberryman@users.noreply.github.com>
Co-authored-by: Vamshi Surabhi <6562944+0x777@users.noreply.github.com>
Co-authored-by: Auke Booij <164426+abooij@users.noreply.github.com>
Co-authored-by: Matthew Pickering <1216657+mpickering@users.noreply.github.com>
Co-authored-by: Antoine Leblanc <1618949+nicuveo@users.noreply.github.com>
GitOrigin-RevId: a7a210e2237f5adc63302b18403616c7c0aa39ca
This commit is contained in:
kodiakhq[bot] 2023-06-01 12:50:06 +00:00 committed by hasura-bot
parent af6795da93
commit 34e172d576
14 changed files with 646 additions and 6 deletions

View File

@ -51,11 +51,6 @@ source-repository-package
location: https://github.com/hasura/kriti-lang.git
tag: c8fd863d359876af3a0fce47db8a5393dc556667
source-repository-package
type: git
location: https://github.com/hasura/ci-info-hs.git
tag: be578a01979fc95137cc2c84827f9fafb99df60f
-- This is an unrelesaed version of "odbc"
source-repository-package
type: git

View File

@ -68,7 +68,6 @@ constraints: any.Cabal ==3.6.3.0,
any.case-insensitive ==1.2.1.0,
any.cereal ==0.5.8.3,
any.charset ==0.3.9,
any.ci-info ==0.1.0.0,
any.clock ==0.8.3,
any.cmdargs ==0.10.21,
any.colour ==2.3.6,

22
server/lib/ci-info/.gitignore vendored Normal file
View File

@ -0,0 +1,22 @@
dist
dist-*
cabal-dev
*.o
*.hi
*.chi
*.chs.h
*.dyn_o
*.dyn_hi
.hpc
.hsenv
.cabal-sandbox/
cabal.sandbox.config
*.prof
*.aux
*.hp
*.eventlog
.stack-work/
cabal.project.local
cabal.project.local~
.HTF/
.ghc.environment.*

View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2019 Hasura
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -0,0 +1,19 @@
# ci-info-hs
Checks if the current environment is a Continuous Integration server.
This is a Haskell port of [watson/ci-info](https://github.com/watson/ci-info).
## Usage
Check if the current environment is a CI server:
```haskell
isCI :: IO Bool
```
Get the name of the CI vendor. Returns `Nothing` if no CI could be detected. Returns `Just CI_UNKNOWN_VENDOR` if a CI was detected, but the vendor name could not be determined:
```haskell
getCI :: IO (Maybe CI)
```

View File

@ -0,0 +1,3 @@
import Distribution.Simple
main = defaultMain

View File

@ -0,0 +1,64 @@
constraints: any.aeson ==1.5.5.1,
aeson -bytestring-builder -cffi -developer -fast,
any.aeson-casing ==0.2.0.0,
any.array ==0.5.4.0,
any.assoc ==1.0.2,
any.attoparsec ==0.13.2.4,
attoparsec -developer,
any.base ==4.14.1.0,
any.base-compat ==0.11.2,
any.base-compat-batteries ==0.11.2,
any.base-orphans ==0.8.4,
any.bifunctors ==5.5.10,
bifunctors +semigroups +tagged,
any.binary ==0.8.8.0,
any.bytestring ==0.10.10.0,
any.comonad ==5.0.8,
comonad +containers +distributive +indexed-traversable,
any.containers ==0.6.2.1,
any.data-fix ==0.3.0,
any.deepseq ==1.4.4.0,
any.distributive ==0.6.2.1,
distributive +semigroups +tagged,
any.dlist ==1.0,
dlist -werror,
any.ghc-boot-th ==8.10.2,
any.ghc-prim ==0.6.1,
any.hashable ==1.3.0.0,
hashable -examples +integer-gmp +sse2 -sse41,
any.indexed-traversable ==0.1.1,
any.integer-gmp ==1.0.3.0,
any.integer-logarithms ==1.0.3.1,
integer-logarithms -check-bounds +integer-gmp,
any.mtl ==2.2.2,
any.pretty ==1.1.3.6,
any.primitive ==0.7.1.0,
any.random ==1.2.0,
any.rts ==1.0,
any.scientific ==0.3.6.2,
scientific -bytestring-builder -integer-simple,
any.splitmix ==0.1.0.3,
splitmix -optimised-mixer,
any.strict ==0.4.0.1,
strict +assoc,
any.tagged ==0.8.6.1,
tagged +deepseq +transformers,
any.template-haskell ==2.16.0.0,
any.text ==1.2.3.2,
any.th-abstraction ==0.4.2.0,
any.th-lift ==0.8.2,
any.th-lift-instances ==0.1.18,
any.these ==1.1.1.1,
these +assoc,
any.time ==1.9.3,
any.time-compat ==1.9.5,
time-compat -old-locale,
any.transformers ==0.5.6.2,
any.transformers-compat ==0.6.6,
transformers-compat -five +five-three -four +generic-deriving +mtl -three -two,
any.unix ==2.7.2.2,
any.unordered-containers ==0.2.13.0,
unordered-containers -debug,
any.uuid-types ==1.0.3,
any.vector ==0.12.1.2,
vector +boundschecks -internalchecks -unsafechecks -wall

View File

@ -0,0 +1,57 @@
-- This file has been generated from package.yaml by hpack version 0.9.1.
--
-- see: https://github.com/sol/hpack
name: ci-info
version: 0.1.0.0
description: Please see the README on GitHub at <https://github.com/hasura/graphql-engine#readme>
homepage: https://github.com/hasura/graphql-engine#readme
bug-reports: https://github.com/hasura/graphql-engine/issues
author: Ajeet D'Souza
maintainer: build@hasura.io
copyright: 2019 Hasura Inc.
license: MIT
license-file: LICENSE
build-type: Simple
cabal-version: >= 1.10
extra-source-files:
README.md
res/vendors.json
source-repository head
type: git
location: https://github.com/hasura/
library
hs-source-dirs:
src
ghc-options:
-- Taken from https://medium.com/mercury-bank/enable-all-the-warnings-a0517bc081c3
-Weverything
-Wno-missing-exported-signatures
-Wno-missing-import-lists
-Wno-missed-specialisations
-Wno-all-missed-specialisations
-Wno-unsafe
-Wno-safe
-Wno-missing-local-signatures
-Wno-monomorphism-restriction
-Wno-missing-kind-signatures
-Wno-missing-safe-haskell-mode
build-depends:
base >= 4.7 && < 5
, aeson
, aeson-casing
, hashable
, template-haskell
, th-lift-instances
, text
, unordered-containers
exposed-modules:
CI
other-modules:
CI.TH
CI.Types
default-language: Haskell2010

View File

@ -0,0 +1,36 @@
name: ci-info
version: 0.1.0.0
github: "hasura/graphql-engine"
license: MIT
author: "Ajeet D'Souza"
maintainer: "build@hasura.io"
copyright: "2019 Hasura Inc."
extra-source-files:
- README.md
description: Please see the README on GitHub at <https://github.com/hasura/ci-info-hs#readme>
dependencies:
- base >= 4.7 && < 5
- aeson
- aeson-casing
- hashable
- template-haskell
- th-lift-instances
- text
- unordered-containers
ghc-options:
- -Wall
- -Wincomplete-uni-patterns
- -Wincomplete-record-updates
- -Wcompat
- -Widentities
- -Wredundant-constraints
- -Wmissing-export-lists
- -Wpartial-fields
library:
exposed-modules: CI
source-dirs: src

View File

@ -0,0 +1,159 @@
[
{
"name": "AppVeyor",
"constant": "APPVEYOR",
"env": "APPVEYOR",
"pr": "APPVEYOR_PULL_REQUEST_NUMBER"
},
{
"name": "Azure Pipelines",
"constant": "AZURE_PIPELINES",
"env": "SYSTEM_TEAMFOUNDATIONCOLLECTIONURI",
"pr": "SYSTEM_PULLREQUEST_PULLREQUESTID"
},
{
"name": "Bamboo",
"constant": "BAMBOO",
"env": "bamboo_planKey"
},
{
"name": "Bitbucket Pipelines",
"constant": "BITBUCKET",
"env": "BITBUCKET_COMMIT",
"pr": "BITBUCKET_PR_ID"
},
{
"name": "Bitrise",
"constant": "BITRISE",
"env": "BITRISE_IO",
"pr": "BITRISE_PULL_REQUEST"
},
{
"name": "Buddy",
"constant": "BUDDY",
"env": "BUDDY_WORKSPACE_ID",
"pr": "BUDDY_EXECUTION_PULL_REQUEST_ID"
},
{
"name": "Buildkite",
"constant": "BUILDKITE",
"env": "BUILDKITE",
"pr": { "env": "BUILDKITE_PULL_REQUEST", "ne": "false" }
},
{
"name": "CircleCI",
"constant": "CIRCLE",
"env": "CIRCLECI",
"pr": "CIRCLE_PULL_REQUEST"
},
{
"name": "Cirrus CI",
"constant": "CIRRUS",
"env": "CIRRUS_CI",
"pr": "CIRRUS_PR"
},
{
"name": "AWS CodeBuild",
"constant": "CODEBUILD",
"env": "CODEBUILD_BUILD_ARN"
},
{
"name": "Codeship",
"constant": "CODESHIP",
"env": { "CI_NAME": "codeship" }
},
{
"name": "Drone",
"constant": "DRONE",
"env": "DRONE",
"pr": { "DRONE_BUILD_EVENT": "pull_request" }
},
{
"name": "dsari",
"constant": "DSARI",
"env": "DSARI"
},
{
"name": "GitLab CI",
"constant": "GITLAB",
"env": "GITLAB_CI"
},
{
"name": "GoCD",
"constant": "GOCD",
"env": "GO_PIPELINE_LABEL"
},
{
"name": "Hudson",
"constant": "HUDSON",
"env": "HUDSON_URL"
},
{
"name": "Jenkins",
"constant": "JENKINS",
"env": ["JENKINS_URL", "BUILD_ID"],
"pr": { "any": ["ghprbPullId", "CHANGE_ID"] }
},
{
"name": "Magnum CI",
"constant": "MAGNUM",
"env": "MAGNUM"
},
{
"name": "Netlify CI",
"constant": "NETLIFY",
"env": "NETLIFY_BUILD_BASE",
"pr": { "env": "PULL_REQUEST", "ne": "false" }
},
{
"name": "Nevercode",
"constant": "NEVERCODE",
"env": "NEVERCODE",
"pr": { "env": "NEVERCODE_PULL_REQUEST", "ne": "false" }
},
{
"name": "Sail CI",
"constant": "SAIL",
"env": "SAILCI",
"pr": "SAIL_PULL_REQUEST_NUMBER"
},
{
"name": "Semaphore",
"constant": "SEMAPHORE",
"env": "SEMAPHORE",
"pr": "PULL_REQUEST_NUMBER"
},
{
"name": "Shippable",
"constant": "SHIPPABLE",
"env": "SHIPPABLE",
"pr": { "IS_PULL_REQUEST": "true" }
},
{
"name": "Solano CI",
"constant": "SOLANO",
"env": "TDDIUM",
"pr": "TDDIUM_PR_ID"
},
{
"name": "Strider CD",
"constant": "STRIDER",
"env": "STRIDER"
},
{
"name": "TaskCluster",
"constant": "TASKCLUSTER",
"env": ["TASK_ID", "RUN_ID"]
},
{
"name": "TeamCity",
"constant": "TEAMCITY",
"env": "TEAMCITY_VERSION"
},
{
"name": "Travis CI",
"constant": "TRAVIS",
"env": "TRAVIS",
"pr": { "env": "TRAVIS_PULL_REQUEST", "ne": "false" }
}
]

View File

@ -0,0 +1,62 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}
{-# HLINT ignore "avoid getEnvironment" #-}
module CI
( Types.CI (..),
isCI,
getCI,
)
where
import CI.TH (getVendors)
import qualified CI.Types as Types
import Control.Arrow ((***))
import Data.Bool (bool)
import Data.Foldable (find)
import qualified Data.HashMap.Strict as HashMap
import Data.Maybe (isJust)
import qualified Data.Text as T
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
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
-- 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
]
mkEnvMap =
HashMap.fromList
. map (Types.EnvVarName . T.pack *** Types.EnvVarValue . T.pack)
isCI :: IO Bool
isCI = isJust <$> getCI

View File

@ -0,0 +1,23 @@
{-# HLINT ignore "Use onLeft" #-}
module CI.TH
( getVendors,
)
where
import qualified CI.Types as Types
import qualified Data.Aeson as J
import qualified Language.Haskell.TH as TH
import qualified Language.Haskell.TH.Syntax as TH
getVendors :: TH.Q TH.Exp
getVendors = TH.runIO readVendors >>= TH.lift
where
vendorsPath = "res/vendors.json"
readVendors :: IO [Types.Vendor]
readVendors = do
vendors <- J.eitherDecodeFileStrict' vendorsPath
case vendors of
Left e -> fail $ "parsing vendors.json failed: " <> e
Right v -> return v

View File

@ -0,0 +1,116 @@
{-# LANGUAGE DeriveLift #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}
module CI.Types
( CI (..),
Vendor (..),
VendorEnv (..),
EnvVarName (..),
EnvVarValue (..),
)
where
import qualified Data.Aeson as J
import qualified Data.Aeson.Casing as J
import qualified Data.Aeson.TH as J
import Data.HashMap.Strict (HashMap)
import qualified Data.HashMap.Strict as HashMap
import Data.Hashable (Hashable)
import Data.Text (Text)
import qualified Data.Text as T
import Instances.TH.Lift ()
import qualified Language.Haskell.TH.Syntax as TH
data CI
= CI_APPVEYOR -- http://www.appveyor.com/
| CI_AZURE_PIPELINES -- https://azure.microsoft.com/en-us/services/devops/pipelines/
| CI_BAMBOO -- https://www.atlassian.com/software/bamboo/
| CI_BITBUCKET -- https://bitbucket.org/product/features/pipelines/
| CI_BITRISE -- https://www.bitrise.io/
| CI_BUDDY -- https://buddy.works/
| CI_BUILDKITE -- https://buildkite.com/
| CI_CIRCLE -- http://circleci.com/
| CI_CIRRUS -- https://cirrus-ci.org/
| CI_CODEBUILD -- https://aws.amazon.com/codebuild/
| CI_CODESHIP -- https://codeship.com/
| CI_DRONE -- https://drone.io/
| CI_DSARI -- https://github.com/rfinnie/dsari/
| CI_GITLAB -- https://about.gitlab.com/gitlab-ci/
| CI_GOCD -- https://www.go.cd/
| CI_HUDSON -- http://hudson-ci.org/
| CI_JENKINS -- https://jenkins-ci.org/
| CI_MAGNUM -- https://magnum-ci.com/
| CI_NETLIFY -- https://www.netlify.com/
| CI_NEVERCODE -- http://nevercode.io/
| CI_SAIL -- https://sail.ci/
| CI_SEMAPHORE -- https://semaphoreci.com/
| CI_SHIPPABLE -- https://www.shippable.com/
| CI_SOLANO -- https://www.solanolabs.com/
| CI_STRIDER -- https://strider-cd.github.io/
| CI_TASKCLUSTER -- http://docs.taskcluster.net/
| CI_TEAMCITY -- https://www.jetbrains.com/teamcity/
| CI_TRAVIS -- http://travis-ci.org/
| CI_UNKNOWN_VENDOR
deriving (Eq, Show, TH.Lift)
$( J.deriveJSON
J.defaultOptions {J.constructorTagModifier = drop $ T.length "CI_"}
''CI
)
newtype EnvVarName = EnvVarName {unEnvVarName :: Text}
deriving
( Eq,
Hashable,
Show,
J.FromJSON,
J.FromJSONKey,
J.ToJSON,
J.ToJSONKey,
TH.Lift
)
newtype EnvVarValue = EnvVarValue {unEnvVarValue :: Text}
deriving (Eq, Show, J.FromJSON, J.ToJSON, TH.Lift)
data VendorEnv
= VendorEnvString !EnvVarName
| VendorEnvList ![EnvVarName]
| VendorEnvObject !(HashMap EnvVarName EnvVarValue)
deriving (Eq, Show)
instance TH.Lift VendorEnv where
liftTyped (VendorEnvString n) = [||VendorEnvString $$(TH.liftTyped n)||]
liftTyped (VendorEnvList ns) = [||VendorEnvList $$(TH.liftTyped ns)||]
liftTyped (VendorEnvObject m) =
[||VendorEnvObject $ HashMap.fromList $$(TH.liftTyped $ HashMap.toList m)||]
instance J.FromJSON VendorEnv where
parseJSON val = case val of
J.String _ -> VendorEnvString <$> J.parseJSON val
J.Array _ -> VendorEnvList <$> J.parseJSON val
J.Object _ -> VendorEnvObject <$> J.parseJSON val
_ ->
fail
"expected String, List[String], or Map[String, String] in vendor env"
instance J.ToJSON VendorEnv where
toJSON val = case val of
VendorEnvString name -> J.toJSON name
VendorEnvList list -> J.toJSON list
VendorEnvObject object -> J.toJSON object
newtype VendorName = VendorName {unVendorName :: Text}
deriving (Eq, Show, J.FromJSON, J.ToJSON, TH.Lift)
data Vendor = Vendor
{ vendorName :: !VendorName,
vendorConstant :: !CI,
vendorEnv :: !VendorEnv
}
deriving (Eq, Show, TH.Lift)
$(J.deriveJSON (J.aesonPrefix J.snakeCase) ''Vendor)

View File

@ -0,0 +1,64 @@
# This file was automatically generated by 'stack init'
#
# Some commonly used options have been documented as comments in this file.
# For advanced use and comprehensive documentation of the format, please see:
# https://docs.haskellstack.org/en/stable/yaml_configuration/
# Resolver to choose a 'specific' stackage snapshot or a compiler version.
# A snapshot resolver dictates the compiler version and the set of packages
# to be used for project dependencies. For example:
#
# resolver: lts-3.5
# resolver: nightly-2015-09-21
# resolver: ghc-7.10.2
#
# The location of a snapshot can be provided as a file or url. Stack assumes
# a snapshot provided as a file might change, whereas a url resource does not.
#
# resolver: ./custom-snapshot.yaml
# resolver: https://example.com/snapshots/2018-01-01.yaml
resolver: lts-13.25
# User packages to be built.
# Various formats can be used as shown in the example below.
#
# packages:
# - some-directory
# - https://example.com/foo/bar/baz-0.0.2.tar.gz
# - location:
# git: https://github.com/commercialhaskell/stack.git
# commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a
# - location: https://github.com/commercialhaskell/stack/commit/e7b331f14bcffb8367cd58fbfc8b40ec7642100a
# subdirs:
# - auto-update
# - wai
packages:
- .
# Dependency packages to be pulled from upstream that are not in the resolver
# using the same syntax as the packages field.
# (e.g., acme-missiles-0.3)
# extra-deps: []
# Override default flag values for local packages and extra-deps
# flags: {}
# Extra package databases containing global packages
# extra-package-dbs: []
# Control whether we use the GHC we find on the path
# system-ghc: true
#
# Require a specific version of stack, using version ranges
# require-stack-version: -any # Default
# require-stack-version: ">=1.9"
#
# Override the architecture used by stack, especially useful on Windows
# arch: i386
# arch: x86_64
#
# Extra directories used by stack for building
# extra-include-dirs: [/path/to/dir]
# extra-lib-dirs: [/path/to/dir]
#
# Allow a newer minor version of GHC than the snapshot specifies
# compiler-check: newer-minor