From 36f8d35f1c3781a73cf9b6a975df2d5da61cf2ed Mon Sep 17 00:00:00 2001 From: Jordi van Liempt <35920075+jliempt@users.noreply.github.com> Date: Mon, 29 Jul 2024 09:00:30 +0200 Subject: [PATCH] feat(mtaBuild): Add enableSetTimestamp parameter (#4996) * add enableSetTimestamp param to mtaBuild * make default: true * go generate * update unit tests --------- Co-authored-by: jliempt <> --- cmd/mtaBuild.go | 6 ++++-- cmd/mtaBuild_generated.go | 11 +++++++++++ cmd/mtaBuild_test.go | 7 ++----- resources/metadata/mtaBuild.yaml | 8 ++++++++ 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/cmd/mtaBuild.go b/cmd/mtaBuild.go index 0982c0cb96..4f1ef4c64c 100644 --- a/cmd/mtaBuild.go +++ b/cmd/mtaBuild.go @@ -180,8 +180,10 @@ func runMtaBuild(config mtaBuildOptions, log.Entry().Infof("\"%s\" file found in project sources", mtaYamlFile) } - if err = setTimeStamp(mtaYamlFile, utils); err != nil { - return err + if config.EnableSetTimestamp { + if err = setTimeStamp(mtaYamlFile, utils); err != nil { + return err + } } mtarName, isMtarNativelySuffixed, err := getMtarName(config, mtaYamlFile, utils) diff --git a/cmd/mtaBuild_generated.go b/cmd/mtaBuild_generated.go index fc69335b0d..7912027e97 100644 --- a/cmd/mtaBuild_generated.go +++ b/cmd/mtaBuild_generated.go @@ -43,6 +43,7 @@ type mtaBuildOptions struct { Profiles []string `json:"profiles,omitempty"` BuildSettingsInfo string `json:"buildSettingsInfo,omitempty"` CreateBOM bool `json:"createBOM,omitempty"` + EnableSetTimestamp bool `json:"enableSetTimestamp,omitempty"` } type mtaBuildCommonPipelineEnvironment struct { @@ -245,6 +246,7 @@ func addMtaBuildFlags(cmd *cobra.Command, stepConfig *mtaBuildOptions) { cmd.Flags().StringSliceVar(&stepConfig.Profiles, "profiles", []string{}, "Defines list of maven build profiles to be used. profiles will overwrite existing values in the global settings xml at $M2_HOME/conf/settings.xml") cmd.Flags().StringVar(&stepConfig.BuildSettingsInfo, "buildSettingsInfo", os.Getenv("PIPER_buildSettingsInfo"), "build settings info is typically filled by the step automatically to create information about the build settings that were used during the mta build . This information is typically used for compliance related processes.") cmd.Flags().BoolVar(&stepConfig.CreateBOM, "createBOM", false, "Creates the bill of materials (BOM) using CycloneDX plugin.") + cmd.Flags().BoolVar(&stepConfig.EnableSetTimestamp, "enableSetTimestamp", true, "Enables setting the timestamp in the `mta.yaml` when it contains `${timestamp}`. Disable this when you want the MTA Deploy Service to do this instead.") } @@ -499,6 +501,15 @@ func mtaBuildMetadata() config.StepData { Aliases: []config.Alias{}, Default: false, }, + { + Name: "enableSetTimestamp", + ResourceRef: []config.ResourceReference{}, + Scope: []string{"STEPS", "STAGES", "PARAMETERS"}, + Type: "bool", + Mandatory: false, + Aliases: []config.Alias{}, + Default: true, + }, }, }, Containers: []config.Container{ diff --git a/cmd/mtaBuild_test.go b/cmd/mtaBuild_test.go index a3812900d4..3f127c4944 100644 --- a/cmd/mtaBuild_test.go +++ b/cmd/mtaBuild_test.go @@ -1,6 +1,3 @@ -//go:build unit -// +build unit - package cmd import ( @@ -98,7 +95,7 @@ func TestMtaBuild(t *testing.T) { utilsMock := newMtaBuildTestUtilsBundle() - options := mtaBuildOptions{ApplicationName: "myApp", Platform: "CF", MtarName: "myName", Source: "./", Target: "./"} + options := mtaBuildOptions{ApplicationName: "myApp", Platform: "CF", MtarName: "myName", Source: "./", Target: "./", EnableSetTimestamp: true} utilsMock.AddFile("package.json", []byte("{\"name\": \"myName\", \"version\": \"1.2.3\"}")) @@ -149,7 +146,7 @@ func TestMtaBuild(t *testing.T) { utilsMock := newMtaBuildTestUtilsBundle() - options := mtaBuildOptions{ApplicationName: "myApp"} + options := mtaBuildOptions{ApplicationName: "myApp", EnableSetTimestamp: true} utilsMock.AddFile("package.json", []byte("{\"name\": \"myName\", \"version\": \"1.2.3\"}")) utilsMock.AddFile("mta.yaml", []byte("already there with-${timestamp}")) diff --git a/resources/metadata/mtaBuild.yaml b/resources/metadata/mtaBuild.yaml index b69bb6a8e0..acbe5c06a7 100644 --- a/resources/metadata/mtaBuild.yaml +++ b/resources/metadata/mtaBuild.yaml @@ -236,6 +236,14 @@ spec: - STAGES - PARAMETERS default: false + - name: enableSetTimestamp + type: bool + description: Enables setting the timestamp in the `mta.yaml` when it contains `${timestamp}`. Disable this when you want the MTA Deploy Service to do this instead. + scope: + - STEPS + - STAGES + - PARAMETERS + default: true outputs: resources: - name: commonPipelineEnvironment