Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DNM: feat(adv/validate): check for package config existing #989

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading