-
-
Notifications
You must be signed in to change notification settings - Fork 2
feat(pipe): add version compatibility matrix automation (tracer pilot) #1752
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
Open
gauchito91
wants to merge
10
commits into
main
Choose a base branch
from
feat/compat-matrix-tracer-pilot
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
9e9a7f1
feat(pipe): add generate-compatibility tool for version support matrix
gauchito91 218c941
ci(pipe): wire generate-compatibility into release and PR check
gauchito91 dab165a
docs(tracer): generate compatibility matrix for tracer chart (pilot)
gauchito91 ae15c19
doc(pipe): add pre-dev planning docs for compatibility matrix
gauchito91 9ee356b
fix(pipe): address CodeRabbit review on generate-compatibility
gauchito91 4bb012c
doc(pipe): align planning docs with CodeRabbit review
gauchito91 084e542
fix(pipe): use English 'Requires' label for cross-compat column
gauchito91 0025fc2
fix(pipe): address CodeRabbit 2nd review
gauchito91 bda284a
doc(pipe): fix remaining CodeRabbit doc nits
gauchito91 05516c4
doc(pipe): align ST-6-1 exit-code recipe with unknown --chart case
gauchito91 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "fmt" | ||
| "io" | ||
| "strings" | ||
|
|
||
| "github.com/Masterminds/semver/v3" | ||
| "gopkg.in/yaml.v3" | ||
| ) | ||
|
|
||
| // compatAnnotationKey is the reverse-DNS annotation carrying compatibility data. | ||
| // It follows the precedent of lerian.studio/chart-type | ||
| // (validate-helm-charts/main.go:21). | ||
| const compatAnnotationKey = "lerian.studio/compatibility" | ||
|
|
||
| // chartTypeAnnotationKey is the pre-existing annotation every chart carries. | ||
| // It decides whether a missing cross-compatibility declaration is worth an INFO | ||
| // reminder: single-service charts are standalone and are NOT expected to declare | ||
| // compatibility, so their absence is silent. | ||
| const chartTypeAnnotationKey = "lerian.studio/chart-type" | ||
|
|
||
| const ( | ||
| chartTypeSingleService = "single-service" | ||
| chartTypeMultiComponent = "multi-component" | ||
| chartTypeDependencyWrapper = "dependency-wrapper" | ||
| ) | ||
|
|
||
| // CompatAnnotation is the parsed representation of the embedded YAML in the | ||
| // lerian.studio/compatibility annotation (data-model §A.1). Both maps are | ||
| // optional in v1; a wholly absent annotation is represented by a nil pointer. | ||
| type CompatAnnotation struct { | ||
| Requires map[string]string `yaml:"requires"` | ||
| TestedWith map[string]string `yaml:"testedWith"` | ||
| } | ||
|
|
||
| // parseCompatAnnotation is the SECOND step of the two-step unmarshal: the caller | ||
| // has already pulled the annotation string out of Chart.yaml.annotations; here | ||
| // we unmarshal that embedded YAML document. An empty/whitespace-only string | ||
| // means "no annotation declared" and returns (nil, nil). | ||
| // | ||
| // KnownFields(true) makes unknown/typo top-level keys (e.g. "testedWih", | ||
| // "require") a parse error instead of being silently dropped — otherwise a typo | ||
| // would erase the declaration without warning. The caller surfaces the error as | ||
| // a V1 WARN and continues (never aborts). An empty document yields io.EOF from | ||
| // Decode, which we treat as "nothing declared" (empty ann, no error). | ||
| func parseCompatAnnotation(raw string) (*CompatAnnotation, error) { | ||
| if strings.TrimSpace(raw) == "" { | ||
| return nil, nil | ||
| } | ||
| var ann CompatAnnotation | ||
| dec := yaml.NewDecoder(bytes.NewReader([]byte(raw))) | ||
| dec.KnownFields(true) | ||
| if err := dec.Decode(&ann); err != nil && err != io.EOF { | ||
| return nil, err | ||
| } | ||
| return &ann, nil | ||
| } | ||
|
|
||
| // validateCompat applies rules V3–V6 (api-design §I.3) without ever failing. | ||
| // V1 (valid YAML) and V2 (unknown keys) are handled by parseCompatAnnotation | ||
| // and the typed struct respectively. knownProducts is the set of chart names | ||
| // present in the repo, used for the V3 existence check. | ||
| // | ||
| // chartType (lerian.studio/chart-type) gates the V6 reminder for a MISSING | ||
| // cross-compatibility declaration: | ||
| // - single-service → standalone; no reminder (cross-compat N/A). | ||
| // - multi-component / | ||
| // dependency-wrapper → INFO reminder when nothing is declared. | ||
| // - "" (missing) → treated as multi-component (conservative) PLUS a | ||
| // WARN that the chart-type annotation is absent. | ||
| // | ||
| // A DECLARED compatibility is always validated (V3/V4/V5) regardless of type. | ||
| func validateCompat(chart, chartType string, ann *CompatAnnotation, knownProducts map[string]bool) []Warning { | ||
| var out []Warning | ||
|
|
||
| if chartType == "" { | ||
| // chart-type should always be present; flag its absence and fall through | ||
| // as if multi-component (the stricter branch that still reminds on V6). | ||
| out = append(out, Warning{SevWarn, chart, "CT", "lerian.studio/chart-type annotation is missing; treating as multi-component"}) | ||
| chartType = chartTypeMultiComponent | ||
| } | ||
|
|
||
| if ann == nil || (len(ann.Requires) == 0 && len(ann.TestedWith) == 0) { | ||
| // Nothing declared. Single-service charts are standalone and are not | ||
| // expected to declare cross-compatibility, so stay silent for them. | ||
| if chartType == chartTypeSingleService { | ||
| return out | ||
| } | ||
| // multi-component / dependency-wrapper: soft, non-blocking reminder. | ||
| out = append(out, Warning{ | ||
| Severity: SevInfo, | ||
| Chart: chart, | ||
| Rule: "V6", | ||
| Detail: "no compatibility declared (testedWith expected in v1)", | ||
| }) | ||
| return out | ||
| } | ||
|
|
||
| // V3 + V4: requires. | ||
| for product, rng := range ann.Requires { | ||
| if !knownProducts[product] { | ||
| out = append(out, Warning{SevWarn, chart, "V3", fmt.Sprintf("requires[%s] — unknown chart", product)}) | ||
| } | ||
| if _, err := semver.NewConstraint(rng); err != nil { | ||
| out = append(out, Warning{SevWarn, chart, "V4", fmt.Sprintf("requires[%s] — invalid semver range %q", product, rng)}) | ||
| } | ||
| } | ||
|
|
||
| // V3 + V5: testedWith. | ||
| for product, ver := range ann.TestedWith { | ||
| if !knownProducts[product] { | ||
| out = append(out, Warning{SevWarn, chart, "V3", fmt.Sprintf("testedWith[%s] — unknown chart", product)}) | ||
| } | ||
| if _, err := semver.NewVersion(ver); err != nil { | ||
| out = append(out, Warning{SevWarn, chart, "V5", fmt.Sprintf("testedWith[%s] — not an exact version %q", product, ver)}) | ||
| } | ||
| } | ||
|
|
||
| return out | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "reflect" | ||
| "testing" | ||
| ) | ||
|
|
||
| func TestParseCompatAnnotation(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| raw string | ||
| want *CompatAnnotation | ||
| wantError bool | ||
| }{ | ||
| { | ||
| name: "complete requires + testedWith", | ||
| raw: `requires: | ||
| midaz-helm: ">=8.4.0 <9.0.0" | ||
| testedWith: | ||
| midaz-helm: "8.6.0" | ||
| `, | ||
| want: &CompatAnnotation{ | ||
| Requires: map[string]string{"midaz-helm": ">=8.4.0 <9.0.0"}, | ||
| TestedWith: map[string]string{"midaz-helm": "8.6.0"}, | ||
| }, | ||
| }, | ||
| { | ||
| name: "only testedWith (typical v1 post-backfill)", | ||
| raw: `testedWith: | ||
| midaz-helm: "8.6.0" | ||
| `, | ||
| want: &CompatAnnotation{ | ||
| TestedWith: map[string]string{"midaz-helm": "8.6.0"}, | ||
| }, | ||
| }, | ||
| { | ||
| name: "empty string => nil (absent)", | ||
| raw: "", | ||
| want: nil, | ||
| }, | ||
| { | ||
| name: "broken embedded YAML => error (V1)", | ||
| raw: "requires:\n midaz-helm \">=8.4.0\"\n", // missing colon | ||
| wantError: true, | ||
| }, | ||
| { | ||
| name: "unknown top-level field (typo 'testedWih') => error, not silent", | ||
| raw: "testedWih:\n midaz-helm: \"8.6.0\"\n", | ||
| wantError: true, | ||
| }, | ||
| { | ||
| name: "unknown top-level field (typo 'require') => error, not silent", | ||
| raw: "require:\n midaz-helm: \">=8.4.0\"\n", | ||
| wantError: true, | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| got, err := parseCompatAnnotation(tt.raw) | ||
| if (err != nil) != tt.wantError { | ||
| t.Fatalf("err = %v, wantError = %v", err, tt.wantError) | ||
| } | ||
| if tt.wantError { | ||
| return | ||
| } | ||
| if !reflect.DeepEqual(got, tt.want) { | ||
| t.Fatalf("got %+v, want %+v", got, tt.want) | ||
| } | ||
| }) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "io" | ||
| "os" | ||
| "path/filepath" | ||
| "testing" | ||
| ) | ||
|
|
||
| // fakeTagLister returns canned tags (and optional dates) per dir. | ||
| type fakeTagLister struct { | ||
| tags map[string][]string | ||
| dates map[string]map[string]string // dir -> (tag -> YYYY-MM-DD) | ||
| } | ||
|
|
||
| func (f fakeTagLister) listTags(dir string) ([]string, error) { | ||
| return f.tags[dir], nil | ||
| } | ||
|
|
||
| func (f fakeTagLister) listTagDates(dir string) (map[string]string, error) { | ||
| if f.dates == nil { | ||
| return map[string]string{}, nil | ||
| } | ||
| return f.dates[dir], nil | ||
| } | ||
|
|
||
| func TestBuildDoc_Golden(t *testing.T) { | ||
| root := t.TempDir() | ||
|
|
||
| // midaz: N=8.6.0, tags cover 8.6..8.2. | ||
| writeChart(t, root, "midaz", `apiVersion: v2 | ||
| name: midaz-helm | ||
| type: application | ||
| version: 8.6.0 | ||
| appVersion: "3.7.8" | ||
| `) | ||
| // plugin-fees: N=7.2.0, only its own tag; declares requires+testedWith. | ||
| writeChart(t, root, "plugin-fees", `apiVersion: v2 | ||
| name: plugin-fees-helm | ||
| type: application | ||
| version: 7.2.0 | ||
| appVersion: "3.3.0" | ||
| annotations: | ||
| lerian.studio/compatibility: | | ||
| requires: | ||
| midaz-helm: ">=8.4.0 <9.0.0" | ||
| testedWith: | ||
| midaz-helm: "8.6.0" | ||
| `) | ||
|
|
||
| lister := fakeTagLister{ | ||
| tags: map[string][]string{ | ||
| "midaz": { | ||
| "midaz-v8.6.0", "midaz-v8.5.0", "midaz-v8.4.0", | ||
| "midaz-v8.3.0", "midaz-v8.2.0", "midaz-v8.6.0-beta.11", | ||
| }, | ||
| "plugin-fees": {"plugin-fees-v7.2.0"}, | ||
| }, | ||
| dates: map[string]map[string]string{ | ||
| "midaz": { | ||
| "midaz-v8.6.0": "2026-06-01", "midaz-v8.5.0": "2026-05-01", | ||
| "midaz-v8.4.0": "2026-04-01", "midaz-v8.3.0": "2026-03-01", | ||
| "midaz-v8.2.0": "2026-02-01", | ||
| }, | ||
| "plugin-fees": {"plugin-fees-v7.2.0": "2026-06-15"}, | ||
| }, | ||
| } | ||
|
|
||
| doc, err := buildDoc(root, lister, io.Discard) | ||
| if err != nil { | ||
| t.Fatalf("buildDoc: %v", err) | ||
| } | ||
| doc.GeneratedFrom = "test" // pin the provenance field for a stable golden | ||
|
|
||
| got, err := renderJSON(doc) | ||
| if err != nil { | ||
| t.Fatalf("renderJSON: %v", err) | ||
| } | ||
|
|
||
| goldenPath := filepath.Join("testdata", "golden_two_products.json") | ||
| if os.Getenv("UPDATE_GOLDEN") == "1" { | ||
| if err := os.WriteFile(goldenPath, got, 0o644); err != nil { | ||
| t.Fatalf("update golden: %v", err) | ||
| } | ||
| } | ||
| want, err := os.ReadFile(goldenPath) | ||
| if err != nil { | ||
| t.Fatalf("read golden (run with UPDATE_GOLDEN=1 first): %v", err) | ||
| } | ||
| if string(got) != string(want) { | ||
| t.Fatalf("JSON mismatch.\n--- got ---\n%s\n--- want ---\n%s", got, want) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| // Command generate-compatibility produces the per-product support-window matrix | ||
| // (README blocks + docs/compatibility.json) for the charts in this repo. | ||
| // | ||
| // It mirrors the sibling tools in .github/scripts (generate-values-schemas, | ||
| // update-readme-matrix): invoked with --root ../.., reads the repo state, and | ||
| // writes deterministic artifacts. No network access beyond the git tags already | ||
| // present in the checkout. | ||
| package main | ||
|
|
||
| import ( | ||
| "os" | ||
| "path/filepath" | ||
| "sort" | ||
| ) | ||
|
|
||
| // chartDirectories returns the names (not full paths) of the immediate | ||
| // subdirectories of <root>/charts, sorted ascending. Loose files under charts/ | ||
| // are ignored. Mirrors validate-helm-charts/main.go:292-307 but returns bare | ||
| // names (the caller joins paths), copied here because Go forbids importing one | ||
| // package main from another. | ||
| func chartDirectories(root string) ([]string, error) { | ||
| chartsRoot := filepath.Join(root, "charts") | ||
| entries, err := os.ReadDir(chartsRoot) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| dirs := []string{} | ||
| for _, entry := range entries { | ||
| if entry.IsDir() { | ||
| dirs = append(dirs, entry.Name()) | ||
| } | ||
| } | ||
| sort.Strings(dirs) | ||
| return dirs, nil | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.