Skip to content

Commit 4fce9d6

Browse files
authored
Fixed build info recording npm workspaces (jfrog#168)
1 parent dd92b2c commit 4fce9d6

File tree

5 files changed

+32
-15
lines changed

5 files changed

+32
-15
lines changed

artifactory/commands/npm/artifactoryupload.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package npm
33
import (
44
"errors"
55
"fmt"
6+
67
buildinfo "github.com/jfrog/build-info-go/entities"
78
"github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
89
"github.com/jfrog/jfrog-cli-core/v2/utils/config"
@@ -35,8 +36,8 @@ func (nru *npmRtUpload) upload() (err error) {
3536
return
3637
}
3738

38-
func (nru *npmRtUpload) getBuildArtifacts() ([]buildinfo.Artifact, error) {
39-
return specutils.ConvertArtifactsDetailsToBuildInfoArtifacts(nru.artifactsDetailsReader)
39+
func (nru *npmRtUpload) getBuildArtifacts() []buildinfo.Artifact {
40+
return ConvertArtifactsDetailsToBuildInfoArtifacts(nru.artifactsDetailsReader, specutils.ConvertArtifactsDetailsToBuildInfoArtifacts)
4041
}
4142

4243
func (nru *npmRtUpload) doDeploy(target string, artDetails *config.ServerDetails, packedFilePath string) error {
@@ -63,7 +64,7 @@ func (nru *npmRtUpload) doDeploy(target string, artDetails *config.ServerDetails
6364
}
6465
totalFailed = summary.TotalFailed
6566
if nru.collectBuildInfo {
66-
nru.artifactsDetailsReader = summary.ArtifactsDetailsReader
67+
nru.artifactsDetailsReader = append(nru.artifactsDetailsReader, summary.ArtifactsDetailsReader)
6768
} else {
6869
err = summary.ArtifactsDetailsReader.Close()
6970
if err != nil {

artifactory/commands/npm/npmpublish.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ func (npu *npmPublish) upload() (err error) {
5151
return
5252
}
5353

54-
func (npu *npmPublish) getBuildArtifacts() ([]buildinfo.Artifact, error) {
55-
return utils.ConvertArtifactsSearchDetailsToBuildInfoArtifacts(npu.artifactsDetailsReader)
54+
func (npu *npmPublish) getBuildArtifacts() []buildinfo.Artifact {
55+
return ConvertArtifactsDetailsToBuildInfoArtifacts(npu.artifactsDetailsReader, utils.ConvertArtifactsSearchDetailsToBuildInfoArtifacts)
5656
}
5757

5858
func (npu *npmPublish) publishPackage(executablePath, filePath string, serverDetails *config.ServerDetails, target string) error {
@@ -96,7 +96,7 @@ func (npu *npmPublish) publishPackage(executablePath, filePath string, serverDet
9696
if err != nil {
9797
log.Warn("Unable to set build properties: ", err, "\nThis may cause build to not properly link with artifact, please add build name and build number properties on the tarball artifact manually")
9898
}
99-
npu.artifactsDetailsReader = searchReader
99+
npu.artifactsDetailsReader = append(npu.artifactsDetailsReader, searchReader)
100100
}
101101
return nil
102102
}

artifactory/commands/npm/publish.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ type NpmPublishCommandArgs struct {
4444
packageInfo *biutils.PackageInfo
4545
publishPath string
4646
tarballProvided bool
47-
artifactsDetailsReader *content.ContentReader
47+
artifactsDetailsReader []*content.ContentReader
4848
xrayScan bool
4949
scanOutputFormat format.OutputFormat
5050
distTag string
@@ -220,11 +220,10 @@ func (npc *NpmPublishCommand) Run() (err error) {
220220
npmModule.SetName(npc.buildConfiguration.GetModule())
221221
}
222222

223-
buildArtifacts, err := publishStrategy.GetBuildArtifacts()
224-
if err != nil {
225-
return err
223+
buildArtifacts := publishStrategy.GetBuildArtifacts()
224+
for _, artifactReader := range npc.artifactsDetailsReader {
225+
gofrogcmd.Close(artifactReader, &err)
226226
}
227-
defer gofrogcmd.Close(npc.artifactsDetailsReader, &err)
228227
err = npmModule.AddArtifacts(buildArtifacts...)
229228
if err != nil {
230229
return errorutils.CheckError(err)

artifactory/commands/npm/publishstrategy.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ import (
66
"github.com/jfrog/jfrog-cli-core/v2/common/format"
77
"github.com/jfrog/jfrog-cli-core/v2/common/spec"
88
"github.com/jfrog/jfrog-cli-core/v2/utils/config"
9+
"github.com/jfrog/jfrog-client-go/utils/io/content"
910
"github.com/jfrog/jfrog-client-go/utils/log"
1011
)
1112

1213
type Publisher interface {
1314
upload() error
14-
getBuildArtifacts() ([]buildinfo.Artifact, error)
15+
getBuildArtifacts() []buildinfo.Artifact
1516
}
1617

1718
type NpmPublishStrategy struct {
@@ -37,11 +38,25 @@ func (nps *NpmPublishStrategy) Publish() error {
3738
return nps.strategy.upload()
3839
}
3940

40-
func (nps *NpmPublishStrategy) GetBuildArtifacts() ([]buildinfo.Artifact, error) {
41+
func (nps *NpmPublishStrategy) GetBuildArtifacts() []buildinfo.Artifact {
4142
log.Debug("Using strategy for build info: ", nps.strategyName)
4243
return nps.strategy.getBuildArtifacts()
4344
}
4445

46+
// ConvertArtifactsDetailsToBuildInfoArtifacts converts artifact details readers to build info artifacts
47+
// using the provided conversion function
48+
func ConvertArtifactsDetailsToBuildInfoArtifacts(artifactsDetailsReader []*content.ContentReader, convertFunc func(*content.ContentReader) ([]buildinfo.Artifact, error)) []buildinfo.Artifact {
49+
buildArtifacts := make([]buildinfo.Artifact, 0, len(artifactsDetailsReader))
50+
for _, artifactReader := range artifactsDetailsReader {
51+
buildArtifact, err := convertFunc(artifactReader)
52+
if err != nil {
53+
log.Warn("Failed converting artifact details to build info artifacts: ", err.Error())
54+
}
55+
buildArtifacts = append(buildArtifacts, buildArtifact...)
56+
}
57+
return buildArtifacts
58+
}
59+
4560
func performXrayScan(filePath string, repo string, serverDetails *config.ServerDetails, scanOutputFormat format.OutputFormat) error {
4661
fileSpec := spec.NewBuilder().
4762
Pattern(filePath).

cliutils/flagkit/flags.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ const (
349349
npmPrefix = "npm-"
350350
npmDetailedSummary = npmPrefix + detailedSummary
351351
runNative = "run-native"
352+
npmWorkspaces = "workspaces"
352353

353354
// Unique nuget/dotnet config flags
354355
nugetV2 = "nuget-v2"
@@ -676,7 +677,7 @@ var commandFlags = map[string][]string{
676677
BuildName, BuildNumber, module, Project, runNative,
677678
},
678679
NpmPublish: {
679-
BuildName, BuildNumber, module, Project, npmDetailedSummary, xrayScan, xrOutput, runNative,
680+
BuildName, BuildNumber, module, Project, npmDetailedSummary, xrayScan, xrOutput, runNative, npmWorkspaces,
680681
},
681682
PnpmConfig: {
682683
global, serverIdResolve, repoResolve,
@@ -817,7 +818,8 @@ var flagsMap = map[string]components.Flag{
817818
bundle: components.NewStringFlag(bundle, "[Optional] If specified, only artifacts of the specified bundle are matched. The value format is bundle-name/bundle-version.", components.SetMandatoryFalse()),
818819
imageFile: components.NewStringFlag(imageFile, "[Mandatory] Path to a file which includes one line in the following format: <IMAGE-TAG>@sha256:<MANIFEST-SHA256>.", components.SetMandatoryTrue()),
819820
ocStartBuildRepo: components.NewStringFlag(repo, "[Mandatory] The name of the repository to which the image was pushed.", components.SetMandatoryTrue()),
820-
runNative: components.NewBoolFlag(runNative, "[Default: false] Set to true if you'd like to use the native client configurations. Note: This flag would invoke native client behind the scenes, has performance implications and does not support deployment view and detailed summary.", components.WithBoolDefaultValueFalse()),
821+
runNative: components.NewBoolFlag(runNative, "Set to true if you'd like to use the native client configurations. Note: This flag would invoke native client behind the scenes, has performance implications and does not support deployment view and detailed summary.", components.WithBoolDefaultValueFalse()),
822+
npmWorkspaces: components.NewBoolFlag(npmWorkspaces, "Set to true if you'd like to use npm workspaces.", components.WithBoolDefaultValueFalse()),
821823

822824
// Config specific commands flags
823825
interactive: components.NewBoolFlag(interactive, "[Default: true, unless $CI is true] Set to false if you do not want the config command to be interactive. If true, the --url option becomes optional.", components.WithBoolDefaultValueFalse()),

0 commit comments

Comments
 (0)