Skip to content

Commit

Permalink
Login to expo before eject (#16)
Browse files Browse the repository at this point in the history
* Login to expo before eject

* Extract detach

* Remove faildefered

* Remove usage of failfDefered
  • Loading branch information
adborbas authored Mar 12, 2021
1 parent f92d72c commit fca9da9
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 29 deletions.
26 changes: 23 additions & 3 deletions bitrise.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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:
Expand Down
70 changes: 46 additions & 24 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func main() {
failf("Input validation failed: %s", err)
}

e := Expo{
expo := Expo{
Version: cfg.ExpoCLIVersion,
Workdir: cfg.Workdir,
}
Expand All @@ -89,28 +89,50 @@ 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()
log.Donef("Successfully ejected your project")

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)
}
}

Expand All @@ -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
}

//
Expand All @@ -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")

Expand Down
6 changes: 4 additions & 2 deletions step.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand Down

0 comments on commit fca9da9

Please sign in to comment.