on master help sign in
ob deploy mobile: more robust mobile branching
c1e0cc0Luigy Leon
lib/command/src/Obelisk/Command.hs+4−8
@@ -142,8 +142,8 @@ deployCommand cfg = hsubparser $ mconcat
142 ]
142 ]
143 where
143 where
144 platformP = hsubparser $ mconcat
144 platformP = hsubparser $ mconcat
145− [ command "android" $ info (pure Android) mempty
145+ [ command "android" $ info (pure (Android, [])) mempty
146− , command "ios" $ info (pure IOS <*> strArgument (metavar "TEAMID" <> help "Your Team ID - found in the Apple developer portal")) mempty
146+ , command "ios" $ info ((,) <$> pure IOS <*> (fmap pure $ strArgument (metavar "TEAMID" <> help "Your Team ID - found in the Apple developer portal"))) mempty
147 ]
147 ]
148
148
149 remoteBuilderParser :: Parser (Maybe RemoteBuilder)
149 remoteBuilderParser :: Parser (Maybe RemoteBuilder)
@@ -173,16 +173,13 @@ deployInitOpts = DeployInitOpts
173 <*> flag True False (long "disable-https" <> help "Disable automatic https configuration for the backend")
173 <*> flag True False (long "disable-https" <> help "Disable automatic https configuration for the backend")
174
174
175type TeamID = String
175type TeamID = String
176−data PlatformDeployment = Android | IOS TeamID
177− deriving (Show)
178−
179data RemoteBuilder = RemoteBuilder_ObeliskVM
176data RemoteBuilder = RemoteBuilder_ObeliskVM
180 deriving (Eq, Show)
177 deriving (Eq, Show)
181
178
182data DeployCommand
179data DeployCommand
183 = DeployCommand_Init DeployInitOpts
180 = DeployCommand_Init DeployInitOpts
184 | DeployCommand_Push (Maybe RemoteBuilder)
181 | DeployCommand_Push (Maybe RemoteBuilder)
185− | DeployCommand_Test PlatformDeployment
182+ | DeployCommand_Test (PlatformDeployment, [String])
186 | DeployCommand_Update
183 | DeployCommand_Update
187 deriving Show
184 deriving Show
188
185
@@ -341,8 +338,7 @@ ob = \case
341 Nothing -> pure []
338 Nothing -> pure []
342 Just RemoteBuilder_ObeliskVM -> (:[]) <$> VmBuilder.getNixBuildersArg
339 Just RemoteBuilder_ObeliskVM -> (:[]) <$> VmBuilder.getNixBuildersArg
343 DeployCommand_Update -> deployUpdate "."
340 DeployCommand_Update -> deployUpdate "."
344− DeployCommand_Test Android -> deployMobile "android" []
341+ DeployCommand_Test (platform, extraArgs) -> deployMobile platform extraArgs
345− DeployCommand_Test (IOS teamID) -> deployMobile "ios" [teamID]
346 ObCommand_Run -> inNixShell' $ static run
342 ObCommand_Run -> inNixShell' $ static run
347 -- inNixShell ($(mkClosure 'ghcidAction) ())
343 -- inNixShell ($(mkClosure 'ghcidAction) ())
348 ObCommand_Thunk tc -> case tc of
344 ObCommand_Thunk tc -> case tc of
lib/command/src/Obelisk/Command/Deploy.hs+51−36
@@ -174,49 +174,64 @@ keytoolToAndroidConfig conf = runIdentity $ do
174 , ("keyPassword", keypass)
174 , ("keyPassword", keypass)
175 ]
175 ]
176
176
177+data PlatformDeployment = Android | IOS
178+ deriving (Show, Eq)
179+
180+renderPlatformDeployment :: PlatformDeployment -> String
181+renderPlatformDeployment = \case
182+ Android -> "android"
183+ IOS -> "ios"
184+
177−deployMobile :: MonadObelisk m => String -> [String] -> m ()
185+deployMobile :: MonadObelisk m => PlatformDeployment -> [String] -> m ()
178deployMobile platform mobileArgs = withProjectRoot "." $ \root -> do
186deployMobile platform mobileArgs = withProjectRoot "." $ \root -> do
179 let srcDir = root </> "src"
187 let srcDir = root </> "src"
180 exists <- liftIO $ doesDirectoryExist srcDir
188 exists <- liftIO $ doesDirectoryExist srcDir
181 unless exists $ failWith "ob test should be run inside of a deploy directory"
189 unless exists $ failWith "ob test should be run inside of a deploy directory"
182− when (platform == "android") $ do
190+ nixBuildTarget <- case platform of
191+ Android -> do
183− let keystorePath = root </> "android_keystore.jks"
192+ let keystorePath = root </> "android_keystore.jks"
184− keytoolConfPath = root </> "android_keytool_config.json"
193+ keytoolConfPath = root </> "android_keytool_config.json"
185− hasKeystore <- liftIO $ doesFileExist keystorePath
194+ hasKeystore <- liftIO $ doesFileExist keystorePath
186− when (not hasKeystore) $ do
195+ when (not hasKeystore) $ do
187− -- TODO log instructions for how to modify the keystore
196+ -- TODO log instructions for how to modify the keystore
188− putLog Notice $ "Creating keystore: " <> T.pack keystorePath
197+ putLog Notice $ "Creating keystore: " <> T.pack keystorePath
189− putLog Notice "Enter a keystore password: "
198+ putLog Notice "Enter a keystore password: "
190− keyStorePassword <- liftIO $ withEcho False getLine
199+ keyStorePassword <- liftIO $ withEcho False getLine
191− putLog Notice "Re-enter the keystore password: "
200+ putLog Notice "Re-enter the keystore password: "
192− keyStorePassword' <- liftIO $ withEcho False getLine
201+ keyStorePassword' <- liftIO $ withEcho False getLine
193− unless (keyStorePassword' == keyStorePassword) $ failWith "passwords do not match"
202+ unless (keyStorePassword' == keyStorePassword) $ failWith "passwords do not match"
194− let keyToolConf = KeytoolConfig
203+ let keyToolConf = KeytoolConfig
195− { _keytoolConfig_keystore = keystorePath
204+ { _keytoolConfig_keystore = keystorePath
196− , _keytoolConfig_alias = "obelisk"
205+ , _keytoolConfig_alias = "obelisk"
197− , _keytoolConfig_storepass = keyStorePassword
206+ , _keytoolConfig_storepass = keyStorePassword
198− , _keytoolConfig_keypass = keyStorePassword
207+ , _keytoolConfig_keypass = keyStorePassword
199− }
208+ }
200− createKeystore root $ keyToolConf
209+ createKeystore root $ keyToolConf
201− liftIO $ BSL.writeFile keytoolConfPath $ encode keyToolConf
210+ liftIO $ BSL.writeFile keytoolConfPath $ encode keyToolConf
202− checkKeytoolConfExist <- liftIO $ doesFileExist keytoolConfPath
211+ checkKeytoolConfExist <- liftIO $ doesFileExist keytoolConfPath
203− unless checkKeytoolConfExist $ failWith "Missing android KeytoolConfig"
212+ unless checkKeytoolConfExist $ failWith "Missing android KeytoolConfig"
204− keytoolConfContents <- liftIO $ BSL.readFile keytoolConfPath
213+ keytoolConfContents <- liftIO $ BSL.readFile keytoolConfPath
205− liftIO $ putStrLn $ show keytoolConfContents
214+ liftIO $ putStrLn $ show keytoolConfContents
206− releaseKey <- case eitherDecode keytoolConfContents of
215+ releaseKey <- case eitherDecode keytoolConfContents of
207− Left err -> failWith $ T.pack err
216+ Left err -> failWith $ T.pack err
208− Right conf -> do
217+ Right conf -> do
209− let nvset = toValue @(HM.HashMap Text (NValueNF Identity)) @Identity @(NValueNF Identity) $ keytoolToAndroidConfig conf
218+ let nvset = toValue @(HM.HashMap Text (NValueNF Identity)) @Identity @(NValueNF Identity) $ keytoolToAndroidConfig conf
210− return $ printNix $ runIdentity nvset
219+ return $ printNix $ runIdentity nvset
211− result <- nixCmd $ NixCmd_Build $ def
220+ return $ Target
212− & nixBuildConfig_outLink .~ OutLink_None
213− & nixCmdConfig_target .~ Target
214 { _target_path = Nothing
221 { _target_path = Nothing
215 , _target_attr = Nothing
222 , _target_attr = Nothing
216− , _target_expr = Just $ "with (import " <> srcDir <> " {}); " <> platform <> ".frontend.override (drv: { releaseKey = (if builtins.isNull drv.releaseKey then {} else drv.releaseKey) // " <> releaseKey <> "; })"
223+ , _target_expr = Just $ "with (import " <> srcDir <> " {}); " <> renderPlatformDeployment platform <> ".frontend.override (drv: { releaseKey = (if builtins.isNull drv.releaseKey then {} else drv.releaseKey) // " <> releaseKey <> "; })"
217 }
224 }
225+ IOS -> return $ Target
226+ { _target_path = Nothing
227+ , _target_attr = Just "ios.frontend"
228+ , _target_expr = Nothing
229+ }
230+ result <- nixCmd $ NixCmd_Build $ def
231+ & nixBuildConfig_outLink .~ OutLink_None
232+ & nixCmdConfig_target .~ nixBuildTarget
218− putLog Notice $ T.pack $ "Your recently built android apk can be found at the following path: " <> (show result)
233+ putLog Notice $ T.pack $ "Your recently built android apk can be found at the following path: " <> (show result)
219− callProcessAndLogOutput (Notice, Error) $ proc (result </> "bin" </> "deploy") mobileArgs
234+ callProcessAndLogOutput (Notice, Error) $ proc (result </> "bin" </> "deploy") mobileArgs
220 where
235 where
221 withEcho showEcho f = do
236 withEcho showEcho f = do
222 prevEcho <- hGetEcho stdin
237 prevEcho <- hGetEcho stdin