Skip to content

Commit c6e413e

Browse files
committed
add support to check subpackage naming standard
Signed-off-by: Dentrax <[email protected]>
1 parent 21870b1 commit c6e413e

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

pkg/lint/rules.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,15 @@ var AllRules = func(l *Linter) Rules { //nolint:gocyclo
524524
return fmt.Errorf("package is version streamed but %s=${{package.full-version}} is missing on dependencies.provides", packageName)
525525
}
526526

527+
// Any subpackage that contains the package name, should follow `${{package.name}}-xyz` format.
528+
for _, s := range c.Subpackages {
529+
if strings.Contains(s.Name, c.Package.Name) {
530+
if !strings.HasPrefix(s.Name, c.Package.Name) {
531+
return fmt.Errorf("subpackage %s should be in format ${{package.name}}-XYZ-SUBPACKAGENAME for a valid version stream", s.Name)
532+
}
533+
}
534+
}
535+
527536
if c.Update.Enabled && !c.Update.Manual && c.Update.GitHubMonitor != nil {
528537
prefixesToCheck := []string{"", "v", packageName, "release", strings.ReplaceAll(packageName, "-fips", ""), c.Update.GitHubMonitor.StripPrefix}
529538
separators := []string{"", ".", "-", "_"}

pkg/lint/rules_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,24 @@ func TestLinter_Rules(t *testing.T) {
469469
wantErr: false,
470470
matches: 1,
471471
},
472+
{
473+
file: "version-stream-wrong-subpackage-naming-1.2.yaml",
474+
minSeverity: SeverityWarning,
475+
want: EvalResult{
476+
File: "version-stream-wrong-subpackage-naming-1.2",
477+
Errors: EvalRuleErrors{
478+
{
479+
Rule: Rule{
480+
Name: "valid-version-stream",
481+
Severity: SeverityWarning,
482+
},
483+
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)"),
484+
},
485+
},
486+
},
487+
wantErr: false,
488+
matches: 1,
489+
},
472490
{
473491
file: "valid-update-schedule.yaml",
474492
minSeverity: SeverityWarning,
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package:
2+
name: version-stream-wrong-subpackage-naming-1.2
3+
version: 1.2.3
4+
epoch: 0
5+
description: "a version-streamed package with no dependencies.provides"
6+
7+
pipeline:
8+
- uses: fetch
9+
with:
10+
uri: https://test.com/version-stream-missing-provides/${{package.version}}.tar.gz
11+
expected-sha256: ab5a03176ee106d3f0fa90e381da478ddae405918153cca248e682cd0c4a2269
12+
13+
subpackages:
14+
- name: this-is-subpackage-of-version-stream-wrong-subpackage-naming-1.2
15+
description: "a package with incorrect subpackage prefix"
16+
pipeline:
17+
- runs: exit 0
18+
19+
test:
20+
pipeline:
21+
- runs: "echo 'test'"
22+
23+
update:
24+
enabled: true

0 commit comments

Comments
 (0)