mirror of
https://github.com/SAP/jenkins-library.git
synced 2024-12-12 10:55:20 +02:00
40e13f1635
* enabling publish to only publish sub packages * changing directory and then coming back to original after the publish runs * searching the glob tar and npmrc in the current directory * excluding build descriptor check and addtional target tool check * changing the npm pack before publish to run only in sub packages * removing commented code clean up * adding the correct npm pack * improve logging * fix error handling and a bit style fix * fix unit tests * remove commented lines * respecting build descriptor list when provided * improve docu for the step param * fixing linting issues * improve docu --------- Co-authored-by: Gulom Alimov <gulomjon.alimov@sap.com> Co-authored-by: Jordi van Liempt <35920075+jliempt@users.noreply.github.com>
102 lines
3.2 KiB
Go
102 lines
3.2 KiB
Go
package cmd
|
|
|
|
import (
|
|
"github.com/SAP/jenkins-library/pkg/buildsettings"
|
|
"github.com/SAP/jenkins-library/pkg/log"
|
|
"github.com/SAP/jenkins-library/pkg/npm"
|
|
"github.com/SAP/jenkins-library/pkg/telemetry"
|
|
)
|
|
|
|
func npmExecuteScripts(config npmExecuteScriptsOptions, telemetryData *telemetry.CustomData, commonPipelineEnvironment *npmExecuteScriptsCommonPipelineEnvironment) {
|
|
npmExecutorOptions := npm.ExecutorOptions{DefaultNpmRegistry: config.DefaultNpmRegistry}
|
|
npmExecutor := npm.NewExecutor(npmExecutorOptions)
|
|
|
|
err := runNpmExecuteScripts(npmExecutor, &config, commonPipelineEnvironment)
|
|
if err != nil {
|
|
log.SetErrorCategory(log.ErrorBuild)
|
|
log.Entry().WithError(err).Fatal("step execution failed")
|
|
}
|
|
}
|
|
|
|
func runNpmExecuteScripts(npmExecutor npm.Executor, config *npmExecuteScriptsOptions, commonPipelineEnvironment *npmExecuteScriptsCommonPipelineEnvironment) error {
|
|
if config.Install {
|
|
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
|
|
}
|
|
}
|
|
}
|
|
|
|
if config.CreateBOM {
|
|
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
|
|
}
|
|
}
|
|
}
|
|
|
|
err := npmExecutor.RunScriptsInAllPackages(config.RunScripts, nil, config.ScriptOptions, config.VirtualFrameBuffer, config.BuildDescriptorExcludeList, config.BuildDescriptorList)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
log.Entry().Debugf("creating build settings information...")
|
|
stepName := "npmExecuteScripts"
|
|
dockerImage, err := GetDockerImageValue(stepName)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
npmConfig := buildsettings.BuildOptions{
|
|
Publish: config.Publish,
|
|
CreateBOM: config.CreateBOM,
|
|
DefaultNpmRegistry: config.DefaultNpmRegistry,
|
|
BuildSettingsInfo: config.BuildSettingsInfo,
|
|
DockerImage: dockerImage,
|
|
}
|
|
buildSettingsInfo, err := buildsettings.CreateBuildSettingsInfo(&npmConfig, stepName)
|
|
if err != nil {
|
|
log.Entry().Warnf("failed to create build settings info: %v", err)
|
|
}
|
|
commonPipelineEnvironment.custom.buildSettingsInfo = buildSettingsInfo
|
|
|
|
if config.Publish {
|
|
if len(config.BuildDescriptorList) > 0 {
|
|
err = npmExecutor.PublishAllPackages(config.BuildDescriptorList, config.RepositoryURL, config.RepositoryUsername, config.RepositoryPassword, config.PackBeforePublish)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
} else {
|
|
packageJSONFiles, err := npmExecutor.FindPackageJSONFilesWithExcludes(config.BuildDescriptorExcludeList)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
err = npmExecutor.PublishAllPackages(packageJSONFiles, config.RepositoryURL, config.RepositoryUsername, config.RepositoryPassword, config.PackBeforePublish)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|