1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2025-10-30 23:57:50 +02:00

fix (mtaBuild) keep .mtar if added as a part of mta id (#3935)

* only remove mtar when its an file extension not other

* keep .mtar if added as a part of mta id

* not adding an addional mtar

* keeping the mtaId intact if the condition

* respecting mta artifact name

* removing condition

* trim only when suffix

* chaging the suffix

* handle case when mtar is natively suffixed

Co-authored-by: anilkeshav27 <you@example.com>
Co-authored-by: Ashly Mathew <ashly.mathew@sap.com>
This commit is contained in:
Anil Keshav
2022-08-24 14:19:04 +02:00
committed by GitHub
parent 0a2327dda8
commit 5b581efc31
2 changed files with 30 additions and 9 deletions

View File

@@ -184,7 +184,7 @@ func runMtaBuild(config mtaBuildOptions,
return err
}
mtarName, err := getMtarName(config, mtaYamlFile, utils)
mtarName, isMtarNativelySuffixed, err := getMtarName(config, mtaYamlFile, utils)
if err != nil {
return err
@@ -282,7 +282,10 @@ func runMtaBuild(config mtaBuildOptions,
mtarArtifactName := mtarName
mtarArtifactName = strings.ReplaceAll(mtarArtifactName, ".mtar", "")
// only trim the .mtar suffix from the mtarName
if !isMtarNativelySuffixed {
mtarArtifactName = strings.TrimSuffix(mtarArtifactName, ".mtar")
}
config.MtaDeploymentRepositoryURL += config.MtarGroup + "/" + mtarArtifactName + "/" + config.Version + "/" + fmt.Sprintf("%v-%v.%v", mtarArtifactName, config.Version, "mtar")
@@ -345,9 +348,10 @@ func addNpmBinToPath(utils mtaBuildUtils) error {
return nil
}
func getMtarName(config mtaBuildOptions, mtaYamlFile string, utils mtaBuildUtils) (string, error) {
func getMtarName(config mtaBuildOptions, mtaYamlFile string, utils mtaBuildUtils) (string, bool, error) {
mtarName := config.MtarName
isMtarNativelySuffixed := false
if len(mtarName) == 0 {
log.Entry().Debugf("mtar name not provided via config. Extracting from file \"%s\"", mtaYamlFile)
@@ -356,20 +360,27 @@ func getMtarName(config mtaBuildOptions, mtaYamlFile string, utils mtaBuildUtils
if err != nil {
log.SetErrorCategory(log.ErrorConfiguration)
return "", err
return "", isMtarNativelySuffixed, err
}
if len(mtaID) == 0 {
log.SetErrorCategory(log.ErrorConfiguration)
return "", fmt.Errorf("Invalid mtar ID. Was empty")
return "", isMtarNativelySuffixed, fmt.Errorf("Invalid mtar ID. Was empty")
}
log.Entry().Debugf("mtar name extracted from file \"%s\": \"%s\"", mtaYamlFile, mtaID)
mtarName = mtaID + ".mtar"
// there can be cases where the mtaId itself has the value com.myComapany.mtar , adding an extra .mtar causes .mtar.mtar
if !strings.HasSuffix(mtaID, ".mtar") {
mtarName = mtaID + ".mtar"
} else {
isMtarNativelySuffixed = true
mtarName = mtaID
}
}
return mtarName, nil
return mtarName, isMtarNativelySuffixed, nil
}

View File

@@ -366,13 +366,19 @@ func TestMtaBuildMtar(t *testing.T) {
utilsMock := newMtaBuildTestUtilsBundle()
utilsMock.AddFile("mta.yaml", []byte("ID: \"nameFromMtar\""))
assert.Equal(t, filepath.FromSlash("nameFromMtar.mtar"), _ignoreError(getMtarName(mtaBuildOptions{MtarName: ""}, "mta.yaml", utilsMock)))
assert.Equal(t, filepath.FromSlash("nameFromMtar.mtar"), _ignoreErrorForGetMtarName(getMtarName(mtaBuildOptions{MtarName: ""}, "mta.yaml", utilsMock)))
})
t.Run("mtar name from yaml with suffixed value", func(t *testing.T) {
utilsMock := newMtaBuildTestUtilsBundle()
utilsMock.AddFile("mta.yaml", []byte("ID: \"nameFromMtar.mtar\""))
assert.Equal(t, filepath.FromSlash("nameFromMtar.mtar"), _ignoreErrorForGetMtarName(getMtarName(mtaBuildOptions{MtarName: ""}, "mta.yaml", utilsMock)))
})
t.Run("mtar name from config", func(t *testing.T) {
utilsMock := newMtaBuildTestUtilsBundle()
utilsMock.AddFile("mta.yaml", []byte("ID: \"nameFromMtar\""))
assert.Equal(t, filepath.FromSlash("nameFromConfig.mtar"), _ignoreError(getMtarName(mtaBuildOptions{MtarName: "nameFromConfig.mtar"}, "mta.yaml", utilsMock)))
assert.Equal(t, filepath.FromSlash("nameFromConfig.mtar"), _ignoreErrorForGetMtarName(getMtarName(mtaBuildOptions{MtarName: "nameFromConfig.mtar"}, "mta.yaml", utilsMock)))
})
})
@@ -401,3 +407,7 @@ func TestMtaBuildMtar(t *testing.T) {
func _ignoreError(s string, e error) string {
return s
}
func _ignoreErrorForGetMtarName(s string, b bool, e error) string {
return s
}