Skip to content

Commit

Permalink
Provide addonDescriptor to build System (#4914)
Browse files Browse the repository at this point in the history
  • Loading branch information
tiloKo authored May 2, 2024
1 parent 7d9fc6a commit 0aac696
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 28 deletions.
14 changes: 9 additions & 5 deletions cmd/abapEnvironmentAssemblePackages.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func runAbapEnvironmentAssemblePackages(config *abapEnvironmentAssemblePackagesO
return errors.Wrap(err, "Reading AddonDescriptor failed [Make sure abapAddonAssemblyKit...CheckCVs|CheckPV|ReserveNextPackages steps have been run before]")
}

builds, err := executeBuilds(addonDescriptor.Repositories, *connBuild, time.Duration(config.MaxRuntimeInMinutes)*time.Minute, time.Duration(config.PollIntervalsInMilliseconds)*time.Millisecond)
builds, err := executeBuilds(addonDescriptor, *connBuild, time.Duration(config.MaxRuntimeInMinutes)*time.Minute, time.Duration(config.PollIntervalsInMilliseconds)*time.Millisecond)
if err != nil {
return errors.Wrap(err, "Starting Builds for Repositories with reserved AAKaaS packages failed")
}
Expand Down Expand Up @@ -84,10 +84,10 @@ func runAbapEnvironmentAssemblePackages(config *abapEnvironmentAssemblePackagesO
return nil
}

func executeBuilds(repos []abaputils.Repository, conn abapbuild.Connector, maxRuntimeInMinutes time.Duration, pollInterval time.Duration) ([]buildWithRepository, error) {
func executeBuilds(addonDescriptor *abaputils.AddonDescriptor, conn abapbuild.Connector, maxRuntimeInMinutes time.Duration, pollInterval time.Duration) ([]buildWithRepository, error) {
var builds []buildWithRepository

for _, repo := range repos {
for _, repo := range addonDescriptor.Repositories {

buildRepo := buildWithRepository{
build: abapbuild.Build{
Expand All @@ -98,7 +98,7 @@ func executeBuilds(repos []abaputils.Repository, conn abapbuild.Connector, maxRu

if repo.Status == "P" {
buildRepo.repo.InBuildScope = true
err := buildRepo.start()
err := buildRepo.start(addonDescriptor)
if err != nil {
buildRepo.build.RunState = abapbuild.Failed
log.Entry().Error(err)
Expand Down Expand Up @@ -140,7 +140,7 @@ func (br *buildWithRepository) waitToBeFinished(maxRuntimeInMinutes time.Duratio
}
}

func (br *buildWithRepository) start() error {
func (br *buildWithRepository) start(addonDescriptor *abaputils.AddonDescriptor) error {
if br.repo.Name == "" || br.repo.Version == "" || br.repo.SpLevel == "" || br.repo.PackageType == "" || br.repo.PackageName == "" {
return errors.New("Parameters missing. Please provide software component name, version, sp-level, packagetype and packagename")
}
Expand All @@ -166,6 +166,10 @@ func (br *buildWithRepository) start() error {
ValueID: "PACKAGE_NAME_" + br.repo.PackageType,
Value: br.repo.PackageName,
},
{
ValueID: "addonDescriptor",
Value: addonDescriptor.AsReducedJson(),
},
},
}
if br.repo.Namespace != "" {
Expand Down
16 changes: 9 additions & 7 deletions cmd/abapEnvironmentAssemblePackages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,15 @@ func TestStartingInvalidInput(t *testing.T) {
conn := new(abapbuild.Connector)
conn.Client = client
conn.Header = make(map[string][]string)
var repos []abaputils.Repository
repo := abaputils.Repository{
Name: "RepoA",
Status: "P",
aD := abaputils.AddonDescriptor{
Repositories: []abaputils.Repository{
{
Name: "RepoA",
Status: "P",
},
},
}
repos = append(repos, repo)
builds, err := executeBuilds(repos, *conn, time.Duration(0*time.Second), time.Duration(1*time.Millisecond))
builds, err := executeBuilds(&aD, *conn, time.Duration(0*time.Second), time.Duration(1*time.Millisecond))
assert.NoError(t, err)
assert.Equal(t, 1, len(builds))
assert.Equal(t, abapbuild.Failed, builds[0].build.RunState)
Expand All @@ -95,7 +97,7 @@ func TestStep(t *testing.T) {

err := runAbapEnvironmentAssemblePackages(config, nil, autils, &mock.FilesMock{}, &client, cpe)
assert.NoError(t, err)
assert.Contains(t, cpe.abap.addonDescriptor, `"InBuildScope":false`)
assert.NotContains(t, cpe.abap.addonDescriptor, `"InBuildScope"`)
})
t.Run("abapEnvironmentAssemblePackages: build", func(t *testing.T) {
config := &abapEnvironmentAssemblePackagesOptions{
Expand Down
51 changes: 35 additions & 16 deletions pkg/abaputils/descriptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,34 +26,34 @@ import (
// AddonDescriptor contains fields about the addonProduct
type AddonDescriptor struct {
AddonProduct string `json:"addonProduct"`
AddonVersionYAML string `json:"addonVersion"`
AddonVersionYAML string `json:"addonVersion,omitempty"`
AddonVersion string `json:"addonVersionAAK"`
AddonSpsLevel string
AddonPatchLevel string
TargetVectorID string
TargetVectorID string `json:",omitempty"`
Repositories []Repository `json:"repositories"`
}

// Repository contains fields for the repository/component version
type Repository struct {
Name string `json:"name"`
UseClassicCTS bool `json:"useClassicCTS"`
Tag string `json:"tag"`
Branch string `json:"branch"`
CommitID string `json:"commitID"`
VersionYAML string `json:"version"`
UseClassicCTS bool `json:"useClassicCTS,omitempty"`
Tag string `json:"tag,omitempty"`
Branch string `json:"branch,omitempty"`
CommitID string `json:"commitID,omitempty"`
VersionYAML string `json:"version,omitempty"`
Version string `json:"versionAAK"`
AdditionalPiecelist string `json:"additionalPiecelist"`
PackageName string
PackageType string
AdditionalPiecelist string `json:"additionalPiecelist,omitempty"`
PackageName string `json:",omitempty"`
PackageType string `json:",omitempty"`
SpLevel string
PatchLevel string
PredecessorCommitID string
Status string
Namespace string
SarXMLFilePath string
Languages []string `json:"languages"`
InBuildScope bool
PredecessorCommitID string `json:",omitempty"`
Status string `json:",omitempty"`
Namespace string `json:",omitempty"`
SarXMLFilePath string `json:",omitempty"`
Languages []string `json:"languages,omitempty"`
InBuildScope bool `json:",omitempty"`
}

// ReadAddonDescriptorType is the type for ReadAddonDescriptor for mocking
Expand Down Expand Up @@ -182,3 +182,22 @@ func (me *AddonDescriptor) GetRepositoriesInBuildScope() []Repository {
}
return RepositoriesInBuildScope
}

func (me *AddonDescriptor) AsReducedJson() string {
input := AddonDescriptor{
AddonProduct: me.AddonProduct,
AddonVersion: me.AddonVersion,
AddonSpsLevel: me.AddonSpsLevel,
AddonPatchLevel: me.AddonPatchLevel,
}
for _, repo := range me.Repositories {
input.Repositories = append(input.Repositories, Repository{
Name: repo.Name,
Version: repo.Version,
SpLevel: repo.SpLevel,
PatchLevel: repo.PatchLevel,
})
}

return input.AsJSONstring()
}
3 changes: 3 additions & 0 deletions pkg/abaputils/descriptor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ func TestAddonDescriptorNew(t *testing.T) {
assert.Equal(t, "/DMO/REPO_B", repos[0].Name)
})

t.Run("AsReducedJson", func(t *testing.T) {
assert.NotContains(t, "commitID", addonDescriptor.AsReducedJson())
})
}

var TestAddonDescriptorYAML = `---
Expand Down

0 comments on commit 0aac696

Please sign in to comment.