2020-04-24 18:29:30 +02:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2021-11-16 16:02:57 +02:00
|
|
|
"github.com/SAP/jenkins-library/pkg/buildsettings"
|
2020-04-24 18:29:30 +02:00
|
|
|
"github.com/SAP/jenkins-library/pkg/log"
|
2020-05-20 13:41:23 +02:00
|
|
|
"github.com/SAP/jenkins-library/pkg/npm"
|
2020-04-24 18:29:30 +02:00
|
|
|
"github.com/SAP/jenkins-library/pkg/telemetry"
|
|
|
|
)
|
|
|
|
|
2021-11-16 16:02:57 +02:00
|
|
|
func npmExecuteScripts(config npmExecuteScriptsOptions, telemetryData *telemetry.CustomData, commonPipelineEnvironment *npmExecuteScriptsCommonPipelineEnvironment) {
|
2020-08-11 15:58:39 +02:00
|
|
|
npmExecutorOptions := npm.ExecutorOptions{DefaultNpmRegistry: config.DefaultNpmRegistry}
|
2020-06-18 17:30:17 +02:00
|
|
|
npmExecutor := npm.NewExecutor(npmExecutorOptions)
|
2020-04-24 18:29:30 +02:00
|
|
|
|
2021-11-16 16:02:57 +02:00
|
|
|
err := runNpmExecuteScripts(npmExecutor, &config, commonPipelineEnvironment)
|
2020-04-24 18:29:30 +02:00
|
|
|
if err != nil {
|
2021-05-10 17:44:28 +02:00
|
|
|
log.SetErrorCategory(log.ErrorBuild)
|
2020-04-24 18:29:30 +02:00
|
|
|
log.Entry().WithError(err).Fatal("step execution failed")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-16 16:02:57 +02:00
|
|
|
func runNpmExecuteScripts(npmExecutor npm.Executor, config *npmExecuteScriptsOptions, commonPipelineEnvironment *npmExecuteScriptsCommonPipelineEnvironment) error {
|
2020-06-18 17:30:17 +02:00
|
|
|
if config.Install {
|
2022-02-07 15:46:03 +02:00
|
|
|
if len(config.BuildDescriptorList) > 0 {
|
|
|
|
if err := npmExecutor.InstallAllDependencies(config.BuildDescriptorList); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
packageJSONFiles, err := npmExecutor.FindPackageJSONFilesWithExcludes(config.BuildDescriptorExcludeList)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := npmExecutor.InstallAllDependencies(packageJSONFiles); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-04-24 18:29:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-04 11:16:59 +02:00
|
|
|
if config.CreateBOM {
|
2022-02-07 15:46:03 +02:00
|
|
|
if len(config.BuildDescriptorList) > 0 {
|
|
|
|
if err := npmExecutor.CreateBOM(config.BuildDescriptorList); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
packageJSONFiles, err := npmExecutor.FindPackageJSONFilesWithExcludes(config.BuildDescriptorExcludeList)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := npmExecutor.CreateBOM(packageJSONFiles); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-03-04 11:16:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-15 14:46:04 +02:00
|
|
|
err := npmExecutor.RunScriptsInAllPackages(config.RunScripts, nil, config.ScriptOptions, config.VirtualFrameBuffer, config.BuildDescriptorExcludeList, config.BuildDescriptorList)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-12-01 08:46:18 +02:00
|
|
|
log.Entry().Debugf("creating build settings information...")
|
|
|
|
stepName := "npmExecuteScripts"
|
2022-03-14 13:33:52 +02:00
|
|
|
dockerImage, err := GetDockerImageValue(stepName)
|
2021-12-01 08:46:18 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-11-16 16:02:57 +02:00
|
|
|
npmConfig := buildsettings.BuildOptions{
|
|
|
|
Publish: config.Publish,
|
|
|
|
CreateBOM: config.CreateBOM,
|
|
|
|
DefaultNpmRegistry: config.DefaultNpmRegistry,
|
|
|
|
BuildSettingsInfo: config.BuildSettingsInfo,
|
2021-12-01 08:46:18 +02:00
|
|
|
DockerImage: dockerImage,
|
2021-11-16 16:02:57 +02:00
|
|
|
}
|
2021-12-01 08:46:18 +02:00
|
|
|
buildSettingsInfo, err := buildsettings.CreateBuildSettingsInfo(&npmConfig, stepName)
|
2021-11-16 16:02:57 +02:00
|
|
|
if err != nil {
|
2021-12-01 08:46:18 +02:00
|
|
|
log.Entry().Warnf("failed to create build settings info: %v", err)
|
2021-11-16 16:02:57 +02:00
|
|
|
}
|
2021-12-01 08:46:18 +02:00
|
|
|
commonPipelineEnvironment.custom.buildSettingsInfo = buildSettingsInfo
|
2021-11-16 16:02:57 +02:00
|
|
|
|
2021-07-15 14:46:04 +02:00
|
|
|
if config.Publish {
|
|
|
|
packageJSONFiles, err := npmExecutor.FindPackageJSONFilesWithExcludes(config.BuildDescriptorExcludeList)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-01-25 10:52:22 +02:00
|
|
|
err = npmExecutor.PublishAllPackages(packageJSONFiles, config.RepositoryURL, config.RepositoryUsername, config.RepositoryPassword, config.PackBeforePublish)
|
2021-07-15 14:46:04 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
2020-04-24 18:29:30 +02:00
|
|
|
}
|