Skip to content

Commit

Permalink
add support to check subpackage naming standard
Browse files Browse the repository at this point in the history
Signed-off-by: Dentrax <[email protected]>
  • Loading branch information
Dentrax committed Nov 1, 2024
1 parent 21870b1 commit c6e413e
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pkg/lint/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{"", ".", "-", "_"}
Expand Down
18 changes: 18 additions & 0 deletions pkg/lint/rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
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

0 comments on commit c6e413e

Please sign in to comment.