Skip to content
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

Merged
merged 64 commits into from
Jan 3, 2025

Conversation

phgermanov
Copy link
Contributor

Changes

  • Tests
  • Documentation
    ADR

@phgermanov phgermanov requested a review from a team as a code owner October 1, 2024 13:05
- PARAMETERS
- STAGES
- STEPS
default: "npm install"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use npm clean-install

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

- STAGES
- STEPS
mandatory: true
default: "wdi5"
Copy link
Member

@CCFenner CCFenner Oct 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Above we expose the tool npm, here we don't. We should be consistent. default: "npm run wdi5"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type: e2e
containers:
- name: node
image: node:lts-buster
Copy link
Member

@CCFenner CCFenner Oct 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

buster is a pretty old image. use a more recent one.

https://hub.docker.com/_/node

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@phgermanov phgermanov requested a review from CCFenner October 4, 2024 08:12
Comment on lines 30 to 36
if (config.credentialsId) {
if (config.wdi5) {
credentials.add([type: 'usernamePassword', id: config.credentialsId, env: ['wdi5_username', 'wdi5_password']])
} else {
credentials.add([type: 'usernamePassword', id: config.credentialsId, env: ['e2e_username', 'e2e_password']])
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should avoid doing such special handling in the groovy. That way we will have no support for it in GHA / ADO.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So should we store those in Vault as well?

Copy link
Contributor Author

@phgermanov phgermanov Oct 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something like:

{
  "appSecrets": {
  	"urls": [
      {
      	"url": "loocalhost:8080",
        "username": "some-username1",
        "password": "some-password1"
      },
      {
      	"url": "loocalhost:8080",
        "username": "some-username2",
        "password": "some-password2"
      }
    ],
    "username": "base-url-username",
    "password": "base-url-password"
  }
}

Comment on lines +141 to +143
if configOptions.OpenFile == nil {
return stepConfig, errors.New("config: open file function not set")
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks unrelated

Copy link
Contributor Author

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

params:
- name: installCommand
type: string
description: Command to be executed for installation. Defaults to `npm ci`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the "defaults to" can be omitted as defaults are printed in the docs.

Comment on lines 52 to 68
- name: onlyRunInProductiveBranch
type: bool
default: false
description: Boolean to indicate whether the step should only be executed in the productive branch or not.
scope:
- PARAMETERS
- STAGES
- STEPS
- name: productiveBranch
type: string
default: "main"
description: The branch used as productive branch.
scope:
- GENERAL
- PARAMETERS
- STAGES
- STEPS
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that really needed? I would not make a simple step aware of where it's running. This should be part of the pipeline I would say.

resources/metadata/npmExecuteTests.yaml Show resolved Hide resolved
- name: reports
type: reports
params:
- filePattern: "**/e2e-results.xml"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a typical file pattern for WDI5?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you can provide report with wdi5

resources/metadata/npmExecuteTests.yaml Outdated Show resolved Hide resolved
- STEPS
mandatory: true
default: "npm run wdi5"
- name: appSecrets
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Name is misleading as it also contains the URLs

resources/metadata/npmExecuteTests.yaml Show resolved Hide resolved
Comment on lines 93 to 96
prefix := "e2e"
if wdi5 {
prefix = "wdi5"
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about leaving this to the user by exposing a credentialEnvVarPrefix parameter?

log.Entry().Infof("Running end to end tests for URL: %s", url)

// Execute the npm script
options := "--baseUrl=" + url
Copy link
Member

Choose a reason for hiding this comment

The 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?


username := config.AppSecrets["username"].(string)
password := config.AppSecrets["password"].(string)
credentialsToEnv(username, password, isWdi5)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are empty credentials working here..?

Comment on lines 34 to 44
if ok {
for _, urlRaw := range urlsRaw {
urlMap := urlRaw.(map[string]interface{})
url := urlMap["url"].(string)
appURLs[url] = AppURL{
URL: url,
Username: urlMap["username"].(string),
Password: urlMap["password"].(string),
}
}
}
Copy link
Member

Choose a reason for hiding this comment

The 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
if ok {
for _, urlRaw := range urlsRaw {
urlMap := urlRaw.(map[string]interface{})
url := urlMap["url"].(string)
appURLs[url] = AppURL{
URL: url,
Username: urlMap["username"].(string),
Password: urlMap["password"].(string),
}
}
}
if ok {
for _, urlRaw := range urlsRaw {
urlMap := urlRaw.(map[string]interface{})
url := urlMap["url"].(string)
appURLs[url] = AppURL{
URL: url,
Username: urlMap["username"].(string),
Password: urlMap["password"].(string),
}
}
} else {
appURLs[url] = AppURL{
URL: config.BaseURL,
}
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this complicates it a bit

for _, urlRaw := range urlsRaw {
urlMap := urlRaw.(map[string]interface{})
url := urlMap["url"].(string)
appURLs[url] = AppURL{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The key is not used at all, so this could also be a list of AppUrL.

}

func runNpmExecuteTests(config *npmExecuteTestsOptions, c command.ExecRunner) error {
type AppURL struct {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
type AppURL struct {
type AppUnderTest struct {

Copy link
Member

@CCFenner CCFenner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good so far, just one thing with the docs, that we should align.

@@ -78,6 +78,7 @@ void call(Map parameters = [:], String stepName, String metadataFile, List crede
try {
try {
credentialWrapper(config, credentialInfo) {
echo "CONFIG: ${defaultConfigArgs}, ${customConfigArg}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this needed? We would see the values in the command anyways, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it was debug log, removed in a205ec9

test.md Outdated
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this used for?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that shouldn't have been committed, removed in a205ec9

- STAGES
- STEPS
mandatory: true
default: "npm run wdi5"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should be clear what our default tool is, if any. So I guess for WDI5 we need a sidecar, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added default sidecar: c215bac

@phgermanov
Copy link
Contributor Author

/it-go

@phgermanov phgermanov removed the request for review from anilkeshav27 January 2, 2025 11:33
Copy link

sonarqubecloud bot commented Jan 3, 2025

@phgermanov
Copy link
Contributor Author

/it-go

@phgermanov phgermanov merged commit 531a0b8 into master Jan 3, 2025
14 checks passed
@phgermanov phgermanov deleted the phgermanov/npm-execute-tests-go branch January 3, 2025 10:43
maxatsap added a commit to maxatsap/jenkins-library that referenced this pull request Jan 10, 2025
…ix-fix

* origin/master: (36 commits)
  Revert changes done to release action (SAP#5228)
  Update release-go.yml (SAP#5227)
  Remove README and CONTRIBUTING files from release 3rd try (SAP#5226)
  fix(setupCommonPipelineEnvironment): handling tags from scm info (SAP#5219)
  Remove README and CONTRIBUTING files from release 2nd try (SAP#5225)
  [CxONE] Improve report: add Low findings; Proposed Not Exploitable state (SAP#5223)
  Remove README and CONTRIBUTING files from release (SAP#5221)
  fix(naming): Rename Trust Engine to System Trust (SAP#5217)
  abapEnvironmentAssemblePackages Check for Build Errors (SAP#5214)
  docs: fix npmExuceteTests documentation formatting issues (SAP#5218)
  feat: Introduce new npmExecuteTests step (SAP#5124)
  fix(cloudFoundryDeploy): argument list too long (SAP#5216)
  Revert "Fix deployment failure with CF if password contains special char (SAP#5197)" (SAP#5215)
  chore(trustengine): Rename Trust Engine to System Trust in logs and docs (SAP#5210)
  Fix deployment failure with CF if password contains special char (SAP#5197)
  Update go version to 1.23 and removed some helper methods in favor of STD library (SAP#5200)
  Added validation for buildTool and buildDescriptorFile (SAP#5193)
  Unstash class files for Compliance stage (SAP#5192) (SAP#5204)
  fix(documentation): check param for jenkinsParams before appending Jenkins-specific text (SAP#5203)
  Align description of ADO and GHA (SAP#5202)
  ...
maxatsap added a commit to maxatsap/jenkins-library that referenced this pull request Jan 10, 2025
* origin/master: (36 commits)
  Revert changes done to release action (SAP#5228)
  Update release-go.yml (SAP#5227)
  Remove README and CONTRIBUTING files from release 3rd try (SAP#5226)
  fix(setupCommonPipelineEnvironment): handling tags from scm info (SAP#5219)
  Remove README and CONTRIBUTING files from release 2nd try (SAP#5225)
  [CxONE] Improve report: add Low findings; Proposed Not Exploitable state (SAP#5223)
  Remove README and CONTRIBUTING files from release (SAP#5221)
  fix(naming): Rename Trust Engine to System Trust (SAP#5217)
  abapEnvironmentAssemblePackages Check for Build Errors (SAP#5214)
  docs: fix npmExuceteTests documentation formatting issues (SAP#5218)
  feat: Introduce new npmExecuteTests step (SAP#5124)
  fix(cloudFoundryDeploy): argument list too long (SAP#5216)
  Revert "Fix deployment failure with CF if password contains special char (SAP#5197)" (SAP#5215)
  chore(trustengine): Rename Trust Engine to System Trust in logs and docs (SAP#5210)
  Fix deployment failure with CF if password contains special char (SAP#5197)
  Update go version to 1.23 and removed some helper methods in favor of STD library (SAP#5200)
  Added validation for buildTool and buildDescriptorFile (SAP#5193)
  Unstash class files for Compliance stage (SAP#5192) (SAP#5204)
  fix(documentation): check param for jenkinsParams before appending Jenkins-specific text (SAP#5203)
  Align description of ADO and GHA (SAP#5202)
  ...
maxatsap added a commit to maxatsap/jenkins-library that referenced this pull request Jan 10, 2025
…fig-fix

* origin/master: (36 commits)
  Revert changes done to release action (SAP#5228)
  Update release-go.yml (SAP#5227)
  Remove README and CONTRIBUTING files from release 3rd try (SAP#5226)
  fix(setupCommonPipelineEnvironment): handling tags from scm info (SAP#5219)
  Remove README and CONTRIBUTING files from release 2nd try (SAP#5225)
  [CxONE] Improve report: add Low findings; Proposed Not Exploitable state (SAP#5223)
  Remove README and CONTRIBUTING files from release (SAP#5221)
  fix(naming): Rename Trust Engine to System Trust (SAP#5217)
  abapEnvironmentAssemblePackages Check for Build Errors (SAP#5214)
  docs: fix npmExuceteTests documentation formatting issues (SAP#5218)
  feat: Introduce new npmExecuteTests step (SAP#5124)
  fix(cloudFoundryDeploy): argument list too long (SAP#5216)
  Revert "Fix deployment failure with CF if password contains special char (SAP#5197)" (SAP#5215)
  chore(trustengine): Rename Trust Engine to System Trust in logs and docs (SAP#5210)
  Fix deployment failure with CF if password contains special char (SAP#5197)
  Update go version to 1.23 and removed some helper methods in favor of STD library (SAP#5200)
  Added validation for buildTool and buildDescriptorFile (SAP#5193)
  Unstash class files for Compliance stage (SAP#5192) (SAP#5204)
  fix(documentation): check param for jenkinsParams before appending Jenkins-specific text (SAP#5203)
  Align description of ADO and GHA (SAP#5202)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants