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

lint: version stream #1062

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
add support to check subpackage naming standard
Signed-off-by: Dentrax <furkan.turkal@chainguard.dev>
  • Loading branch information
Dentrax committed Nov 1, 2024
commit 00378f460bec018e589e1c9122a134b5124e34bc
9 changes: 9 additions & 0 deletions pkg/lint/rules.go
Original file line number Diff line number Diff line change
@@ -524,6 +524,15 @@ var AllRules = func(l *Linter) Rules { //nolint:gocyclo
return fmt.Errorf("package is version streamed but %s=${{package.full-version}} is missing on dependencies.provides", packageName)
}

// Any subpackage that contains the package name, should follow `${{package.name}}-xyz` format.
for _, s := range c.Subpackages {
if strings.Contains(s.Name, c.Package.Name) {
if !strings.HasPrefix(s.Name, c.Package.Name) {
return fmt.Errorf("subpackage %s should be in format ${{package.name}}-XYZ-SUBPACKAGENAME for a valid version stream", s.Name)
}
}
}

if c.Update.Enabled && !c.Update.Manual && c.Update.GitHubMonitor != nil {
prefixesToCheck := []string{"", "v", packageName, "release", strings.ReplaceAll(packageName, "-fips", ""), c.Update.GitHubMonitor.StripPrefix}
separators := []string{"", ".", "-", "_"}
20 changes: 20 additions & 0 deletions pkg/lint/rules_test.go
Original file line number Diff line number Diff line change
@@ -469,6 +469,24 @@ func TestLinter_Rules(t *testing.T) {
wantErr: false,
matches: 1,
},
{
file: "version-stream-wrong-subpackage-naming-1.2.yaml",
minSeverity: SeverityWarning,
want: EvalResult{
File: "version-stream-wrong-subpackage-naming-1.2",
Errors: EvalRuleErrors{
{
Rule: Rule{
Name: "valid-version-stream",
Severity: SeverityWarning,
},
Error: fmt.Errorf("[valid-version-stream]: package is version streamed but version-stream-wrong-subpackage-naming=${{package.full-version}} is missing on dependencies.provides (WARNING)"),
},
},
},
wantErr: false,
matches: 1,
},
{
file: "valid-update-schedule.yaml",
minSeverity: SeverityWarning,
@@ -484,6 +502,8 @@ func TestLinter_Rules(t *testing.T) {
},
},
},
wantErr: false,
matches: 1,
},
{
file: "version-stream-mismatch-version-1.2.yaml",
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package:
name: version-stream-wrong-subpackage-naming-1.2
version: 1.2.3
epoch: 0
description: "a version-streamed package with no dependencies.provides"

pipeline:
- uses: fetch
with:
uri: https://test.com/version-stream-missing-provides/${{package.version}}.tar.gz
expected-sha256: ab5a03176ee106d3f0fa90e381da478ddae405918153cca248e682cd0c4a2269

subpackages:
- name: this-is-subpackage-of-version-stream-wrong-subpackage-naming-1.2
description: "a package with incorrect subpackage prefix"
pipeline:
- runs: exit 0

test:
pipeline:
- runs: "echo 'test'"

update:
enabled: true