Skip to content

Commit

Permalink
Merge pull request #105 from grafana/104-improve-compliance-badge-sup…
Browse files Browse the repository at this point in the history
…port

Improve compliance badge support
  • Loading branch information
szkiba authored Nov 12, 2024
2 parents 3083799 + 4c4f0cb commit d6145d2
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 3 deletions.
13 changes: 12 additions & 1 deletion cmd/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,18 @@ func writeAPIGroupGlobal(registry k6registry.Registry, target string) error {
return writeJSON(filepath.Join(target, "catalog.json"), k6registry.RegistryToCatalog(registry))
}

const gradesvg = `<svg xmlns="http://www.w3.org/2000/svg" width="17" height="20"><clipPath id="B"><rect width="17" height="20" rx="3" fill="#fff"/></clipPath><g clip-path="url(#B)"><path fill="%s" d="M0 0h17v20H0z"/><path fill="url(#A)" d="M0 0h17v20H0z"/></g><g text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="110"><text x="85" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="70">%s</text><text x="85" y="140" transform="scale(.1)" fill="#fff" textLength="70">%s</text></g></svg>` //nolint:lll

func writeAPIGroupModule(registry k6registry.Registry, target string) error {
base := filepath.Join(target, "module")

for _, ext := range registry {
dir := filepath.Join(base, ext.Module)

if ext.Compliance != nil {
b, err := badge.RenderBytes("k6 registry", string(ext.Compliance.Grade), badgecolor(ext.Compliance.Grade))
sgrade := string(ext.Compliance.Grade)

b, err := badge.RenderBytes("k6 registry", sgrade, badgecolor(ext.Compliance.Grade))
if err != nil {
return err
}
Expand All @@ -81,6 +85,13 @@ func writeAPIGroupModule(registry k6registry.Registry, target string) error {
if err != nil {
return err
}

grade := fmt.Sprintf(gradesvg, badgecolor(ext.Compliance.Grade), sgrade, sgrade)

err = writeData(filepath.Join(dir, "grade.svg"), []byte(grade))
if err != nil {
return err
}
}

if err := writeJSON(filepath.Join(dir, "extension.json"), ext); err != nil {
Expand Down
4 changes: 3 additions & 1 deletion cmd/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,9 @@ func checkCompliance(ctx context.Context, module string, cloneURL string, tstamp
return nil, err
}

compliance.Checks = nil
for idx := range compliance.Checks {
compliance.Checks[idx].Details = ""
}

err = saveCompliance(ctx, module, compliance)
if err != nil {
Expand Down
14 changes: 13 additions & 1 deletion cmd/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,19 @@ func loadOne(ctx context.Context, ext *k6registry.Extension, lint bool) error {
return err
}

ext.Compliance = &k6registry.Compliance{Grade: k6registry.Grade(compliance.Grade), Level: compliance.Level}
var issues []string

for _, check := range compliance.Checks {
if !check.Passed {
issues = append(issues, string(check.ID))
}
}

ext.Compliance = &k6registry.Compliance{
Grade: k6registry.Grade(compliance.Grade),
Level: compliance.Level,
Issues: issues,
}
}

return nil
Expand Down
17 changes: 17 additions & 0 deletions docs/registry.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,23 @@
"C",
"A"
]
},
"issues": {
"type": "array",
"description": "A list of compliance check IDs that failed.\n\nThe `issues`` property is primarily used for debugging. It contains the (implementation-dependent) identifiers of those compliance checks that failed.\n",
"items": {
"type": "string"
},
"examples": [
[
"build",
"smoke"
],
[
"readme",
"versions"
]
]
}
},
"additionalProperties": false
Expand Down
7 changes: 7 additions & 0 deletions registry_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions releases/v0.1.34.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
k6registry `v0.1.34` is here 🎉!

This is an internal maintenance release.
- Add go tooling to docker image (k6lint build checker requires it)
- Keep a list of failed k6lint checkers (for debugging purposes)
- Generate a grade badge that only contains the grade letter

0 comments on commit d6145d2

Please sign in to comment.