on master help sign in
Add 'ob test deploy ios'
efe1e8dAlexandre Esteves
lib/command/src/Obelisk/Command.hs+11−15
@@ -25,7 +25,6 @@ import System.Environment
25import System.FilePath
25import System.FilePath
26import System.IO (hIsTerminalDevice, stdout)
26import System.IO (hIsTerminalDevice, stdout)
27import System.Posix.Process (executeFile)
27import System.Posix.Process (executeFile)
28−import System.Process (callCommand)
29
28
30import Obelisk.App
29import Obelisk.App
31import Obelisk.CliApp (Severity (..), failWith, getLogLevel, newCliConfig, putLog)
30import Obelisk.CliApp (Severity (..), failWith, getLogLevel, newCliConfig, putLog)
@@ -125,14 +124,14 @@ deployCommand :: Parser DeployCommand
125deployCommand = hsubparser $ mconcat
124deployCommand = hsubparser $ mconcat
126 [ command "init" $ info deployInitCommand $ progDesc "Initialize a deployment configuration directory"
125 [ command "init" $ info deployInitCommand $ progDesc "Initialize a deployment configuration directory"
127 , command "push" $ info (pure DeployCommand_Push) mempty
126 , command "push" $ info (pure DeployCommand_Push) mempty
128− , command "test" $ info (DeployCommand_Test <$> argument (maybeReader readPlatform) (completeWith ["android"])) $ progDesc "Test your obelisk project from a mobile platform. [Only android supported]"
127+ , command "test" $ info (DeployCommand_Test <$> platformP) $ progDesc "Test your obelisk project from a mobile platform."
129 , command "update" $ info (pure DeployCommand_Update) $ progDesc "Update the deployment's src thunk to latest"
128 , command "update" $ info (pure DeployCommand_Update) $ progDesc "Update the deployment's src thunk to latest"
130 ]
129 ]
131−
130+ where
132−readPlatform :: String -> Maybe Platform
131+ platformP = hsubparser $ mconcat
133−readPlatform = \case
134− "android" -> Just Android
132+ [ command "android" $ info (pure Android) mempty
135− _ -> Nothing
133+ , command "ios" $ info (pure IOS <*> strArgument (metavar "TEAMID" <> help "Your Team ID - found in the Apple developer portal")) mempty
134+ ]
136
135
137deployInitCommand :: Parser DeployCommand
136deployInitCommand :: Parser DeployCommand
138deployInitCommand = fmap DeployCommand_Init $ DeployInitOpts
137deployInitCommand = fmap DeployCommand_Init $ DeployInitOpts
@@ -141,13 +140,14 @@ deployInitCommand = fmap DeployCommand_Init $ DeployInitOpts
141 <*> some (strOption (long "hostname" <> metavar "HOSTNAME" <> help "hostname of the deployment target"))
140 <*> some (strOption (long "hostname" <> metavar "HOSTNAME" <> help "hostname of the deployment target"))
142 <*> strOption (long "upstream" <> value "origin" <> metavar "REMOTE" <> help "git remote to use for the src thunk" <> showDefault)
141 <*> strOption (long "upstream" <> value "origin" <> metavar "REMOTE" <> help "git remote to use for the src thunk" <> showDefault)
143
142
144−data Platform = Android
143+type TeamID = String
144+data PlatformDeployment = Android | IOS TeamID
145 deriving (Show)
145 deriving (Show)
146
146
147data DeployCommand
147data DeployCommand
148 = DeployCommand_Init DeployInitOpts
148 = DeployCommand_Init DeployInitOpts
149 | DeployCommand_Push
149 | DeployCommand_Push
150− | DeployCommand_Test Platform
150+ | DeployCommand_Test PlatformDeployment
151 | DeployCommand_Update
151 | DeployCommand_Update
152 deriving Show
152 deriving Show
153
153
@@ -290,13 +290,9 @@ ob = \case
290 hostname = _deployInitOpts_hostname deployOpts
290 hostname = _deployInitOpts_hostname deployOpts
291 deployInit thunkPtr (root </> "config") deployDir sshKeyPath hostname
291 deployInit thunkPtr (root </> "config") deployDir sshKeyPath hostname
292 DeployCommand_Push -> deployPush "."
292 DeployCommand_Push -> deployPush "."
293− DeployCommand_Test Android -> withProjectRoot "." $ \root -> do
294− let srcDir = root </> "src"
295− exists <- liftIO $ doesDirectoryExist srcDir
296− unless exists $ failWith "ob test should be run inside of a deploy directory"
297− result <- nixBuildAttrWithCache srcDir "android.frontend"
298− liftIO $ callCommand $ result </> "bin" </> "deploy"
299 DeployCommand_Update -> deployUpdate "."
293 DeployCommand_Update -> deployUpdate "."
294+ DeployCommand_Test Android -> deployMobile "android" []
295+ DeployCommand_Test (IOS teamID) -> deployMobile "ios" [teamID]
300 ObCommand_Run -> inNixShell' $ static run
296 ObCommand_Run -> inNixShell' $ static run
301 -- inNixShell ($(mkClosure 'ghcidAction) ())
297 -- inNixShell ($(mkClosure 'ghcidAction) ())
302 ObCommand_Thunk tc -> case tc of
298 ObCommand_Thunk tc -> case tc of
lib/command/src/Obelisk/Command/Deploy.hs+9−1
@@ -20,7 +20,7 @@ import System.Directory
20import System.FilePath
20import System.FilePath
21import System.Posix.Env (getEnvironment)
21import System.Posix.Env (getEnvironment)
22import System.Posix.Files
22import System.Posix.Files
23−import System.Process (delegate_ctlc, env, proc, readProcess)
23+import System.Process (callProcess, delegate_ctlc, env, proc, readProcess)
24
24
25import Obelisk.App (MonadObelisk)
25import Obelisk.App (MonadObelisk)
26import Obelisk.CliApp (Severity (..), callProcessAndLogOutput, failWith, putLog, withSpinner)
26import Obelisk.CliApp (Severity (..), callProcessAndLogOutput, failWith, putLog, withSpinner)
@@ -126,6 +126,14 @@ deployPush deployPath = do
126deployUpdate :: MonadObelisk m => FilePath -> m ()
126deployUpdate :: MonadObelisk m => FilePath -> m ()
127deployUpdate deployPath = updateThunkToLatest $ deployPath </> "src"
127deployUpdate deployPath = updateThunkToLatest $ deployPath </> "src"
128
128
129+deployMobile :: MonadObelisk m => String -> [String] -> m ()
130+deployMobile platform mobileArgs = withProjectRoot "." $ \root -> do
131+ let srcDir = root </> "src"
132+ exists <- liftIO $ doesDirectoryExist srcDir
133+ unless exists $ failWith "ob test should be run inside of a deploy directory"
134+ result <- nixBuildAttrWithCache srcDir $ platform <> ".frontend"
135+ liftIO $ callProcess (result </> "bin" </> "deploy") mobileArgs
136+
129sshAgent :: IO [(String, String)]
137sshAgent :: IO [(String, String)]
130sshAgent = do
138sshAgent = do
131 output <- BC8.pack <$> readProcess "ssh-agent" ["-c"] mempty
139 output <- BC8.pack <$> readProcess "ssh-agent" ["-c"] mempty