Skip to content

feat(lint): add --all-variants flag for lint - #4783

Closed
chaospuppy wants to merge 0 commit into
zarf-dev:mainfrom
chaospuppy:4598-lint-without-flavor
Closed

feat(lint): add --all-variants flag for lint#4783
chaospuppy wants to merge 0 commit into
zarf-dev:mainfrom
chaospuppy:4598-lint-without-flavor

Conversation

@chaospuppy

Copy link
Copy Markdown
Contributor

Description

This PR adds an --all-variants flag to the zarf dev lint command that will result in all variants of a zarf package being linted, even if there are multiple flavors present in the package definition. Previously, it was required that users specify a --flavor flag in order to pass validation. This is done to make linting zarf package in CI or in situations where you would otherwise not want to/could not know which flavor you wanted to lint specifically, and wished to validate the entire package.

Related Issue

Fixes #4598

Checklist before merging

@netlify

netlify Bot commented Apr 3, 2026

Copy link
Copy Markdown

Deploy Preview for zarf-docs ready!

Name Link
🔨 Latest commit dcbc628
🔍 Latest deploy log https://app.netlify.com/projects/zarf-docs/deploys/6a965ca876d95a000875127b
😎 Deploy Preview https://deploy-preview-4783--zarf-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@chaospuppy
chaospuppy force-pushed the 4598-lint-without-flavor branch from dbc0447 to e8ffd82 Compare April 3, 2026 23:14
@chaospuppy
chaospuppy marked this pull request as ready for review April 10, 2026 21:45
@chaospuppy
chaospuppy requested review from a team as code owners April 10, 2026 21:45
@codecov

codecov Bot commented Apr 10, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 77.46479% with 16 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/cmd/dev.go 25.00% 9 Missing ⚠️
src/pkg/packager/load/import.go 77.77% 2 Missing and 2 partials ⚠️
src/pkg/packager/generate.go 0.00% 3 Missing ⚠️
Files with missing lines Coverage Δ
src/internal/api/v1alpha1/validate.go 90.14% <100.00%> (+0.43%) ⬆️
src/pkg/packager/lint.go 68.42% <100.00%> (+0.85%) ⬆️
src/pkg/packager/load/load.go 75.00% <100.00%> (+1.15%) ⬆️
src/pkg/utils/oci_artifacts.go 53.93% <100.00%> (+0.52%) ⬆️
src/pkg/packager/generate.go 0.00% <0.00%> (ø)
src/pkg/packager/load/import.go 55.75% <77.77%> (-0.10%) ⬇️
src/cmd/dev.go 36.83% <25.00%> (+<0.01%) ⬆️

... and 2 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@chaospuppy
chaospuppy force-pushed the 4598-lint-without-flavor branch 3 times, most recently from 815d65f to b771fe5 Compare April 13, 2026 17:15

@AustinAbro321 AustinAbro321 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a nice win for linting, thanks! A few comments

Comment thread src/pkg/packager/load/load.go Outdated
Comment thread src/pkg/packager/load/load.go
Comment thread src/internal/api/v1alpha1/validate.go
@github-project-automation github-project-automation Bot moved this to In progress in Zarf Apr 24, 2026
@chaospuppy
chaospuppy force-pushed the 4598-lint-without-flavor branch from db6ce34 to a8d6f9d Compare May 1, 2026 20:59
Comment thread src/pkg/utils/error.go Outdated
@chaospuppy
chaospuppy requested a review from AustinAbro321 May 8, 2026 16:23
components:
- name: duplicate
only:
flavor: first-flavor

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to test importing a child components with flavors here

Comment thread src/pkg/packager/load/import.go Outdated
}

func compatibleComponent(c v1alpha1.ZarfComponent, arch, flavor string) bool {
func compatibleComponent(c v1alpha1.ZarfComponent, arch, flavor string, allVariants bool) bool {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we'll also want all variants of architectures.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I interpreted this to mean we want allVariants to b evaluated within compatibleComponent for both flavor and arch checks, but I also see how it might be better to leave the function unchanged and instead do something like if !compatibleComponent && !allVariants.

Comment thread src/internal/api/v1alpha1/validate.go Outdated
for _, component := range pkg.Components {
// ensure component name is unique
if _, ok := uniqueComponentNames[component.Name]; ok {
if _, ok := uniqueComponentNames[component.Name]; ok && !opts.SkipComponentNameUniquenessValidation {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is too broad, let's change it so we only allow duplicate component names when the only blocks are not equal

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we can have any number of components with duplicate names when this validation option is true, I needed to map component names to all of the only blocks associated with those component names. Let me know if I could simplify further, but I also didn't want to run reflect.DeepEqual unless we enabled SkipComponentNameUniquenessValidation.

@AustinAbro321 AustinAbro321 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies for the delay in review. A few comments

Comment thread src/pkg/packager/load/load.go Outdated
Comment on lines +119 to +123
validationOpts := internalv1alpha1.ValidateOpts{}

if allVariants {
validationOpts.SkipComponentNameUniquenessValidation = true
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
validationOpts := internalv1alpha1.ValidateOpts{}
if allVariants {
validationOpts.SkipComponentNameUniquenessValidation = true
}
validationOpts := internalv1alpha1.ValidateOpts{
SkipComponentNameUniquenessValidation: allVariants,
}

}
if len(found) == 0 {
return v1alpha1.ZarfPackage{}, fmt.Errorf("no compatible component named %s found", name)
} else if len(found) > 1 {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll now need to handle multiple components with the same name being found. Add a test for this as well

Comment thread src/internal/api/v1alpha1/validate.go Outdated
// only check if only block is duplicated if we're skipping name uniqueness checks
if opts.SkipComponentNameUniquenessValidation {
duplicateOnly = slices.ContainsFunc(uniqueComponentNames[component.Name], func(o v1alpha1.ZarfComponentOnlyTarget) bool {
return reflect.DeepEqual(o, component.Only)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We generally avoid reflect, I'd do something like this instead

func onlyTargetsEqual(a, b v1alpha1.ZarfComponentOnlyTarget) bool {
    return a.LocalOS == b.LocalOS && a.Flavor == b.Flavor &&
        a.Cluster.Architecture == b.Cluster.Architecture &&
        slices.Equal(a.Cluster.Distros, b.Cluster.Distros)
}

Comment thread src/pkg/packager/load/load.go Outdated
type DefinitionOptions struct {
Flavor string
Flavor string
// All variants will ignore Flavor and will return all components, regardless of flavor

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// All variants will ignore Flavor and will return all components, regardless of flavor
// All variants will ignore Flavor & architecture and will return all components. Mutually exclusive with flavor.

@chaospuppy

Copy link
Copy Markdown
Contributor Author

@AustinAbro321 sorry for the delay on my end here, I've addressed the feedback you provided above. Setting allVariants will now result in multiple components of the same name but different only being imported.

@AustinAbro321 AustinAbro321 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've not done a full review, but asking that this be in line with #5020

Comment thread src/pkg/packager/load/load.go Outdated
Flavor string
Flavor string
// All variants will ignore Flavor & architecture and will return all components. Mutually exclusive with flavor.
AllVariants bool

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is similar work going on in #5020 src/pkg/packager/load/load.go. Instead of a boolean, let's copy over the variant Dimension construct, that way users can selectively add the filters that they want.

@chaospuppy
chaospuppy force-pushed the 4598-lint-without-flavor branch from cf56541 to c78dd6b Compare September 1, 2026 04:43
@chaospuppy chaospuppy closed this Sep 1, 2026
@chaospuppy
chaospuppy force-pushed the 4598-lint-without-flavor branch from c78dd6b to dcbc628 Compare September 1, 2026 05:03
@github-project-automation github-project-automation Bot moved this from In progress to Done in Zarf Sep 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

zarf dev lint fails if a flavor is not specified for a flavored package

2 participants