Skip to content

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

Open
chaospuppy wants to merge 15 commits into
zarf-dev:mainfrom
chaospuppy:4598-lint-without-flavor
Open

feat(lint): add --all-variants flag for lint#4783
chaospuppy wants to merge 15 commits 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 canceled.

Name Link
🔨 Latest commit 05b19b7
🔍 Latest deploy log https://app.netlify.com/projects/zarf-docs/deploys/6a5a6cebcdcd98000903e9ec

Signed-off-by: Tim Seagren <timseagren@defenseunicorns.com>
… filter our error types from a joined error

Signed-off-by: Tim Seagren <timseagren@defenseunicorns.com>
@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 85.45455% with 8 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/pkg/packager/load/import.go 77.77% 2 Missing and 2 partials ⚠️
src/pkg/packager/generate.go 0.00% 3 Missing ⚠️
src/cmd/dev.go 75.00% 1 Missing ⚠️
Files with missing lines Coverage Δ
src/internal/api/v1alpha1/validate.go 90.14% <100.00%> (+0.43%) ⬆️
src/pkg/packager/lint.go 63.63% <100.00%> (+1.13%) ⬆️
src/pkg/packager/load/load.go 72.13% <100.00%> (+1.44%) ⬆️
src/pkg/utils/oci_artifacts.go 53.93% <100.00%> (+0.52%) ⬆️
src/cmd/dev.go 38.88% <75.00%> (+0.16%) ⬆️
src/pkg/packager/generate.go 0.00% <0.00%> (ø)
src/pkg/packager/load/import.go 53.16% <77.77%> (-0.10%) ⬇️
🚀 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
Comment thread src/pkg/packager/load/load.go
Comment thread src/internal/api/v1alpha1/validate.go Outdated
@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

}

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.

…pping name uniqueness checks, update unit tests

Signed-off-by: Tim Seagren <timseagren@defenseunicorns.com>
Signed-off-by: Tim Seagren <timseagren@defenseunicorns.com>

@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,
}

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

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.

…e when allVariants, update unit tests to cover new behavior

Signed-off-by: Tim Seagren <timseagren@defenseunicorns.com>
@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

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In progress

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