Skip to content

Commit 119af86

Browse files
a-crateclaude
andauthored
feat(config): add annotations field to subpackages (#2582)
Mirrors the existing top-level Package.Annotations, letting each subpackage carry its own independent annotations map through YAML serialization into the .melange.yaml embedded in the APK. Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent ef24ddf commit 119af86

5 files changed

Lines changed: 43 additions & 0 deletions

File tree

pkg/build/package.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ func pkgFromSub(sub *config.Subpackage) *config.Package {
8282
Options: sub.Options,
8383
Scriptlets: sub.Scriptlets,
8484
Description: sub.Description,
85+
Annotations: sub.Annotations,
8586
URL: sub.URL,
8687
Commit: sub.Commit,
8788
}

pkg/config/config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,8 @@ type Subpackage struct {
848848
Scriptlets *Scriptlets `json:"scriptlets,omitempty" yaml:"scriptlets,omitempty"`
849849
// Optional: The human readable description of the subpackage
850850
Description string `json:"description,omitempty" yaml:"description,omitempty"`
851+
// Optional: Annotations for this subpackage
852+
Annotations map[string]string `json:"annotations,omitempty" yaml:"annotations,omitempty"`
851853
// Optional: The URL to the package's homepage
852854
URL string `json:"url,omitempty" yaml:"url,omitempty"`
853855
// Optional: The git commit of the subpackage build configuration
@@ -1566,6 +1568,7 @@ func replaceSubpackage(r *strings.Replacer, detectedCommit string, in Subpackage
15661568
Options: in.Options,
15671569
Scriptlets: replaceScriptlets(r, in.Scriptlets),
15681570
Description: r.Replace(in.Description),
1571+
Annotations: replaceMap(r, in.Annotations),
15691572
URL: r.Replace(in.URL),
15701573
Commit: replaceCommit(detectedCommit, in.Commit),
15711574
Checks: in.Checks,

pkg/config/config_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,35 @@ package:
496496
require.Equal(t, "python", cfg.Package.Annotations["cgr.dev/ecosystem"])
497497
}
498498

499+
func Test_subpackageAnnotations(t *testing.T) {
500+
ctx := slogtest.Context(t)
501+
fp := filepath.Join(os.TempDir(), "melange-test-subpackageAnnotations")
502+
if err := os.WriteFile(fp, []byte(`
503+
package:
504+
name: parent
505+
version: 0.0.1
506+
epoch: 1
507+
508+
subpackages:
509+
- name: parent-docs
510+
annotations:
511+
cgr.dev/ecosystem: docs
512+
cgr.dev/component: manual
513+
514+
`), 0o644); err != nil {
515+
t.Fatal(err)
516+
}
517+
cfg, err := ParseConfiguration(ctx, fp)
518+
if err != nil {
519+
t.Fatalf("failed to parse configuration: %s", err)
520+
}
521+
522+
require.Len(t, cfg.Subpackages, 1)
523+
require.Equal(t, "docs", cfg.Subpackages[0].Annotations["cgr.dev/ecosystem"])
524+
require.Equal(t, "manual", cfg.Subpackages[0].Annotations["cgr.dev/component"])
525+
require.Nil(t, cfg.Package.Annotations, "subpackage annotations must not leak into parent")
526+
}
527+
499528
func TestDuplicateSubpackage(t *testing.T) {
500529
ctx := slogtest.Context(t)
501530

pkg/config/schema.cue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,9 @@
561561
// Optional: The human readable description of the subpackage
562562
description?: string
563563

564+
// Optional: Annotations for this subpackage
565+
annotations?: [string]: string
566+
564567
// Optional: The URL to the package's homepage
565568
url?: string
566569

pkg/config/schema.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,6 +1025,13 @@
10251025
"type": "string",
10261026
"description": "Optional: The human readable description of the subpackage"
10271027
},
1028+
"annotations": {
1029+
"additionalProperties": {
1030+
"type": "string"
1031+
},
1032+
"type": "object",
1033+
"description": "Optional: Annotations for this subpackage"
1034+
},
10281035
"url": {
10291036
"type": "string",
10301037
"description": "Optional: The URL to the package's homepage"

0 commit comments

Comments
 (0)