Skip to content

Commit

Permalink
feat(adv/validate): check for package config existing
Browse files Browse the repository at this point in the history
Signed-off-by: Dan Luhring <[email protected]>
  • Loading branch information
luhring committed Jun 21, 2024
1 parent 1de2ce8 commit baa92a1
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions pkg/advisory/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ func Validate(ctx context.Context, opts ValidateOptions) error {
)
errs = append(errs, errorhelpers.LabelError("basic validation failure(s)", errors.Join(documentErrs...)))

if opts.PackageConfigurations != nil {
errs = append(errs, opts.validatePackageConfigurationExistence(ctx))
}

if opts.BaseAdvisoryDocs != nil {
diff := IndexDiff(opts.BaseAdvisoryDocs, opts.AdvisoryDocs)
errs = append(errs, opts.validateIndexDiff(ctx, diff))
Expand Down Expand Up @@ -398,6 +402,32 @@ func (opts ValidateOptions) validateAliasSetCompleteness(ctx context.Context) er
return errorhelpers.LabelError("alias set completeness validation failure(s)", errors.Join(errs...))
}

// validatePackageConfigurationExistence validates that the package described by each
// advisory document currently has a build definition in the packages repo.
func (opts ValidateOptions) validatePackageConfigurationExistence(ctx context.Context) error {
log := clog.FromContext(ctx)
log.Info("validating package configuration existence")

advisoryDocs := opts.AdvisoryDocs.Select().Configurations()

var errs []error

for _, doc := range advisoryDocs {
if len(opts.SelectedPackages) > 0 {
if _, ok := opts.SelectedPackages[doc.Name()]; !ok {
// Skip this document, since it's not in the set of selected packages.
return nil
}
}

if _, ok := opts.distroPackageMap[doc.Name()]; !ok {
errs = append(errs, fmt.Errorf("package %q does not have a build definition", doc.Name()))
}
}

return errorhelpers.LabelError("package configuration existence validation failure(s)", errors.Join(errs...))
}

func (opts ValidateOptions) validateIndexDiff(ctx context.Context, diff IndexDiffResult) error {
log := clog.FromContext(ctx)
log.Info("validating index diff", "diffIsZero", diff.IsZero())
Expand Down

0 comments on commit baa92a1

Please sign in to comment.