on master help sign in
ob deploy test: Add command to test on android device
commit0796b75a449d33ec3f21e2d98ccf09c2453d7731 authorLuigy Leon <luigy@outlook.com> dateTue 22 May 2018, 12:54 (8 years ago) parent9d30db9
1 file changed+17
lib/command/src/Obelisk/Command.hs+17
lib/command/src/Obelisk/Command.hs+17
@@ -26,6 +26,7 @@ import System.Environment
2626import System.FilePath
2727import System.IO (hIsTerminalDevice, stdout)
2828import System.Posix.Process (executeFile)
29+import System.Process (callCommand)
2930
3031import Obelisk.App
3132import Obelisk.CLI (Severity (..), cliDemo, failWith, getLogLevel, newLoggingConfig, putLog)
@@ -126,9 +127,15 @@ deployCommand :: Parser DeployCommand
126127deployCommand = hsubparser $ mconcat
127128 [ command "init" $ info deployInitCommand $ progDesc "Initialize a deployment configuration directory"
128129 , command "push" $ info (pure DeployCommand_Push) mempty
130+ , command "test" $ info (DeployCommand_Test <$> argument (maybeReader readPlatform) (completeWith ["android"])) $ progDesc "Test your obelisk project from a mobile platform. [Only android supported]"
129131 , command "update" $ info (pure DeployCommand_Update) $ progDesc "Update the deployment's src thunk to latest"
130132 ]
131133
134+readPlatform :: String -> Maybe Platform
135+readPlatform = \case
136+ "android" -> Just Android
137+ _ -> Nothing
138+
132139deployInitCommand :: Parser DeployCommand
133140deployInitCommand = fmap DeployCommand_Init $ DeployInitOpts
134141 <$> strArgument (action "directory" <> metavar "DEPLOYDIR" <> help "Path to a directory that it will create")
@@ -136,9 +143,13 @@ deployInitCommand = fmap DeployCommand_Init $ DeployInitOpts
136143 <*> some (strOption (long "hostname" <> metavar "HOSTNAME" <> help "hostname of the deployment target"))
137144 <*> strOption (long "upstream" <> value "origin" <> metavar "REMOTE" <> help "git remote to use for the src thunk" <> showDefault)
138145
146+data Platform = Android
147+ deriving (Show)
148+
139149data DeployCommand
140150 = DeployCommand_Init DeployInitOpts
141151 | DeployCommand_Push
152+ | DeployCommand_Test Platform
142153 | DeployCommand_Update
143154 deriving Show
144155
@@ -281,6 +292,12 @@ ob = \case
281292 hostname = _deployInitOpts_hostname deployOpts
282293 deployInit thunkPtr (root </> "config") deployDir sshKeyPath hostname
283294 DeployCommand_Push -> deployPush "."
295+ DeployCommand_Test Android -> withProjectRoot "." $ \root -> do
296+ let srcDir = root </> "src"
297+ exists <- liftIO $ doesDirectoryExist srcDir
298+ unless exists $ failWith "ob test should be run inside of a deploy directory"
299+ result <- nixBuildAttrWithCache srcDir "android.frontend"
300+ liftIO $ callCommand $ result </> "bin" </> "deploy"
284301 DeployCommand_Update -> deployUpdate "."
285302 ObCommand_Run -> inNixShell' $ static run
286303 -- inNixShell ($(mkClosure 'ghcidAction) ())