mirror of
https://github.com/wasp-lang/wasp.git
synced 2024-08-17 03:00:59 +03:00
Telemetry now recognizes when running on CI. (#963)
* Telemetry now recognizes when running on CI. * Bumped cabal version from 0.8.0 to 0.8.1 . * fixed e2e tests.
This commit is contained in:
parent
5d6b229d6a
commit
0002414fa1
@ -5,6 +5,8 @@ module Wasp.Cli.Command.Telemetry.Project
|
||||
considerSendingData,
|
||||
readProjectTelemetryFile,
|
||||
getTimeOfLastTelemetryDataSent,
|
||||
-- NOTE: for testing only
|
||||
checkIfEnvValueIsTruthy,
|
||||
)
|
||||
where
|
||||
|
||||
@ -14,6 +16,8 @@ import Data.Aeson ((.=))
|
||||
import qualified Data.Aeson as Aeson
|
||||
import qualified Data.ByteString.Lazy.UTF8 as ByteStringLazyUTF8
|
||||
import qualified Data.ByteString.UTF8 as ByteStringUTF8
|
||||
import Data.Char (toLower)
|
||||
import Data.Functor ((<&>))
|
||||
import Data.Maybe (fromJust, fromMaybe)
|
||||
import qualified Data.Time as T
|
||||
import Data.Version (showVersion)
|
||||
@ -69,7 +73,24 @@ considerSendingData telemetryCacheDirPath userSignature projectHash cmdCall = do
|
||||
}
|
||||
|
||||
getTelemetryContext :: IO String
|
||||
getTelemetryContext = fromMaybe "" <$> ENV.lookupEnv "WASP_TELEMETRY_CONTEXT"
|
||||
getTelemetryContext =
|
||||
unwords . filter (not . null)
|
||||
<$> sequence
|
||||
[ fromMaybe "" <$> ENV.lookupEnv "WASP_TELEMETRY_CONTEXT",
|
||||
checkIfOnCi <&> \case True -> "CI"; False -> ""
|
||||
]
|
||||
where
|
||||
-- This function was inspired by https://github.com/watson/ci-info/blob/master/index.js .
|
||||
checkIfOnCi :: IO Bool
|
||||
checkIfOnCi =
|
||||
any checkIfEnvValueIsTruthy <$> mapM ENV.lookupEnv ["CI", "BUILD_ID", "CI_BUILD_ID"]
|
||||
|
||||
checkIfEnvValueIsTruthy :: Maybe String -> Bool
|
||||
checkIfEnvValueIsTruthy Nothing = False
|
||||
checkIfEnvValueIsTruthy (Just v)
|
||||
| null v = False
|
||||
| (toLower <$> v) == "false" = False
|
||||
| otherwise = True
|
||||
|
||||
-- * Project hash.
|
||||
|
||||
|
25
waspc/cli/test/Wasp/Cli/Command/Telemetry/ProjectTest.hs
Normal file
25
waspc/cli/test/Wasp/Cli/Command/Telemetry/ProjectTest.hs
Normal file
@ -0,0 +1,25 @@
|
||||
module Wasp.Cli.Command.Telemetry.ProjectTest where
|
||||
|
||||
import Test.Tasty.Hspec
|
||||
import Wasp.Cli.Command.Telemetry.Project
|
||||
( checkIfEnvValueIsTruthy,
|
||||
)
|
||||
|
||||
spec_checkIfEnvValueIsTruthy :: Spec
|
||||
spec_checkIfEnvValueIsTruthy = do
|
||||
it "Correctly determines if different env values are truthy" $ do
|
||||
let testCases =
|
||||
[ (Nothing, False),
|
||||
(Just "", False),
|
||||
(Just "false", False),
|
||||
(Just "False", False),
|
||||
(Just "FALSE", False),
|
||||
(Just "true", True),
|
||||
(Just "something", True),
|
||||
(Just "0", True),
|
||||
(Just "1", True),
|
||||
(Just "falsy", True),
|
||||
(Just "foo", True)
|
||||
]
|
||||
checkIfEnvValueIsTruthy . fst <$> testCases
|
||||
`shouldBe` snd <$> testCases
|
@ -453,6 +453,7 @@ test-suite cli-test
|
||||
DbMigrateTest
|
||||
TerminalTest
|
||||
Paths_waspc
|
||||
Wasp.Cli.Command.Telemetry.ProjectTest
|
||||
|
||||
test-suite e2e-test
|
||||
import: common-all, common-exe
|
||||
|
Loading…
Reference in New Issue
Block a user