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

Fail On Duplicate Config Names #1372

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

paulgibert
Copy link

Fixes #1599

  • Updated wolfictl lint to fail if a duplicate package config name is encountered.
  • Added a unit test to melange_test.go for duplicate package config names

Steps to test:

  1. See that lint succeeds on a valid repo:
git clone https://github.com/wolfi-dev/os.git
cd os
wolfictl lint -s error

# Should succeed
  1. See that introducing duplicate configs results in an error:
# From inside os/

echo "package:\n  name: duplicate\n  version: 1.2.3" > duplicate1.yaml
cp duplicate1.yaml duplicate2.yaml
wolfictl lint -s error

# Example output: 2024/12/13 11:44:33 ERRO Package config names must be unique. Found duplicate 'duplicate'

The check happens in pkg/melange as this is where the duplicates were ignored as pointed out in #1599. An alternative but more complex solution would be to add a new lint rule. I didn't go that route because it would require a notable ABI change.

#first-golang-pr (let's go)

@priyawadhwa

@paulgibert paulgibert changed the title Block Duplicate Config Names Fail On Duplicate Config Names Dec 13, 2024
@@ -0,0 +1,3 @@
package:
name: foo
Copy link
Member

Choose a reason for hiding this comment

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

I think we might also want to fail if .package.name is not the same as the filename.

These are potentially different/separate issues, but it does I think violate some assumptions we've made, and is worth avoiding.

If we have that check, we also get uniqueness "for free" since there can't be two foo.yamls

Copy link
Author

Choose a reason for hiding this comment

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

If the .package.name field must match the filename, couldn't you make an argument that the field is redundant and should be removed?

// check that the package config name is unique
_, exists := p[name]
if exists {
return p, fmt.Errorf("Package config names must be unique. Found duplicate '%s'", name)
Copy link
Member

Choose a reason for hiding this comment

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

It might be helpful to include the file names for the duplicate packages in the error message so it's easier to fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants