Something went wrong. Try again.
A collection of +180 reusable WebAssembly modules for building composable CI/CD pipelines with FluentCI fluentci.io/modules
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647module CI.ToolSetup (setupWith) where
import Preludeimport CI.Contract as Contractimport CI.Setup.Host as Himport CI.Setup.Types as Typesimport Data.Argonaut.Core (Json)import Data.Either (Either(..), either)import Data.String as Stringimport Data.String.CodeUnits as CUimport Data.String.Common (trim)import Data.String.Pattern (Pattern(..))import Foreign.Object as Objectimport Effect (Effect)import Effect.Exception (throw, try)
foreign import installGit :: Effect Unit
foreign import install :: Json -> Effect Contract.SetupResult
setupWith :: Json -> Effect Contract.SetupResultsetupWith json = do config <- either throw pure (Types.decodeConfig "gh" json) host <- H.host either throw pure (Types.hostSupported "gh" host) present <- try (H.run [ "git", "--version" ]) case present of Right _ -> pure unit Left _ -> do installGit H.run [ "git", "--version" ] reusable <- try do unless (config.installDir == "" && config.packageName == "" && not config.sudo) $ throw "Explicit installation requested" executable <- H.findExecutable "gh" unless (String.startsWith (Pattern "/") executable) $ throw "GitHub CLI is unavailable" actual <- H.capture [ executable, "--version" ] >>= H.versionFrom "gh" let expected = if String.startsWith (Pattern "v") config.version then CU.drop 1 config.version else config.version unless (expected == "latest" || expected == actual) $ throw "GitHub CLI version mismatch" bin <- trim <$> H.capture [ "dirname", executable ] result <- H.result "gh" actual bin Object.empty H.activate result pure (Contract.setupResult result) case reusable of Right result -> pure result Left _ -> install json