From 5744d0fc1682282d18a41c1cb7f0401bf0100060 Mon Sep 17 00:00:00 2001 From: Thomas Carpentier Date: Fri, 28 Jun 2024 11:53:53 +0200 Subject: [PATCH 1/3] Support API Token --- bitrise.yml | 3 ++- main.go | 41 ++++++++++++++++++++++++++++++----------- step.yml | 17 +++++++++++------ 3 files changed, 43 insertions(+), 18 deletions(-) diff --git a/bitrise.yml b/bitrise.yml index 2bedcdd..724685a 100644 --- a/bitrise.yml +++ b/bitrise.yml @@ -11,6 +11,7 @@ app: # Define these in your .bitrise.secrets.yml - GMCLOUD_SAAS_EMAIL: $GMCLOUD_SAAS_EMAIL - GMCLOUD_SAAS_PASSWORD: $GMCLOUD_SAAS_PASSWORD + - GMCLOUD_SAAS_API_TOKEN: $GMCLOUD_SAAS_API_TOKEN workflows: ci: @@ -39,7 +40,7 @@ workflows: title: Genymotion SaaS - Install gmsaas run_if: "true" inputs: - - gmsaas_version: "1.9.0" + - gmsaas_version: "1.11.0" - email: $GMCLOUD_SAAS_EMAIL - password: $GMCLOUD_SAAS_PASSWORD - script: diff --git a/main.go b/main.go index 2230aca..25ea64b 100644 --- a/main.go +++ b/main.go @@ -16,9 +16,10 @@ var isError bool = false // Config ... type Config struct { - GMCloudSaaSEmail string `env:"email,required"` - GMCloudSaaSPassword stepconf.Secret `env:"password,required"` - GMCloudSaaSGmsaasVersion string `env:"gmsaas_version"` + GMCloudSaaSEmail string `env:"email"` + GMCloudSaaSPassword stepconf.Secret `env:"password"` + GMCloudSaaSGmsaasVersion string `env:"gmsaas_version"` + GMCloudSaaSAPIToken stepconf.Secret `env:"api_token"` } // install gmsaas if not installed. @@ -29,15 +30,18 @@ func ensureGMSAASisInstalled(version string) error { var installCmd *exec.Cmd if version != "" { - installCmd = exec.Command("pip3", "install", "gmsaas=="+version) + installCmd = exec.Command("pip3", "install", "gmsaas=="+version, "--break-system-packages") } else { - installCmd = exec.Command("pip3", "install", "gmsaas") + installCmd = exec.Command("pip3", "install", "gmsaas", "--break-system-packages") } if out, err := installCmd.CombinedOutput(); err != nil { return fmt.Errorf("%s failed, error: %s | output: %s", installCmd.Args, err, out) } + // Execute asdf reshim to update PATH + exec.Command("asdf", "reshim", "python").CombinedOutput() + if version != "" { log.Infof("gmsaas %s has been installed.", version) } else { @@ -88,13 +92,24 @@ func configureAndroidSDKPath() { } } -func login(username, password string) { +func login(api_token, username, password string) { log.Infof("Login Genymotion Account") - cmd := command.New("gmsaas", "auth", "login", username, password) - out, err := cmd.RunAndReturnTrimmedCombinedOutput() - if err != nil { - abortf("Failed to log with gmsaas, error: error: %s | output: %s", cmd.PrintableCommandArgs(), err, out) + + var cmd *exec.Cmd + if api_token != "" { + cmd = exec.Command("gmsaas", "auth", "token", api_token) + } else if username != "" && password != "" { + cmd = exec.Command("gmsaas", "auth", "login", username, password) + } else { + abortf("Invalid arguments. Must provide either a token or both email and password.") + return } + + if out, err := cmd.CombinedOutput(); err != nil { + abortf("Failed to login with gmsaas, error: error: %s | output: %s", cmd.Args, err, out) + return + } + log.Infof("Logged to Genymotion Cloud SaaS platform") } @@ -115,7 +130,11 @@ func main() { printError("Failed to export %s, error: %v", "GMSAAS_USER_AGENT_EXTRA_DATA", err) } - login(c.GMCloudSaaSEmail, string(c.GMCloudSaaSPassword)) + if c.GMCloudSaaSAPIToken != "" { + login(string(c.GMCloudSaaSAPIToken), "", "") + } else { + login("", c.GMCloudSaaSEmail, string(c.GMCloudSaaSPassword)) + } // --- Exit codes: // The exit code of your Step is very important. If you return diff --git a/step.yml b/step.yml index cb9d777..628302b 100644 --- a/step.yml +++ b/step.yml @@ -64,27 +64,32 @@ toolkit: inputs: + - api_token: "" + opts: + title: Genymotion Cloud SaaS API Token + summary: "" + description: |- + API Token to authenticate to your Genymotion Cloud SaaS account. If you don't have an account please register on [https://cloud.geny.io](https://cloud.geny.io/?&utm_source=web-referral&utm_medium=docs&utm_campaign=bitrise&utm_content=signup) and create an [API Token](https://cloud.geny.io/api) + - email: "" opts: title: Genymotion Cloud SaaS email summary: "" description: |- - Email of your Genymotion Cloud SaaS account, if you don't have an account please create it first on [https://cloud.geny.io](https://cloud.geny.io/?&utm_source=web-referral&utm_medium=docs&utm_campaign=bitrise&utm_content=signup) - is_required: true + DEPRECATED : Email of your Genymotion Cloud SaaS account, if you don't have an account please create it first on [https://cloud.geny.io](https://cloud.geny.io/?&utm_source=web-referral&utm_medium=docs&utm_campaign=bitrise&utm_content=signup) - password: "" opts: title: Genymotion Cloud SaaS password summary: "" description: |- - Password of your Genymotion Cloud SaaS account. + DEPRECATED: Password of your Genymotion Cloud SaaS account. is_sensitive: true - is_required: true - - gmsaas_version: "1.9.0" + - gmsaas_version: "1.11.0" opts: title: gmsaas version summary: "" description: |- - Install a specific version of gmsaas, per default it will install the latest gmsaas compatible : 1.9.0 + Install a specific version of gmsaas, per default it will install the latest gmsaas compatible : 1.11.0 From 0ff05404b87f045d1938d93745763c4217af1f59 Mon Sep 17 00:00:00 2001 From: Thomas Carpentier Date: Fri, 28 Jun 2024 11:54:18 +0200 Subject: [PATCH 2/3] Add tests --- bitrise.yml | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/bitrise.yml b/bitrise.yml index 724685a..bbe6a4b 100644 --- a/bitrise.yml +++ b/bitrise.yml @@ -48,6 +48,37 @@ workflows: - content: | #!/bin/bash gmsaas auth whoami + test-api-token: + before_run: + - audit-this-step + steps: + - change-workdir: + title: Switch working dir to test / _tmp dir + description: |- + To prevent step testing issues, like referencing relative + files with just './some-file' in the step's code, which would + work for testing the step from this directory directly + but would break if the step is included in another `bitrise.yml`. + run_if: true + inputs: + - path: ./_tmp + - is_create_path: true + - path::./: + title: Genymotion SaaS - Install gmsaas + run_if: "true" + inputs: + - gmsaas_version: "1.11.0" + - api_token: $GMCLOUD_SAAS_API_TOKEN + - script: + inputs: + - content: | + #!/bin/bash + gmsaas doctor + retVal=$? + if [ $retVal -ne 0 ]; then + echo "Error" + fi + exit $retVal From f3def9f3a76cfe5bbf585c711fcd2aa41ee4792d Mon Sep 17 00:00:00 2001 From: Thomas Carpentier Date: Fri, 28 Jun 2024 11:55:05 +0200 Subject: [PATCH 3/3] Bump step version --- bitrise.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bitrise.yml b/bitrise.yml index bbe6a4b..39132e1 100644 --- a/bitrise.yml +++ b/bitrise.yml @@ -5,7 +5,7 @@ app: envs: # If you want to share this step into a StepLib - BITRISE_STEP_ID: genymotion-saas-install-gmsaas-cli - - BITRISE_STEP_VERSION: "0.0.2" + - BITRISE_STEP_VERSION: "0.0.3" - BITRISE_STEP_GIT_CLONE_URL: https://github.com/genymobile/bitrise-step-genymotion-saas-install-gmsaas-cli.git - MY_STEPLIB_REPO_FORK_GIT_URL: $MY_STEPLIB_REPO_FORK_GIT_URL # Define these in your .bitrise.secrets.yml