From 823ef47db697186080f37dc91455bd26128870ed Mon Sep 17 00:00:00 2001 From: Ashly Mathew Date: Thu, 5 May 2022 12:39:59 +0200 Subject: [PATCH] Golang build publish binaries and add group id (#3749) * Add golang binaries to CPE and add groupID in coordinates Signed-off-by: Ashly Mathew * Introducing binaries as artifacts Signed-off-by: Ashly Mathew --- cmd/golangBuild.go | 8 ++++++++ cmd/golangBuild_generated.go | 5 ++++- pkg/versioning/gomodfile.go | 5 +++++ resources/metadata/golangBuild.yaml | 2 ++ 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/cmd/golangBuild.go b/cmd/golangBuild.go index af3d7dd8e..4b69b884e 100644 --- a/cmd/golangBuild.go +++ b/cmd/golangBuild.go @@ -259,7 +259,9 @@ func runGolangBuild(config *golangBuildOptions, telemetryData *telemetry.CustomD utils.SetOptions(repoClientOptions) + var binaryArtifacts piperenv.Artifacts for _, binary := range binaries { + targetPath := fmt.Sprintf("go/%s/%s/%s", goModFile.Module.Mod.Path, config.ArtifactVersion, binary) separator := "/" @@ -281,7 +283,13 @@ func runGolangBuild(config *golangBuildOptions, telemetryData *telemetry.CustomD if !(response.StatusCode == 200 || response.StatusCode == 201) { return fmt.Errorf("couldn't upload artifact, received status code %d", response.StatusCode) } + + binaryArtifacts = append(binaryArtifacts, piperenv.Artifact{ + Name: binary, + }) } + commonPipelineEnvironment.artifacts = binaryArtifacts + } return nil diff --git a/cmd/golangBuild_generated.go b/cmd/golangBuild_generated.go index a7b8371fd..efaf8be74 100644 --- a/cmd/golangBuild_generated.go +++ b/cmd/golangBuild_generated.go @@ -48,7 +48,8 @@ type golangBuildOptions struct { } type golangBuildCommonPipelineEnvironment struct { - custom struct { + artifacts piperenv.Artifacts + custom struct { buildSettingsInfo string } } @@ -60,6 +61,7 @@ func (p *golangBuildCommonPipelineEnvironment) persist(path, resourceName string value interface{} }{ {category: "custom", name: "buildSettingsInfo", value: p.custom.buildSettingsInfo}, + {category: "", name: "artifacts", value: p.artifacts}, } errCount := 0 @@ -526,6 +528,7 @@ func golangBuildMetadata() config.StepData { Type: "piperEnvironment", Parameters: []map[string]interface{}{ {"name": "custom/buildSettingsInfo"}, + {"name": "artifacts", "type": "piperenv.Artifacts"}, }, }, { diff --git a/pkg/versioning/gomodfile.go b/pkg/versioning/gomodfile.go index 20f1b7d58..2429abcc9 100644 --- a/pkg/versioning/gomodfile.go +++ b/pkg/versioning/gomodfile.go @@ -96,6 +96,11 @@ func (m *GoMod) GetCoordinates() (Coordinates, error) { artifactSplit := strings.Split(parsed.Module.Mod.Path, "/") artifactID := artifactSplit[len(artifactSplit)-1] result.ArtifactID = artifactID + + goModPath := parsed.Module.Mod.Path + lastIndex := strings.LastIndex(goModPath, "/") + groupID := goModPath[0:lastIndex] + result.GroupID = groupID } result.Version = parsed.Module.Mod.Version if result.Version == "" { diff --git a/resources/metadata/golangBuild.yaml b/resources/metadata/golangBuild.yaml index ecceb4d42..42d6d06bc 100644 --- a/resources/metadata/golangBuild.yaml +++ b/resources/metadata/golangBuild.yaml @@ -240,6 +240,8 @@ spec: type: piperEnvironment params: - name: custom/buildSettingsInfo + - name: artifacts + type: "piperenv.Artifacts" - name: reports type: reports params: