-
Notifications
You must be signed in to change notification settings - Fork 593
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Introduce new npmExecuteTests step #5124
Changes from 16 commits
da9d73b
20e00eb
f24b876
7cadbf8
221840f
17f0810
0dc2cee
49d42fb
47ca127
187d850
aeef66b
56dfffe
65f7cba
20f05d8
045b530
6bf1d06
64f063f
f67b7a8
8e4ba08
1a3e5ea
c22d874
8c2456d
7c14e86
d8db284
44f8cd9
ec8369a
5768f0f
84cf942
d4cf486
cf6af6f
5dc002b
17175ff
3d9c038
0f8f9c3
1a682fc
db6c087
23ac975
e1a3653
970f340
803f18d
bc61bf3
103f0e5
9c482a4
84879a5
14f1527
c778adf
51548a4
d1ac1e7
ce98cff
d7e4bc0
636be4b
13a287e
52ed146
4da465d
d135127
9b637e2
44754da
2766216
2469441
9aec770
c215bac
a205ec9
d768424
6fc71b3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,99 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
package cmd | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
import ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
"fmt" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
"os" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
"strings" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
"github.com/SAP/jenkins-library/pkg/command" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
"github.com/SAP/jenkins-library/pkg/log" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
"github.com/SAP/jenkins-library/pkg/orchestrator" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
"github.com/SAP/jenkins-library/pkg/telemetry" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
func npmExecuteTests(config npmExecuteTestsOptions, _ *telemetry.CustomData) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
c := command.Command{} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
c.Stdout(log.Writer()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
c.Stderr(log.Writer()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
err := runNpmExecuteTests(&config, &c) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
log.Entry().WithError(err).Fatal("Step execution failed") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
func runNpmExecuteTests(config *npmExecuteTestsOptions, c command.ExecRunner) error { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
type AppURL struct { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
URL string `json:"url"` | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
Username string `json:"username"` | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
Password string `json:"password"` | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
appURLs := make(map[string]AppURL) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
urlsRaw, ok := config.AppSecrets["urls"].([]interface{}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
if ok { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
for _, urlRaw := range urlsRaw { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
urlMap := urlRaw.(map[string]interface{}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
url := urlMap["url"].(string) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
appURLs[url] = AppURL{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||||||||||||||||||||||||||||||||||||||||||||||||||||||
URL: url, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
Username: urlMap["username"].(string), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
Password: urlMap["password"].(string), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can handle the single url case with the collection as well.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this complicates it a bit |
||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
provider, err := orchestrator.GetOrchestratorConfigProvider(nil) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
return fmt.Errorf("failed to get orchestrator config provider: %w", err) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
env := provider.Branch() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
if config.OnlyRunInProductiveBranch && config.ProductiveBranch != env { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
log.Entry().Info("Skipping execution because it is configured to run only in the productive branch.") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
return nil | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
installCommandTokens := strings.Fields(config.InstallCommand) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
if err := c.RunExecutable(installCommandTokens[0], installCommandTokens[1:]...); err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
return fmt.Errorf("failed to execute install command: %w", err) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
isWdi5 := strings.Contains(config.RunScript, "wdi5") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
for _, appUrl := range appURLs { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
credentialsToEnv(appUrl.Username, appUrl.Password, isWdi5) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
err := runTestForUrl(appUrl.URL, config, c) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
return err | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
username := config.AppSecrets["username"].(string) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
password := config.AppSecrets["password"].(string) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
credentialsToEnv(username, password, isWdi5) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are empty credentials working here..? |
||||||||||||||||||||||||||||||||||||||||||||||||||||||
if err := runTestForUrl(config.BaseURL, config, c); err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
return err | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
return nil | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
func runTestForUrl(url string, config *npmExecuteTestsOptions, command command.ExecRunner) error { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
log.Entry().Infof("Running end to end tests for URL: %s", url) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
// Execute the npm script | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
options := "--baseUrl=" + url | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess this is tool specific and should be configurable or maybe expose as an env var as well? |
||||||||||||||||||||||||||||||||||||||||||||||||||||||
runScriptTokens := strings.Fields(config.RunScript) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
if err := command.RunExecutable(runScriptTokens[0], append(runScriptTokens[1:], options)...); err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
return fmt.Errorf("failed to execute npm script: %w", err) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
return nil | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
func credentialsToEnv(username, password string, wdi5 bool) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
prefix := "e2e" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
if wdi5 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
prefix = "wdi5" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about leaving this to the user by exposing a |
||||||||||||||||||||||||||||||||||||||||||||||||||||||
os.Setenv(prefix+"_username", username) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
os.Setenv(prefix+"_password", password) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks unrelated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is, but it's been missed in some old PR and it's a hard bug to catch, might add it as a new PR