-
Notifications
You must be signed in to change notification settings - Fork 583
/
abapAddonAssemblyKitCheckCVs.go
75 lines (63 loc) · 3.68 KB
/
abapAddonAssemblyKitCheckCVs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package cmd
import (
"github.com/SAP/jenkins-library/pkg/abap/aakaas"
abapbuild "github.com/SAP/jenkins-library/pkg/abap/build"
"github.com/SAP/jenkins-library/pkg/abaputils"
"github.com/SAP/jenkins-library/pkg/log"
"github.com/SAP/jenkins-library/pkg/telemetry"
"github.com/pkg/errors"
)
func abapAddonAssemblyKitCheckCVs(config abapAddonAssemblyKitCheckCVsOptions, telemetryData *telemetry.CustomData, cpe *abapAddonAssemblyKitCheckCVsCommonPipelineEnvironment) {
utils := aakaas.NewAakBundle()
if err := runAbapAddonAssemblyKitCheckCVs(&config, telemetryData, &utils, cpe); err != nil {
log.Entry().WithError(err).Fatal("step execution failed")
}
}
func runAbapAddonAssemblyKitCheckCVs(config *abapAddonAssemblyKitCheckCVsOptions, telemetryData *telemetry.CustomData, utils *aakaas.AakUtils, cpe *abapAddonAssemblyKitCheckCVsCommonPipelineEnvironment) error {
log.Entry().Info("╔══════════════════════════════╗")
log.Entry().Info("║ abapAddonAssemblyKitCheckCVs ║")
log.Entry().Info("╚══════════════════════════════╝")
conn := new(abapbuild.Connector)
if err := conn.InitAAKaaS(config.AbapAddonAssemblyKitEndpoint, config.Username, config.Password, *utils, "", config.AbapAddonAssemblyKitCertificateFile, config.AbapAddonAssemblyKitCertificatePass); err != nil {
return err
}
log.Entry().Infof("Reading Product Version Information from addonDescriptor (aka addon.yml) file: %s", config.AddonDescriptorFileName)
addonDescriptor, err := (*utils).ReadAddonDescriptor(config.AddonDescriptorFileName)
if err != nil {
return err
}
for i, repo := range addonDescriptor.Repositories {
componentVersion := new(aakaas.ComponentVersion)
if err := componentVersion.ConstructComponentVersion(addonDescriptor.Repositories[i], *conn); err != nil {
return err
}
if err := componentVersion.Validate(); err != nil {
return err
}
componentVersion.CopyVersionFieldsToRepo(&addonDescriptor.Repositories[i])
log.Entry().Infof("Using cCTS %t", repo.UseClassicCTS)
log.Entry().Infof("CommitId %s", repo.CommitID)
if !repo.UseClassicCTS && repo.CommitID == "" {
return errors.Errorf("CommitID missing in repo '%s' of the addon.yml", repo.Name)
}
}
// now Software Component Versions fields are valid, but maybe Product Version was checked before, so copy that part from CPE
// we don't care for errors
// scenario 1: config.AddonDescriptor is empty since checkCVs is the first step in the pipeline, then the empty result is fine anyway
// scenario 2: for some reason config.AddonDescriptor is corrupt - then we insert the valid data but delete the repositories which will ensure issue is found later on
addonDescriptorCPE, _ := abaputils.ConstructAddonDescriptorFromJSON([]byte(config.AddonDescriptor))
if len(addonDescriptorCPE.AddonProduct) == 0 {
log.Entry().Info("No Product Version information present yet in the addonDescriptor of CommonPipelineEnvironment")
} else {
log.Entry().Infof("Information for Product Version %s taken from addonDescriptor of CommonPipelineEnvironment", addonDescriptorCPE.AddonProduct)
}
addonDescriptorCPE.SetRepositories(addonDescriptor.Repositories)
cpe.abap.addonDescriptor = string(addonDescriptorCPE.AsJSON())
log.Entry().Info("Wrote addonDescriptor to CommonPipelineEnvironment")
return nil
}
// take the product part from CPE and the repositories part from the YAML file
func combineYAMLRepositoriesWithCPEProduct(addonDescriptor abaputils.AddonDescriptor, addonDescriptorFromCPE abaputils.AddonDescriptor) abaputils.AddonDescriptor {
addonDescriptorFromCPE.Repositories = addonDescriptor.Repositories
return addonDescriptorFromCPE
}