Skip to content

Commit

Permalink
shorten commits to common length prior compare (#4859)
Browse files Browse the repository at this point in the history
* shorten commits to common length prior compare

* remove obsolete unit tests

* some test

* 2nd try

* fix old wrong unit test
  • Loading branch information
tiloKo authored Mar 8, 2024
1 parent 09cd271 commit 2c69c4c
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 37 deletions.
60 changes: 38 additions & 22 deletions cmd/abapAddonAssemblyKitReserveNextPackages.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,37 +100,53 @@ func checkCommitID(pckgWR []aakaas.PackageWithRepository, i int, checkFailure er
}

func checkCommitIDSameAsGiven(pckgWR []aakaas.PackageWithRepository, i int, checkFailure error) error {
//Ensure for Packages with Status R that CommitID of package = the one from addon.yml, beware of short commitID in addon.yml
addonYAMLcommitIDLength := len(pckgWR[i].Repo.CommitID)
if len(pckgWR[i].Package.CommitID) < addonYAMLcommitIDLength {
checkFailure = errors.New("Provided CommitIDs have wrong length: " + pckgWR[i].Repo.CommitID + "(addon.yml) longer than the one from AAKaaS " + pckgWR[i].Package.CommitID)
log.Entry().WithError(checkFailure).Error(" => Check failure: to be corrected in addon.yml prior next execution")
//Ensure for Packages with Status R that CommitID of package = the one from addon.yml, beware of short commitID in addon.yml (and AAKaaS had due to a bug some time also short commid IDs)
AAKaaSCommitId := pckgWR[i].Package.CommitID
AddonYAMLCommitId := pckgWR[i].Repo.CommitID

var commitIdLength int
//determine shortes commitID length
if len(AAKaaSCommitId) >= len(AddonYAMLCommitId) {
commitIdLength = len(AddonYAMLCommitId)
} else {
packageCommitIDsubsting := pckgWR[i].Package.CommitID[0:addonYAMLcommitIDLength]
if pckgWR[i].Repo.CommitID != packageCommitIDsubsting {
log.Entry().Error("package " + pckgWR[i].Package.PackageName + " was already build but with commit " + pckgWR[i].Package.CommitID + ", not with " + pckgWR[i].Repo.CommitID)
log.Entry().Error("If you want to build a new package make sure to increase the dotted-version-string in addon.yml - current value: " + pckgWR[i].Package.VersionYAML)
log.Entry().Error("If you do NOT want to build a new package enter the commitID " + pckgWR[i].Package.CommitID + " for software component " + pckgWR[i].Repo.Name + " in addon.yml")
checkFailure = errors.New("commit of already released package does not match with addon.yml")
log.Entry().WithError(checkFailure).Error(" => Check failure: to be corrected in addon.yml prior next execution")
}
commitIdLength = len(AAKaaSCommitId)
}

//shorten both to common length
AAKaaSCommitId = AAKaaSCommitId[0:commitIdLength]
AddonYAMLCommitId = AddonYAMLCommitId[0:commitIdLength]

if AddonYAMLCommitId != AAKaaSCommitId {
log.Entry().Error("package " + pckgWR[i].Package.PackageName + " was already build but with commit " + pckgWR[i].Package.CommitID + ", not with " + pckgWR[i].Repo.CommitID)
log.Entry().Error("If you want to build a new package make sure to increase the dotted-version-string in addon.yml - current value: " + pckgWR[i].Package.VersionYAML)
log.Entry().Error("If you do NOT want to build a new package enter the commitID " + pckgWR[i].Package.CommitID + " for software component " + pckgWR[i].Repo.Name + " in addon.yml")
checkFailure = errors.New("commit of already released package does not match with addon.yml")
log.Entry().WithError(checkFailure).Error(" => Check failure: to be corrected in addon.yml prior next execution")
}
return checkFailure
}

func checkCommitIDNotSameAsPrevious(pckgWR []aakaas.PackageWithRepository, i int, checkFailure error) error {
//Check for newly reserved packages which are to be build that CommitID from addon.yml != PreviousCommitID [this will result in an error as no delta can be calculated]
addonYAMLcommitIDLength := len(pckgWR[i].Repo.CommitID)
if len(pckgWR[i].Package.PredecessorCommitID) < addonYAMLcommitIDLength {
checkFailure = errors.New("Provided CommitIDs have wrong length: " + pckgWR[i].Repo.CommitID + "(addon.yml) longer than the one from AAKaaS " + pckgWR[i].Package.CommitID)
log.Entry().WithError(checkFailure).Error(" => Check failure: to be corrected in addon.yml prior next execution")
AAKaaSPreviousCommitId := pckgWR[i].Package.PredecessorCommitID
AddonYAMLCommitId := pckgWR[i].Repo.CommitID

var commitIdLength int
//determine shortes commitID length
if len(AAKaaSPreviousCommitId) >= len(AddonYAMLCommitId) {
commitIdLength = len(AddonYAMLCommitId)
} else {
packagePredecessorCommitIDsubsting := pckgWR[i].Package.PredecessorCommitID[0:addonYAMLcommitIDLength]
if pckgWR[i].Repo.CommitID == packagePredecessorCommitIDsubsting {
checkFailure = errors.New("CommitID of package " + pckgWR[i].Package.PackageName + " is the same as the one of the predecessor package. Make sure to change both the dotted-version-string AND the commitID in addon.yml")
log.Entry().WithError(checkFailure).Error(" => Check failure: to be corrected in addon.yml prior next execution")
}
commitIdLength = len(AAKaaSPreviousCommitId)
}

AAKaaSPreviousCommitId = AAKaaSPreviousCommitId[0:commitIdLength]
AddonYAMLCommitId = AddonYAMLCommitId[0:commitIdLength]

if AddonYAMLCommitId == AAKaaSPreviousCommitId {
checkFailure = errors.New("CommitID of package " + pckgWR[i].Package.PackageName + " is the same as the one of the predecessor package. Make sure to change both the dotted-version-string AND the commitID in addon.yml")
log.Entry().WithError(checkFailure).Error(" => Check failure: to be corrected in addon.yml prior next execution")
}

return checkFailure
}

Expand Down
30 changes: 15 additions & 15 deletions cmd/abapAddonAssemblyKitReserveNextPackages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,19 +163,28 @@ func TestCopyFieldsToRepositoriesPackage(t *testing.T) {
assert.NoError(t, err)
})

t.Run("test copyFieldsToRepositories Planned error with predecessorcommitID same as commitID", func(t *testing.T) {
t.Run("test copyFieldsToRepositories Planned success with predecessorcommitI short AAKaaS", func(t *testing.T) {
pckgWR[0].Package.Status = aakaas.PackageStatusPlanned
pckgWR[0].Package.PredecessorCommitID = pckgWR[0].Repo.CommitID
pckgWR[0].Package.PredecessorCommitID = "predecessor"
pckgWR[0].Repo.CommitID = "something40charslongxxxxxxxxxxxxxxxxxxxx"
pckgWR[0].Package.CommitID = "something40charslongxxxxxxxxxxxxxxxxxxxx"
_, err := checkAndCopyFieldsToRepositories(pckgWR)
assert.Error(t, err)
assert.NoError(t, err)
})

t.Run("test copyFieldsToRepositories Planned error with too long commitID in addon.yml", func(t *testing.T) {
t.Run("test copyFieldsToRepositories Planned success with predecessorcommitID short addon.yml", func(t *testing.T) {
pckgWR[0].Package.Status = aakaas.PackageStatusPlanned
pckgWR[0].Package.PredecessorCommitID = "something40charslongPREDECESSORyyyyyyyyy"
pckgWR[0].Repo.CommitID = "something40charslongxxxxxxxxxxxxxxxxxxxxtoolong"
pckgWR[0].Package.PredecessorCommitID = "predecessor"
pckgWR[0].Repo.CommitID = "successor"
pckgWR[0].Package.CommitID = "successorANDsomemore"
_, err := checkAndCopyFieldsToRepositories(pckgWR)
assert.NoError(t, err)
})

t.Run("test copyFieldsToRepositories Planned error with predecessorcommitID same as commitID", func(t *testing.T) {
pckgWR[0].Package.Status = aakaas.PackageStatusPlanned
pckgWR[0].Repo.CommitID = "something40charslongxxxxxxxxxxxxxxxxxxxx"
pckgWR[0].Package.PredecessorCommitID = pckgWR[0].Repo.CommitID
pckgWR[0].Package.CommitID = "something40charslongxxxxxxxxxxxxxxxxxxxx"
_, err := checkAndCopyFieldsToRepositories(pckgWR)
assert.Error(t, err)
Expand All @@ -198,15 +207,6 @@ func TestCopyFieldsToRepositoriesPackage(t *testing.T) {
_, err := checkAndCopyFieldsToRepositories(pckgWR)
assert.Error(t, err)
})

t.Run("test copyFieldsToRepositories Released error with too long commitID in addon.yml", func(t *testing.T) {
pckgWR[0].Package.Status = aakaas.PackageStatusReleased
pckgWR[0].Package.PredecessorCommitID = "" //released packages do not have this attribute
pckgWR[0].Repo.CommitID = "something40charslongxxxxxxxxxxxxxxxxxxxxtoolong"
pckgWR[0].Package.CommitID = "something40charslongxxxxxxxxxxxxxxxxxxxO"
_, err := checkAndCopyFieldsToRepositories(pckgWR)
assert.Error(t, err)
})
}

// ********************* Test reserveNext *******************
Expand Down

0 comments on commit 2c69c4c

Please sign in to comment.