From fca9da9468090b459ae63471594dfc741b2b6c24 Mon Sep 17 00:00:00 2001 From: Adam Borbas Date: Fri, 12 Mar 2021 13:58:21 +0100 Subject: [PATCH] Login to expo before eject (#16) * Login to expo before eject * Extract detach * Remove faildefered * Remove usage of failfDefered --- bitrise.yml | 26 +++++++++++++++++--- main.go | 70 +++++++++++++++++++++++++++++++++++------------------ step.yml | 6 +++-- 3 files changed, 73 insertions(+), 29 deletions(-) diff --git a/bitrise.yml b/bitrise.yml index fb1c6dc..88643ed 100644 --- a/bitrise.yml +++ b/bitrise.yml @@ -9,6 +9,9 @@ app: - SAMPLE_APP_URL: https://github.com/bitrise-samples/react-native-expo.git - BRANCH: "SDK39" + - ANDROIDMANIFEST_PATH: "$ORIGIN_SOURCE_DIR/_tmp/android/app/src/main/AndroidManifest.xml" + - EXPO_UPDATE_URL_KEY: "expo.modules.updates.EXPO_UPDATE_URL" + workflows: test: before_run: @@ -19,11 +22,13 @@ workflows: - errcheck: - go-test: after_run: - - eject + - test-eject - eject: + test-eject: before_run: - _clear_workdir + after_run: + - validate-output steps: - script: title: Clone sample app @@ -40,9 +45,24 @@ workflows: - project_path: $BITRISE_SOURCE_DIR - expo_cli_verson: "latest" - override_react_native_version: 0.61.0 + - user_name: $USER_NAME + - password: $PASSWORD + + validate-output: + title: Validate output + steps: + - script: + title: Validate that expo.modules.updates.EXPO_UPDATE_URL is present in AndroidManifest.xml + inputs: + - content: |- + #!/bin/bash + set -ex + if ! grep -q $EXPO_UPDATE_URL_KEY $ANDROIDMANIFEST_PATH; then + echo "$EXPO_UPDATE_URL_KEY is not found in $ANDROIDMANIFEST_PATH" + exit 1 + fi _clear_workdir: - envs: steps: - script: inputs: diff --git a/main.go b/main.go index cee79da..efb2c4e 100644 --- a/main.go +++ b/main.go @@ -79,7 +79,7 @@ func main() { failf("Input validation failed: %s", err) } - e := Expo{ + expo := Expo{ Version: cfg.ExpoCLIVersion, Workdir: cfg.Workdir, } @@ -89,20 +89,42 @@ func main() { fmt.Println() log.Infof("Install Expo CLI version: %s", cfg.ExpoCLIVersion) { - if err := e.installExpoCLI(); err != nil { + if err := expo.installExpoCLI(); err != nil { failf("Failed to install the selected (%s) version for Expo CLI: %s", cfg.ExpoCLIVersion, err) } } + // + // Logging in the user to the Expo account + loggedIn := false + if cfg.UserName != "" && cfg.Password != "" { + if err := login(expo, cfg); err != nil { + failf("Failed to log in to your provided Expo account: %s", err) + } + loggedIn = true + } + + if err := detach(expo, cfg); err != nil { + if loggedIn { + logout(expo) + } + failf(err.Error()) + } + + if loggedIn { + logout(expo) + } +} + +func detach(e Expo, cfg Config) error { // // Eject project via the Expo CLI fmt.Println() log.Infof("Eject project") { if err := e.eject(); err != nil { - failf("Failed to eject project: %s", err) + return fmt.Errorf("Failed to eject project: %s", err) } - } fmt.Println() @@ -110,7 +132,7 @@ func main() { if cfg.RunPublish == "yes" { if err := runPublish(e, cfg); err != nil { - failf("Failed to publish project: %s", err) + return fmt.Errorf("Failed to publish project: %s", err) } } @@ -123,19 +145,19 @@ func main() { packageJSONPth := filepath.Join(cfg.Workdir, "package.json") packages, err := parsePackageJSON(packageJSONPth) if err != nil { - failf(err.Error()) + return err } deps, err := packages.Object("dependencies") if err != nil { - failf("Failed to parse dependencies from package.json file: %s", err) + return fmt.Errorf("Failed to parse dependencies from package.json file: %s", err) } deps["react-native"] = cfg.OverrideReactNativeVersion packages["dependencies"] = deps if err := savePackageJSON(packages, packageJSONPth); err != nil { - failf(err.Error()) + return err } // @@ -153,36 +175,36 @@ func main() { out, err := cmd.RunAndReturnTrimmedCombinedOutput() if err != nil { if errorutil.IsExitStatusError(err) { - failf("%s failed: %s", cmd.PrintableCommandArgs(), out) + return fmt.Errorf("%s failed: %s", cmd.PrintableCommandArgs(), out) } - failf("%s failed: %s", cmd.PrintableCommandArgs(), err) + return fmt.Errorf("%s failed: %s", cmd.PrintableCommandArgs(), err) } } + + return nil } -func runPublish(expo Expo, cfg Config) error { - // - // Logging in the user to the Expo account +func login(expo Expo, cfg Config) error { fmt.Println() log.Infof("Login to Expo") { - if err := expo.login(cfg.UserName, cfg.Password); err != nil { - return fmt.Errorf("failed to log in to your provided Expo account: %s", err) - } + return expo.login(cfg.UserName, cfg.Password) } +} +func logout(expo Expo) { // // Logging out the user from the Expo account (even if it fails) - defer func() { - fmt.Println() - log.Infof("Logging out from Expo") - { - if err := expo.logout(); err != nil { - log.Warnf("Failed to log out from your Expo account: %s", err) - } + fmt.Println() + log.Infof("Logging out from Expo") + { + if err := expo.logout(); err != nil { + log.Warnf("Failed to log out from your Expo account: %s", err) } - }() + } +} +func runPublish(expo Expo, cfg Config) error { fmt.Println() log.Infof("Running expo publish") diff --git a/step.yml b/step.yml index 185a49e..54f6280 100644 --- a/step.yml +++ b/step.yml @@ -10,6 +10,8 @@ description: |- 1. Set the **Working directory input field** to the value of your project directory. By default, you do not have to change this. + 1. Provide your Expo username and password if you are using an Expo module that requires loging in before ejecting your app. Please refer to the [Expo documentation](https://docs.expo.io/) for more information. + 1. Specify the Expo CLI version. The default value is `latest` but you can specify an exact version, such as 3.0.0. @@ -68,7 +70,7 @@ inputs: title: Username for Expo summary: Username for Expo description: |- - Your account's username for `https://expo.io/` . + Your account's username for `https://expo.io/` . If provided `expo login` will be run before eject. Required if `run_publish` is set to "yes". **NOTE:** You need to use your username and not your e-mail address. @@ -77,7 +79,7 @@ inputs: title: Password for your Expo account summary: Password for your Expo account. description: |- - Your password for `https://expo.io/` . + Your password for `https://expo.io/` . If provided `expo login` will be run before eject. Required if `run_publish` is set to "yes". is_sensitive: true