You've already forked sap-jenkins-library
mirror of
https://github.com/SAP/jenkins-library.git
synced 2025-07-15 01:34:38 +02:00
Remove sapNpmRegistry (#1909)
The SAP NPM registry has been migrated to the default public registry, thus the separate configuration with the sapNpmRegistry is not required anymore. All packages from npm.sap.com have been migrated to npmjs.org and in the future SAP packages will only be available from the default public registry.
This commit is contained in:
@ -85,7 +85,7 @@ func mtaBuild(config mtaBuildOptions,
|
||||
httpClient := piperhttp.Client{}
|
||||
e := command.Command{}
|
||||
|
||||
npmExecutorOptions := npm.ExecutorOptions{DefaultNpmRegistry: config.DefaultNpmRegistry, SapNpmRegistry: config.SapNpmRegistry, ExecRunner: &e}
|
||||
npmExecutorOptions := npm.ExecutorOptions{DefaultNpmRegistry: config.DefaultNpmRegistry, ExecRunner: &e}
|
||||
npmExecutor := npm.NewExecutor(npmExecutorOptions)
|
||||
|
||||
err := runMtaBuild(config, commonPipelineEnvironment, &e, &files, &httpClient, npmExecutor)
|
||||
|
@ -24,7 +24,6 @@ type mtaBuildOptions struct {
|
||||
Platform string `json:"platform,omitempty"`
|
||||
ApplicationName string `json:"applicationName,omitempty"`
|
||||
DefaultNpmRegistry string `json:"defaultNpmRegistry,omitempty"`
|
||||
SapNpmRegistry string `json:"sapNpmRegistry,omitempty"`
|
||||
ProjectSettingsFile string `json:"projectSettingsFile,omitempty"`
|
||||
GlobalSettingsFile string `json:"globalSettingsFile,omitempty"`
|
||||
M2Path string `json:"m2Path,omitempty"`
|
||||
@ -122,7 +121,6 @@ func addMtaBuildFlags(cmd *cobra.Command, stepConfig *mtaBuildOptions) {
|
||||
cmd.Flags().StringVar(&stepConfig.Platform, "platform", `CF`, "mtaBuildTool 'cloudMbt' only: The target platform to which the mtar can be deployed.")
|
||||
cmd.Flags().StringVar(&stepConfig.ApplicationName, "applicationName", os.Getenv("PIPER_applicationName"), "The name of the application which is being built. If the parameter has been provided and no `mta.yaml` exists, the `mta.yaml` will be automatically generated using this parameter and the information (`name` and `version`) from 'package.json` before the actual build starts.")
|
||||
cmd.Flags().StringVar(&stepConfig.DefaultNpmRegistry, "defaultNpmRegistry", os.Getenv("PIPER_defaultNpmRegistry"), "Url to the npm registry that should be used for installing npm dependencies.")
|
||||
cmd.Flags().StringVar(&stepConfig.SapNpmRegistry, "sapNpmRegistry", `https://npm.sap.com`, "Url to the sap npm registry that should be used for installing npm dependencies prefixed with @sap.")
|
||||
cmd.Flags().StringVar(&stepConfig.ProjectSettingsFile, "projectSettingsFile", os.Getenv("PIPER_projectSettingsFile"), "Path or url to the mvn settings file that should be used as project settings file.")
|
||||
cmd.Flags().StringVar(&stepConfig.GlobalSettingsFile, "globalSettingsFile", os.Getenv("PIPER_globalSettingsFile"), "Path or url to the mvn settings file that should be used as global settings file")
|
||||
cmd.Flags().StringVar(&stepConfig.M2Path, "m2Path", os.Getenv("PIPER_m2Path"), "Path to the location of the local repository that should be used.")
|
||||
@ -204,14 +202,6 @@ func mtaBuildMetadata() config.StepData {
|
||||
Mandatory: false,
|
||||
Aliases: []config.Alias{{Name: "npm/defaultNpmRegistry"}},
|
||||
},
|
||||
{
|
||||
Name: "sapNpmRegistry",
|
||||
ResourceRef: []config.ResourceReference{},
|
||||
Scope: []string{"GENERAL", "PARAMETERS", "STAGES", "STEPS"},
|
||||
Type: "string",
|
||||
Mandatory: false,
|
||||
Aliases: []config.Alias{{Name: "npm/sapNpmRegistry"}},
|
||||
},
|
||||
{
|
||||
Name: "projectSettingsFile",
|
||||
ResourceRef: []config.ResourceReference{},
|
||||
|
@ -52,36 +52,12 @@ func TestMarBuild(t *testing.T) {
|
||||
|
||||
assert.Nil(t, err)
|
||||
|
||||
if assert.Len(t, e.Calls, 4) { // the second (unchecked) entry is the mta call
|
||||
if assert.Len(t, e.Calls, 3) { // the second (unchecked) entry is the mta call
|
||||
assert.Equal(t, "npm", e.Calls[1].Exec)
|
||||
assert.Equal(t, []string{"config", "set", "registry", "https://example.org/npm"}, e.Calls[1].Params)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("Provide SAP npm registry", func(t *testing.T) {
|
||||
|
||||
e := mock.ExecMockRunner{}
|
||||
e.StdoutReturn = map[string]string{"npm config get @sap:registry": "undefined"}
|
||||
|
||||
options := mtaBuildOptions{ApplicationName: "myApp", MtaBuildTool: "classic", BuildTarget: "CF", SapNpmRegistry: "https://example.sap/npm", MtarName: "myName"}
|
||||
|
||||
existingFiles := make(map[string]string)
|
||||
existingFiles["package.json"] = "{\"name\": \"myName\", \"version\": \"1.2.3\"}"
|
||||
fileUtils := MtaTestFileUtilsMock{existingFiles: existingFiles}
|
||||
|
||||
npmExecutor := newNpmExecutor(&e)
|
||||
npmExecutor.Options = npm.ExecutorOptions{SapNpmRegistry: options.SapNpmRegistry}
|
||||
|
||||
err := runMtaBuild(options, &cpe, &e, &fileUtils, &httpClient, npmExecutor)
|
||||
|
||||
assert.Nil(t, err)
|
||||
|
||||
if assert.Len(t, e.Calls, 4) { // the second (unchecked) entry is the mta call
|
||||
assert.Equal(t, "npm", e.Calls[2].Exec)
|
||||
assert.Equal(t, []string{"config", "set", "@sap:registry", "https://example.sap/npm"}, e.Calls[2].Params)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("Package json does not exist", func(t *testing.T) {
|
||||
|
||||
e := mock.ExecMockRunner{}
|
||||
@ -185,9 +161,9 @@ func TestMarBuild(t *testing.T) {
|
||||
|
||||
assert.Nil(t, err)
|
||||
|
||||
if assert.Len(t, e.Calls, 3) {
|
||||
assert.Equal(t, "java", e.Calls[2].Exec)
|
||||
assert.Equal(t, []string{"-jar", "mta.jar", "--mtar", "myName.mtar", "--build-target=CF", "build"}, e.Calls[2].Params)
|
||||
if assert.Len(t, e.Calls, 2) {
|
||||
assert.Equal(t, "java", e.Calls[1].Exec)
|
||||
assert.Equal(t, []string{"-jar", "mta.jar", "--mtar", "myName.mtar", "--build-target=CF", "build"}, e.Calls[1].Params)
|
||||
}
|
||||
|
||||
assert.Equal(t, "myName.mtar", cpe.mtarFilePath)
|
||||
@ -210,9 +186,9 @@ func TestMarBuild(t *testing.T) {
|
||||
|
||||
assert.Nil(t, err)
|
||||
|
||||
if assert.Len(t, e.Calls, 3) {
|
||||
assert.Equal(t, "java", e.Calls[2].Exec)
|
||||
assert.Equal(t, []string{"-jar", "mta.jar", "--mtar", "myNameFromMtar.mtar", "--build-target=CF", "build"}, e.Calls[2].Params)
|
||||
if assert.Len(t, e.Calls, 2) {
|
||||
assert.Equal(t, "java", e.Calls[1].Exec)
|
||||
assert.Equal(t, []string{"-jar", "mta.jar", "--mtar", "myNameFromMtar.mtar", "--build-target=CF", "build"}, e.Calls[1].Params)
|
||||
}
|
||||
})
|
||||
|
||||
@ -230,9 +206,9 @@ func TestMarBuild(t *testing.T) {
|
||||
|
||||
assert.Nil(t, err)
|
||||
|
||||
if assert.Len(t, e.Calls, 3) {
|
||||
assert.Equal(t, "java", e.Calls[2].Exec)
|
||||
assert.Equal(t, []string{"-jar", "/opt/sap/mta/lib/mta.jar", "--mtar", "myName.mtar", "--build-target=CF", "build"}, e.Calls[2].Params)
|
||||
if assert.Len(t, e.Calls, 2) {
|
||||
assert.Equal(t, "java", e.Calls[1].Exec)
|
||||
assert.Equal(t, []string{"-jar", "/opt/sap/mta/lib/mta.jar", "--mtar", "myName.mtar", "--build-target=CF", "build"}, e.Calls[1].Params)
|
||||
}
|
||||
})
|
||||
|
||||
@ -252,9 +228,9 @@ func TestMarBuild(t *testing.T) {
|
||||
|
||||
assert.Nil(t, err)
|
||||
|
||||
if assert.Len(t, e.Calls, 3) {
|
||||
assert.Equal(t, "mbt", e.Calls[2].Exec)
|
||||
assert.Equal(t, []string{"build", "--mtar", "myName.mtar", "--platform", "CF", "--target", "./"}, e.Calls[2].Params)
|
||||
if assert.Len(t, e.Calls, 2) {
|
||||
assert.Equal(t, "mbt", e.Calls[1].Exec)
|
||||
assert.Equal(t, []string{"build", "--mtar", "myName.mtar", "--platform", "CF", "--target", "./"}, e.Calls[1].Params)
|
||||
}
|
||||
assert.Equal(t, "myName.mtar", cpe.mtarFilePath)
|
||||
})
|
||||
|
@ -69,7 +69,7 @@ func (u *lintUtilsBundle) getGeneralPurposeConfig(configURL string) {
|
||||
|
||||
func npmExecuteLint(config npmExecuteLintOptions, telemetryData *telemetry.CustomData) {
|
||||
utils := newLintUtilsBundle()
|
||||
npmExecutorOptions := npm.ExecutorOptions{DefaultNpmRegistry: config.DefaultNpmRegistry, SapNpmRegistry: config.SapNpmRegistry, ExecRunner: utils.getExecRunner()}
|
||||
npmExecutorOptions := npm.ExecutorOptions{DefaultNpmRegistry: config.DefaultNpmRegistry, ExecRunner: utils.getExecRunner()}
|
||||
npmExecutor := npm.NewExecutor(npmExecutorOptions)
|
||||
|
||||
err := runNpmExecuteLint(npmExecutor, utils, &config)
|
||||
|
@ -16,7 +16,6 @@ import (
|
||||
type npmExecuteLintOptions struct {
|
||||
FailOnError bool `json:"failOnError,omitempty"`
|
||||
DefaultNpmRegistry string `json:"defaultNpmRegistry,omitempty"`
|
||||
SapNpmRegistry string `json:"sapNpmRegistry,omitempty"`
|
||||
}
|
||||
|
||||
// NpmExecuteLintCommand Execute ci-lint script on all npm packages in a project or execute default linting
|
||||
@ -77,7 +76,6 @@ either use ESLint configurations present in the project or use the provided gene
|
||||
func addNpmExecuteLintFlags(cmd *cobra.Command, stepConfig *npmExecuteLintOptions) {
|
||||
cmd.Flags().BoolVar(&stepConfig.FailOnError, "failOnError", false, "Defines the behavior in case linting errors are found.")
|
||||
cmd.Flags().StringVar(&stepConfig.DefaultNpmRegistry, "defaultNpmRegistry", os.Getenv("PIPER_defaultNpmRegistry"), "URL of the npm registry to use. Defaults to https://registry.npmjs.org/")
|
||||
cmd.Flags().StringVar(&stepConfig.SapNpmRegistry, "sapNpmRegistry", `https://npm.sap.com`, "The default npm registry URL to be used as the remote mirror for the SAP npm packages.")
|
||||
|
||||
}
|
||||
|
||||
@ -107,14 +105,6 @@ func npmExecuteLintMetadata() config.StepData {
|
||||
Mandatory: false,
|
||||
Aliases: []config.Alias{{Name: "npm/defaultNpmRegistry"}},
|
||||
},
|
||||
{
|
||||
Name: "sapNpmRegistry",
|
||||
ResourceRef: []config.ResourceReference{},
|
||||
Scope: []string{"PARAMETERS", "GENERAL", "STAGES", "STEPS"},
|
||||
Type: "string",
|
||||
Mandatory: false,
|
||||
Aliases: []config.Alias{{Name: "npm/sapNpmRegistry"}},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -62,8 +62,8 @@ func TestNpmExecuteLint(t *testing.T) {
|
||||
err := runNpmExecuteLint(&npmExecutor, &lintUtils, &config)
|
||||
|
||||
if assert.NoError(t, err) {
|
||||
if assert.Equal(t, 3, len(lintUtils.execRunner.Calls)) {
|
||||
assert.Equal(t, mock.ExecCall{Exec: "npx", Params: []string{"eslint", ".", "-f", "checkstyle", "-o", "./0_defaultlint.xml", "--ignore-pattern", "node_modules/", "--ignore-pattern", ".eslintrc.js"}}, lintUtils.execRunner.Calls[2])
|
||||
if assert.Equal(t, 2, len(lintUtils.execRunner.Calls)) {
|
||||
assert.Equal(t, mock.ExecCall{Exec: "npx", Params: []string{"eslint", ".", "-f", "checkstyle", "-o", "./0_defaultlint.xml", "--ignore-pattern", "node_modules/", "--ignore-pattern", ".eslintrc.js"}}, lintUtils.execRunner.Calls[1])
|
||||
}
|
||||
}
|
||||
})
|
||||
@ -84,9 +84,9 @@ func TestNpmExecuteLint(t *testing.T) {
|
||||
err := runNpmExecuteLint(&npmExecutor, &lintUtils, &config)
|
||||
|
||||
if assert.NoError(t, err) {
|
||||
if assert.Equal(t, 4, len(lintUtils.execRunner.Calls)) {
|
||||
assert.Equal(t, mock.ExecCall{Exec: "npx", Params: []string{"eslint", ".", "-f", "checkstyle", "-o", "./0_defaultlint.xml", "--ignore-pattern", "node_modules/", "--ignore-pattern", ".eslintrc.js"}}, lintUtils.execRunner.Calls[2])
|
||||
assert.Equal(t, mock.ExecCall{Exec: "npx", Params: []string{"eslint", "src/**/*.js", "-f", "checkstyle", "-o", "./1_defaultlint.xml", "--ignore-pattern", "node_modules/", "--ignore-pattern", ".eslintrc.js"}}, lintUtils.execRunner.Calls[3])
|
||||
if assert.Equal(t, 3, len(lintUtils.execRunner.Calls)) {
|
||||
assert.Equal(t, mock.ExecCall{Exec: "npx", Params: []string{"eslint", ".", "-f", "checkstyle", "-o", "./0_defaultlint.xml", "--ignore-pattern", "node_modules/", "--ignore-pattern", ".eslintrc.js"}}, lintUtils.execRunner.Calls[1])
|
||||
assert.Equal(t, mock.ExecCall{Exec: "npx", Params: []string{"eslint", "src/**/*.js", "-f", "checkstyle", "-o", "./1_defaultlint.xml", "--ignore-pattern", "node_modules/", "--ignore-pattern", ".eslintrc.js"}}, lintUtils.execRunner.Calls[2])
|
||||
}
|
||||
}
|
||||
})
|
||||
@ -105,9 +105,9 @@ func TestNpmExecuteLint(t *testing.T) {
|
||||
err := runNpmExecuteLint(&npmExecutor, &lintUtils, &config)
|
||||
|
||||
if assert.NoError(t, err) {
|
||||
if assert.Equal(t, 4, len(lintUtils.execRunner.Calls)) {
|
||||
assert.Equal(t, mock.ExecCall{Exec: "npm", Params: []string{"install", "eslint@^7.0.0", "typescript@^3.7.4", "@typescript-eslint/parser@^3.0.0", "@typescript-eslint/eslint-plugin@^3.0.0"}}, lintUtils.execRunner.Calls[2])
|
||||
assert.Equal(t, mock.ExecCall{Exec: "npx", Params: []string{"--no-install", "eslint", ".", "--ext", ".js,.jsx,.ts,.tsx", "-c", ".pipeline/.eslintrc.json", "-f", "checkstyle", "-o", "./defaultlint.xml", "--ignore-pattern", ".eslintrc.js"}}, lintUtils.execRunner.Calls[3])
|
||||
if assert.Equal(t, 3, len(lintUtils.execRunner.Calls)) {
|
||||
assert.Equal(t, mock.ExecCall{Exec: "npm", Params: []string{"install", "eslint@^7.0.0", "typescript@^3.7.4", "@typescript-eslint/parser@^3.0.0", "@typescript-eslint/eslint-plugin@^3.0.0"}}, lintUtils.execRunner.Calls[1])
|
||||
assert.Equal(t, mock.ExecCall{Exec: "npx", Params: []string{"--no-install", "eslint", ".", "--ext", ".js,.jsx,.ts,.tsx", "-c", ".pipeline/.eslintrc.json", "-f", "checkstyle", "-o", "./defaultlint.xml", "--ignore-pattern", ".eslintrc.js"}}, lintUtils.execRunner.Calls[2])
|
||||
}
|
||||
}
|
||||
})
|
||||
@ -129,8 +129,8 @@ func TestNpmExecuteLint(t *testing.T) {
|
||||
err := runNpmExecuteLint(&npmExecutor, &lintUtils, &config)
|
||||
|
||||
if assert.EqualError(t, err, "ci-lint script execution failed with error: failed to run npm script ci-lint: exit 1. This might be the result of severe linting findings, or some other issue while executing the script. Please examine the linting results in the UI, the cilint.xml file, if available, or the log above. ") {
|
||||
if assert.Equal(t, 3, len(lintUtils.execRunner.Calls)) {
|
||||
assert.Equal(t, mock.ExecCall{Exec: "npm", Params: []string{"run", "ci-lint", "--silent"}}, lintUtils.execRunner.Calls[2])
|
||||
if assert.Equal(t, 2, len(lintUtils.execRunner.Calls)) {
|
||||
assert.Equal(t, mock.ExecCall{Exec: "npm", Params: []string{"run", "ci-lint", "--silent"}}, lintUtils.execRunner.Calls[1])
|
||||
}
|
||||
}
|
||||
})
|
||||
@ -152,8 +152,8 @@ func TestNpmExecuteLint(t *testing.T) {
|
||||
err := runNpmExecuteLint(&npmExecutor, &lintUtils, &config)
|
||||
|
||||
if assert.EqualError(t, err, "Lint execution failed. This might be the result of severe linting findings, problems with the provided ESLint configuration (.eslintrc.json), or another issue. Please examine the linting results in the UI or in 0_defaultlint.xml, if available, or the log above. ") {
|
||||
if assert.Equal(t, 3, len(lintUtils.execRunner.Calls)) {
|
||||
assert.Equal(t, mock.ExecCall{Exec: "npx", Params: []string{"eslint", ".", "-f", "checkstyle", "-o", "./0_defaultlint.xml", "--ignore-pattern", "node_modules/", "--ignore-pattern", ".eslintrc.js"}}, lintUtils.execRunner.Calls[2])
|
||||
if assert.Equal(t, 2, len(lintUtils.execRunner.Calls)) {
|
||||
assert.Equal(t, mock.ExecCall{Exec: "npx", Params: []string{"eslint", ".", "-f", "checkstyle", "-o", "./0_defaultlint.xml", "--ignore-pattern", "node_modules/", "--ignore-pattern", ".eslintrc.js"}}, lintUtils.execRunner.Calls[1])
|
||||
}
|
||||
}
|
||||
})
|
||||
|
@ -7,7 +7,7 @@ import (
|
||||
)
|
||||
|
||||
func npmExecuteScripts(config npmExecuteScriptsOptions, telemetryData *telemetry.CustomData) {
|
||||
npmExecutorOptions := npm.ExecutorOptions{DefaultNpmRegistry: config.DefaultNpmRegistry, SapNpmRegistry: config.SapNpmRegistry}
|
||||
npmExecutorOptions := npm.ExecutorOptions{DefaultNpmRegistry: config.DefaultNpmRegistry}
|
||||
npmExecutor := npm.NewExecutor(npmExecutorOptions)
|
||||
|
||||
err := runNpmExecuteScripts(npmExecutor, &config)
|
||||
|
@ -17,7 +17,6 @@ type npmExecuteScriptsOptions struct {
|
||||
Install bool `json:"install,omitempty"`
|
||||
RunScripts []string `json:"runScripts,omitempty"`
|
||||
DefaultNpmRegistry string `json:"defaultNpmRegistry,omitempty"`
|
||||
SapNpmRegistry string `json:"sapNpmRegistry,omitempty"`
|
||||
VirtualFrameBuffer bool `json:"virtualFrameBuffer,omitempty"`
|
||||
ScriptOptions []string `json:"scriptOptions,omitempty"`
|
||||
BuildDescriptorExcludeList []string `json:"buildDescriptorExcludeList,omitempty"`
|
||||
@ -81,7 +80,6 @@ func addNpmExecuteScriptsFlags(cmd *cobra.Command, stepConfig *npmExecuteScripts
|
||||
cmd.Flags().BoolVar(&stepConfig.Install, "install", false, "Run npm install or similar commands depending on the project structure.")
|
||||
cmd.Flags().StringSliceVar(&stepConfig.RunScripts, "runScripts", []string{}, "List of additional run scripts to execute from package.json.")
|
||||
cmd.Flags().StringVar(&stepConfig.DefaultNpmRegistry, "defaultNpmRegistry", os.Getenv("PIPER_defaultNpmRegistry"), "URL of the npm registry to use. Defaults to https://registry.npmjs.org/")
|
||||
cmd.Flags().StringVar(&stepConfig.SapNpmRegistry, "sapNpmRegistry", `https://npm.sap.com`, "The default npm registry URL to be used as the remote mirror for the SAP npm packages.")
|
||||
cmd.Flags().BoolVar(&stepConfig.VirtualFrameBuffer, "virtualFrameBuffer", false, "(Linux only) Start a virtual frame buffer in the background. This allows you to run a web browser without the need for an X server. Note that xvfb needs to be installed in the execution environment.")
|
||||
cmd.Flags().StringSliceVar(&stepConfig.ScriptOptions, "scriptOptions", []string{}, "Options are passed to all runScripts calls separated by a '--'. './piper npmExecuteScripts --runScripts ci-e2e --scriptOptions '--tag1' will correspond to 'npm run ci-e2e -- --tag1'")
|
||||
cmd.Flags().StringSliceVar(&stepConfig.BuildDescriptorExcludeList, "buildDescriptorExcludeList", []string{`deployment/**`}, "List of build descriptors and therefore modules to exclude from execution of the npm scripts. The elements can either be a path to the build descriptor or a pattern.")
|
||||
@ -122,14 +120,6 @@ func npmExecuteScriptsMetadata() config.StepData {
|
||||
Mandatory: false,
|
||||
Aliases: []config.Alias{{Name: "npm/defaultNpmRegistry"}},
|
||||
},
|
||||
{
|
||||
Name: "sapNpmRegistry",
|
||||
ResourceRef: []config.ResourceReference{},
|
||||
Scope: []string{"PARAMETERS", "GENERAL", "STAGES", "STEPS"},
|
||||
Type: "string",
|
||||
Mandatory: false,
|
||||
Aliases: []config.Alias{{Name: "npm/sapNpmRegistry"}},
|
||||
},
|
||||
{
|
||||
Name: "virtualFrameBuffer",
|
||||
ResourceRef: []config.ResourceReference{},
|
||||
|
@ -175,7 +175,7 @@ func TestNpmExecuteScripts(t *testing.T) {
|
||||
t.Run("Test integration with npm pkg", func(t *testing.T) {
|
||||
config := npmExecuteScriptsOptions{Install: true, RunScripts: []string{"ci-build"}}
|
||||
|
||||
options := npm.ExecutorOptions{SapNpmRegistry: config.SapNpmRegistry, DefaultNpmRegistry: config.DefaultNpmRegistry}
|
||||
options := npm.ExecutorOptions{DefaultNpmRegistry: config.DefaultNpmRegistry}
|
||||
|
||||
utils := newNpmMockUtilsBundle()
|
||||
utils.AddFile("package.json", []byte("{\"scripts\": { \"ci-build\": \"\" } }"))
|
||||
@ -186,11 +186,10 @@ func TestNpmExecuteScripts(t *testing.T) {
|
||||
err := runNpmExecuteScripts(&npmExecutor, &config)
|
||||
|
||||
if assert.NoError(t, err) {
|
||||
if assert.Equal(t, 6, len(utils.execRunner.Calls)) {
|
||||
if assert.Equal(t, 4, len(utils.execRunner.Calls)) {
|
||||
assert.Equal(t, mock.ExecCall{Exec: "npm", Params: []string{"config", "get", "registry"}}, utils.execRunner.Calls[0])
|
||||
assert.Equal(t, mock.ExecCall{Exec: "npm", Params: []string{"config", "get", "@sap:registry"}}, utils.execRunner.Calls[1])
|
||||
assert.Equal(t, mock.ExecCall{Exec: "npm", Params: []string{"ci"}}, utils.execRunner.Calls[2])
|
||||
assert.Equal(t, mock.ExecCall{Exec: "npm", Params: []string{"run", "ci-build"}}, utils.execRunner.Calls[5])
|
||||
assert.Equal(t, mock.ExecCall{Exec: "npm", Params: []string{"ci"}}, utils.execRunner.Calls[1])
|
||||
assert.Equal(t, mock.ExecCall{Exec: "npm", Params: []string{"run", "ci-build"}}, utils.execRunner.Calls[3])
|
||||
}
|
||||
}
|
||||
})
|
||||
|
@ -87,7 +87,7 @@ func TestRegistrySetInFlags(t *testing.T) {
|
||||
//workaround to use test script util it is possible to set workdir for Exec call
|
||||
testScript := `#!/bin/sh
|
||||
cd /test
|
||||
/piperbin/piper npmExecuteScripts --install --runScripts=ci-build,ci-backend-unit-test --sapNpmRegistry=https://foo.bar >test-log.txt 2>&1
|
||||
/piperbin/piper npmExecuteScripts --install --runScripts=ci-build,ci-backend-unit-test --defaultNpmRegistry=https://foo.bar >test-log.txt 2>&1
|
||||
`
|
||||
ioutil.WriteFile(filepath.Join(tempDir, "runPiper.sh"), []byte(testScript), 0700)
|
||||
|
||||
@ -189,7 +189,7 @@ func TestRegistryWithTwoModules(t *testing.T) {
|
||||
//workaround to use test script util it is possible to set workdir for Exec call
|
||||
testScript := `#!/bin/sh
|
||||
cd /test
|
||||
/piperbin/piper npmExecuteScripts --install --runScripts=ci-build,ci-backend-unit-test --sapNpmRegistry=https://foo.bar >test-log.txt 2>&1
|
||||
/piperbin/piper npmExecuteScripts --install --runScripts=ci-build,ci-backend-unit-test --defaultNpmRegistry=https://foo.bar >test-log.txt 2>&1
|
||||
`
|
||||
ioutil.WriteFile(filepath.Join(tempDir, "runPiper.sh"), []byte(testScript), 0700)
|
||||
|
||||
|
@ -4,6 +4,6 @@
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"ci-build": "npm config get @sap:registry"
|
||||
"ci-build": "npm config get registry"
|
||||
}
|
||||
}
|
||||
|
@ -1 +1 @@
|
||||
@sap:registry=https://example.com
|
||||
registry=https://example.com
|
||||
|
@ -4,6 +4,6 @@
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"ci-build": "npm config get @sap:registry"
|
||||
"ci-build": "npm config get registry"
|
||||
}
|
||||
}
|
||||
|
@ -1 +1 @@
|
||||
@sap:registry=https://example.com
|
||||
registry=https://example.com
|
||||
|
@ -4,6 +4,6 @@
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"ci-build": "npm config get @sap:registry"
|
||||
"ci-build": "npm config get registry"
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,6 @@
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"ci-build": "npm config get @sap:registry"
|
||||
"ci-build": "npm config get registry"
|
||||
}
|
||||
}
|
||||
|
@ -32,7 +32,6 @@ type Executor interface {
|
||||
// ExecutorOptions holds common parameters for functions of Executor
|
||||
type ExecutorOptions struct {
|
||||
DefaultNpmRegistry string
|
||||
SapNpmRegistry string
|
||||
ExecRunner ExecRunner
|
||||
}
|
||||
|
||||
@ -84,39 +83,29 @@ func (u *utilsBundle) GetExecRunner() ExecRunner {
|
||||
// CAUTION: This will change the npm configuration in the user's home directory.
|
||||
func (exec *Execute) SetNpmRegistries() error {
|
||||
execRunner := exec.Utils.GetExecRunner()
|
||||
const sapRegistry = "@sap:registry"
|
||||
const npmRegistry = "registry"
|
||||
configurableRegistries := []string{npmRegistry, sapRegistry}
|
||||
for _, registry := range configurableRegistries {
|
||||
var buffer bytes.Buffer
|
||||
execRunner.Stdout(&buffer)
|
||||
err := execRunner.RunExecutable("npm", "config", "get", registry)
|
||||
execRunner.Stdout(log.Writer())
|
||||
|
||||
var buffer bytes.Buffer
|
||||
execRunner.Stdout(&buffer)
|
||||
err := execRunner.RunExecutable("npm", "config", "get", npmRegistry)
|
||||
execRunner.Stdout(log.Writer())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
preConfiguredRegistry := buffer.String()
|
||||
|
||||
if registryIsNonEmpty(preConfiguredRegistry) {
|
||||
log.Entry().Info("Discovered pre-configured npm registry " + npmRegistry + " with value " + preConfiguredRegistry)
|
||||
}
|
||||
|
||||
if exec.Options.DefaultNpmRegistry != "" && registryRequiresConfiguration(preConfiguredRegistry, "https://registry.npmjs.org") {
|
||||
log.Entry().Info("npm registry " + npmRegistry + " was not configured, setting it to " + exec.Options.DefaultNpmRegistry)
|
||||
err = execRunner.RunExecutable("npm", "config", "set", npmRegistry, exec.Options.DefaultNpmRegistry)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
preConfiguredRegistry := buffer.String()
|
||||
|
||||
if registryIsNonEmpty(preConfiguredRegistry) {
|
||||
log.Entry().Info("Discovered pre-configured npm registry " + registry + " with value " + preConfiguredRegistry)
|
||||
}
|
||||
|
||||
if registry == npmRegistry && exec.Options.DefaultNpmRegistry != "" && registryRequiresConfiguration(preConfiguredRegistry, "https://registry.npmjs.org") {
|
||||
log.Entry().Info("npm registry " + registry + " was not configured, setting it to " + exec.Options.DefaultNpmRegistry)
|
||||
err = execRunner.RunExecutable("npm", "config", "set", registry, exec.Options.DefaultNpmRegistry)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if registry == sapRegistry && exec.Options.SapNpmRegistry != "" && registryRequiresConfiguration(preConfiguredRegistry, "https://npm.sap.com") {
|
||||
log.Entry().Info("npm registry " + registry + " was not configured, setting it to " + exec.Options.SapNpmRegistry)
|
||||
err = execRunner.RunExecutable("npm", "config", "set", registry, exec.Options.SapNpmRegistry)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -119,8 +119,8 @@ func TestNpm(t *testing.T) {
|
||||
err := exec.install("package.json")
|
||||
|
||||
if assert.NoError(t, err) {
|
||||
if assert.Equal(t, 3, len(utils.execRunner.Calls)) {
|
||||
assert.Equal(t, mock.ExecCall{Exec: "npm", Params: []string{"ci"}}, utils.execRunner.Calls[2])
|
||||
if assert.Equal(t, 2, len(utils.execRunner.Calls)) {
|
||||
assert.Equal(t, mock.ExecCall{Exec: "npm", Params: []string{"ci"}}, utils.execRunner.Calls[1])
|
||||
}
|
||||
}
|
||||
})
|
||||
@ -139,8 +139,8 @@ func TestNpm(t *testing.T) {
|
||||
err := exec.install("package.json")
|
||||
|
||||
if assert.NoError(t, err) {
|
||||
if assert.Equal(t, 3, len(utils.execRunner.Calls)) {
|
||||
assert.Equal(t, mock.ExecCall{Exec: "npm", Params: []string{"install"}}, utils.execRunner.Calls[2])
|
||||
if assert.Equal(t, 2, len(utils.execRunner.Calls)) {
|
||||
assert.Equal(t, mock.ExecCall{Exec: "npm", Params: []string{"install"}}, utils.execRunner.Calls[1])
|
||||
}
|
||||
}
|
||||
})
|
||||
@ -160,8 +160,8 @@ func TestNpm(t *testing.T) {
|
||||
err := exec.install("package.json")
|
||||
|
||||
if assert.NoError(t, err) {
|
||||
if assert.Equal(t, 3, len(utils.execRunner.Calls)) {
|
||||
assert.Equal(t, mock.ExecCall{Exec: "yarn", Params: []string{"install", "--frozen-lockfile"}}, utils.execRunner.Calls[2])
|
||||
if assert.Equal(t, 2, len(utils.execRunner.Calls)) {
|
||||
assert.Equal(t, mock.ExecCall{Exec: "yarn", Params: []string{"install", "--frozen-lockfile"}}, utils.execRunner.Calls[1])
|
||||
}
|
||||
}
|
||||
})
|
||||
@ -183,9 +183,9 @@ func TestNpm(t *testing.T) {
|
||||
err := exec.InstallAllDependencies([]string{"package.json", filepath.Join("src", "package.json")})
|
||||
|
||||
if assert.NoError(t, err) {
|
||||
if assert.Equal(t, 6, len(utils.execRunner.Calls)) {
|
||||
assert.Equal(t, mock.ExecCall{Exec: "npm", Params: []string{"ci"}}, utils.execRunner.Calls[2])
|
||||
assert.Equal(t, mock.ExecCall{Exec: "npm", Params: []string{"ci"}}, utils.execRunner.Calls[5])
|
||||
if assert.Equal(t, 4, len(utils.execRunner.Calls)) {
|
||||
assert.Equal(t, mock.ExecCall{Exec: "npm", Params: []string{"ci"}}, utils.execRunner.Calls[1])
|
||||
assert.Equal(t, mock.ExecCall{Exec: "npm", Params: []string{"ci"}}, utils.execRunner.Calls[3])
|
||||
}
|
||||
}
|
||||
})
|
||||
@ -215,7 +215,6 @@ func TestNpm(t *testing.T) {
|
||||
utils.AddFile("package.json", []byte("{\"scripts\": { \"ci-lint\": \"exit 0\" } }"))
|
||||
|
||||
options := ExecutorOptions{}
|
||||
options.SapNpmRegistry = "foo.sap"
|
||||
|
||||
exec := &Execute{
|
||||
Utils: &utils,
|
||||
@ -242,8 +241,8 @@ func TestNpm(t *testing.T) {
|
||||
err := exec.executeScript("package.json", "ci-lint", []string{"--silent"}, []string{"--tag", "tag1"})
|
||||
|
||||
if assert.NoError(t, err) {
|
||||
if assert.Equal(t, 3, len(utils.execRunner.Calls)) {
|
||||
assert.Equal(t, mock.ExecCall{Exec: "npm", Params: []string{"run", "ci-lint", "--silent", "--", "--tag", "tag1"}}, utils.execRunner.Calls[2])
|
||||
if assert.Equal(t, 2, len(utils.execRunner.Calls)) {
|
||||
assert.Equal(t, mock.ExecCall{Exec: "npm", Params: []string{"run", "ci-lint", "--silent", "--", "--tag", "tag1"}}, utils.execRunner.Calls[1])
|
||||
}
|
||||
}
|
||||
})
|
||||
@ -263,9 +262,9 @@ func TestNpm(t *testing.T) {
|
||||
err := exec.RunScriptsInAllPackages(runScripts, nil, nil, false, nil)
|
||||
|
||||
if assert.NoError(t, err) {
|
||||
if assert.Equal(t, 6, len(utils.execRunner.Calls)) {
|
||||
assert.Equal(t, mock.ExecCall{Exec: "npm", Params: []string{"run", "ci-lint"}}, utils.execRunner.Calls[2])
|
||||
assert.Equal(t, mock.ExecCall{Exec: "npm", Params: []string{"run", "ci-build"}}, utils.execRunner.Calls[5])
|
||||
if assert.Equal(t, 4, len(utils.execRunner.Calls)) {
|
||||
assert.Equal(t, mock.ExecCall{Exec: "npm", Params: []string{"run", "ci-lint"}}, utils.execRunner.Calls[1])
|
||||
assert.Equal(t, mock.ExecCall{Exec: "npm", Params: []string{"run", "ci-build"}}, utils.execRunner.Calls[3])
|
||||
}
|
||||
}
|
||||
})
|
||||
@ -285,35 +284,13 @@ func TestNpm(t *testing.T) {
|
||||
err := exec.SetNpmRegistries()
|
||||
|
||||
if assert.NoError(t, err) {
|
||||
if assert.Equal(t, 3, len(utils.execRunner.Calls)) {
|
||||
if assert.Equal(t, 2, len(utils.execRunner.Calls)) {
|
||||
assert.Equal(t, mock.ExecCall{Exec: "npm", Params: []string{"config", "get", "registry"}}, utils.execRunner.Calls[0])
|
||||
assert.Equal(t, mock.ExecCall{Exec: "npm", Params: []string{"config", "set", "registry", exec.Options.DefaultNpmRegistry}}, utils.execRunner.Calls[1])
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("check set npm registry", func(t *testing.T) {
|
||||
utils := newNpmMockUtilsBundle()
|
||||
utils.AddFile("package.json", []byte("{\"scripts\": { \"ci-lint\": \"exit 0\" } }"))
|
||||
utils.AddFile(filepath.Join("src", "package.json"), []byte("{\"scripts\": { \"ci-build\": \"exit 0\" } }"))
|
||||
utils.execRunner = &mock.ExecMockRunner{StdoutReturn: map[string]string{"npm config get @sap:registry": "undefined"}}
|
||||
options := ExecutorOptions{}
|
||||
options.SapNpmRegistry = "https://example.sap/npm"
|
||||
|
||||
exec := &Execute{
|
||||
Utils: &utils,
|
||||
Options: options,
|
||||
}
|
||||
err := exec.SetNpmRegistries()
|
||||
|
||||
if assert.NoError(t, err) {
|
||||
if assert.Equal(t, 3, len(utils.execRunner.Calls)) {
|
||||
assert.Equal(t, mock.ExecCall{Exec: "npm", Params: []string{"config", "get", "@sap:registry"}}, utils.execRunner.Calls[1])
|
||||
assert.Equal(t, mock.ExecCall{Exec: "npm", Params: []string{"config", "set", "@sap:registry", exec.Options.SapNpmRegistry}}, utils.execRunner.Calls[2])
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("Call run-scripts with virtual frame buffer", func(t *testing.T) {
|
||||
utils := newNpmMockUtilsBundle()
|
||||
utils.AddFile("package.json", []byte("{\"scripts\": { \"foo\": \"\" } }"))
|
||||
@ -328,14 +305,14 @@ func TestNpm(t *testing.T) {
|
||||
|
||||
assert.Contains(t, utils.execRunner.Env, "DISPLAY=:99")
|
||||
assert.NoError(t, err)
|
||||
if assert.Len(t, utils.execRunner.Calls, 4) {
|
||||
if assert.Len(t, utils.execRunner.Calls, 3) {
|
||||
xvfbCall := utils.execRunner.Calls[0]
|
||||
assert.Equal(t, "Xvfb", xvfbCall.Exec)
|
||||
assert.Equal(t, []string{"-ac", ":99", "-screen", "0", "1280x1024x16"}, xvfbCall.Params)
|
||||
assert.True(t, xvfbCall.Async)
|
||||
assert.True(t, xvfbCall.Execution.Killed)
|
||||
|
||||
assert.Equal(t, mock.ExecCall{Exec: "npm", Params: []string{"run", "foo"}}, utils.execRunner.Calls[3])
|
||||
assert.Equal(t, mock.ExecCall{Exec: "npm", Params: []string{"run", "foo"}}, utils.execRunner.Calls[2])
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -94,18 +94,6 @@ spec:
|
||||
aliases:
|
||||
- name: npm/defaultNpmRegistry
|
||||
default:
|
||||
- name: sapNpmRegistry
|
||||
type: string
|
||||
description: "Url to the sap npm registry that should be used for installing npm dependencies prefixed with @sap."
|
||||
scope:
|
||||
- GENERAL
|
||||
- PARAMETERS
|
||||
- STAGES
|
||||
- STEPS
|
||||
mandatory: false
|
||||
default: https://npm.sap.com
|
||||
aliases:
|
||||
- name: npm/sapNpmRegistry
|
||||
- name: projectSettingsFile
|
||||
type: string
|
||||
description: "Path or url to the mvn settings file that should be used as project settings file."
|
||||
|
@ -29,18 +29,6 @@ spec:
|
||||
mandatory: false
|
||||
aliases:
|
||||
- name: npm/defaultNpmRegistry
|
||||
- name: sapNpmRegistry
|
||||
type: string
|
||||
description: The default npm registry URL to be used as the remote mirror for the SAP npm packages.
|
||||
scope:
|
||||
- PARAMETERS
|
||||
- GENERAL
|
||||
- STAGES
|
||||
- STEPS
|
||||
mandatory: false
|
||||
default: https://npm.sap.com
|
||||
aliases:
|
||||
- name: npm/sapNpmRegistry
|
||||
containers:
|
||||
- name: node
|
||||
image: node:12-buster-slim
|
||||
|
@ -33,17 +33,6 @@ spec:
|
||||
- STEPS
|
||||
aliases:
|
||||
- name: npm/defaultNpmRegistry
|
||||
- name: sapNpmRegistry
|
||||
type: string
|
||||
description: The default npm registry URL to be used as the remote mirror for the SAP npm packages.
|
||||
scope:
|
||||
- PARAMETERS
|
||||
- GENERAL
|
||||
- STAGES
|
||||
- STEPS
|
||||
default: https://npm.sap.com
|
||||
aliases:
|
||||
- name: npm/sapNpmRegistry
|
||||
- name: virtualFrameBuffer
|
||||
type: bool
|
||||
description: (Linux only) Start a virtual frame buffer in the background. This allows you to run a web browser without the need for an X server. Note that xvfb needs to be installed in the execution environment.
|
||||
|
Reference in New Issue
Block a user