Skip to content

Commit

Permalink
Sort ah lint output leaving errors at the end (#3853)
Browse files Browse the repository at this point in the history
Closes #3852

Signed-off-by: Sergio Castaño Arteaga <[email protected]>
  • Loading branch information
tegioz authored Jun 6, 2024
1 parent 3b66a5f commit 503f7f2
Show file tree
Hide file tree
Showing 9 changed files with 279 additions and 0 deletions.
20 changes: 20 additions & 0 deletions cmd/ah/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"path"
"path/filepath"
"reflect"
"sort"
"strconv"
"strings"

Expand Down Expand Up @@ -459,6 +460,25 @@ type output struct {

// printReport prints the provided lint report to the receiver output.
func (out *output) printReport(report *lintReport) {
// Sort report entries leaving the ones with errors at the end
sort.Slice(report.entries, func(i, j int) bool {
if report.entries[i].result.ErrorOrNil() != nil && report.entries[j].result.ErrorOrNil() == nil {
return false
}
if report.entries[i].result.ErrorOrNil() == nil && report.entries[j].result.ErrorOrNil() != nil {
return true
}

if report.entries[i].pkg != nil && report.entries[j].pkg != nil {
if report.entries[i].pkg.Name == report.entries[j].pkg.Name {
return report.entries[i].pkg.Version < report.entries[j].pkg.Version
}
return report.entries[i].pkg.Name < report.entries[j].pkg.Name
}

return false
})

// Print packages checks results
for _, e := range report.entries {
// Setup minimal skeleton package if not provided
Expand Down
6 changes: 6 additions & 0 deletions cmd/ah/lint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ func TestLintCmd(t *testing.T) {
"no packages found",
errNoPackagesFound,
},
{
"kyverno",
"test18",
"four packages found, two with errors",
errLintFailed,
},
}

for _, tc := range testCases {
Expand Down
95 changes: 95 additions & 0 deletions cmd/ah/testdata/lint/test18/output.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@

------------------------------------------------------------------------------------------------------------------------
✓ pkg1 1.0.0 (testdata/lint/test18/pkgs/pkg1/1.0.0)
------------------------------------------------------------------------------------------------------------------------

Package lint SUCCEEDED!

✓ Name: pkg1
✓ Display name: Package 1
✓ Version: 1.0.0
✓ App version: 10.0.0
✓ Description: Description
✓ License: Apache-2.0
✓ Logo URL: https://home.url/logo.svg
✓ Home URL: https://home.url
✓ Deprecated: false
✓ Pre-release: true
✓ Contains security updates: true
✓ Provider: Provider
✓ Readme: PROVIDED
✓ Keywords:
- kw1
- kw2
✓ Links:
- Name: Link1 | URL: https://link1.url
✓ Maintainers:
- Name: Maintainer | Email: [email protected]
✓ Containers images:
- Name: | Image: registry/test/test:latest
✓ Changes:
- Kind: added | Description: feature 1
- Kind: fixed | Description: issue 1
✓ Recommendations:
- https://artifacthub.io/packages/helm/artifact-hub/artifact-hub
! Screenshots: *** NOT PROVIDED ***
✓ Operator: false
✓ Install: PROVIDED

------------------------------------------------------------------------------------------------------------------------
✓ pkg2 2.0.0 (testdata/lint/test18/pkgs/pkg2/2.0.0)
------------------------------------------------------------------------------------------------------------------------

Package lint SUCCEEDED!

✓ Name: pkg2
✓ Display name: Package 2
✓ Version: 2.0.0
✓ App version: 10.0.0
✓ Description: Description
✓ License: Apache-2.0
✓ Logo URL: https://home.url/logo.svg
✓ Home URL: https://home.url
✓ Deprecated: false
✓ Pre-release: true
✓ Contains security updates: true
✓ Provider: Provider
✓ Readme: PROVIDED
✓ Keywords:
- kw1
- kw2
✓ Links:
- Name: Link1 | URL: https://link1.url
✓ Maintainers:
- Name: Maintainer | Email: [email protected]
✓ Containers images:
- Name: | Image: registry/test/test:latest
✓ Changes:
- Kind: added | Description: feature 1
- Kind: fixed | Description: issue 1
✓ Recommendations:
- https://artifacthub.io/packages/helm/artifact-hub/artifact-hub
! Screenshots: *** NOT PROVIDED ***
✓ Operator: false
✓ Install: PROVIDED

------------------------------------------------------------------------------------------------------------------------
✗ name: ? version: ? (testdata/lint/test18/pkgs/pkg1/2.0.0)
------------------------------------------------------------------------------------------------------------------------

Package lint FAILED. 1 error(s) occurred:

* error preparing package pkg1 version 2.0.0 data: error reading kyverno policy file: lstat testdata/lint/test18/pkgs/pkg1/2.0.0/2.0.0.yaml: no such file or directory

------------------------------------------------------------------------------------------------------------------------
✗ name: ? version: ? (testdata/lint/test18/pkgs/pkg2/1.0.0)
------------------------------------------------------------------------------------------------------------------------

Package lint FAILED. 1 error(s) occurred:

* error preparing package pkg2 version 1.0.0 data: error reading kyverno policy file: lstat testdata/lint/test18/pkgs/pkg2/1.0.0/1.0.0.yaml: no such file or directory

------------------------------------------------------------------------------------------------------------------------

4 package(s) found, 2 package(s) with errors

1 change: 1 addition & 0 deletions cmd/ah/testdata/lint/test18/pkgs/pkg1/1.0.0/1.0.0.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
policy content
39 changes: 39 additions & 0 deletions cmd/ah/testdata/lint/test18/pkgs/pkg1/1.0.0/artifacthub-pkg.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
version: 1.0.0
name: pkg1
displayName: Package 1
createdAt: 2019-06-28T15:23:00Z
description: Description
digest: 0123456789
license: Apache-2.0
logoURL: https://home.url/logo.svg
homeURL: https://home.url
appVersion: 10.0.0
containersImages:
- image: registry/test/test:latest
containsSecurityUpdates: true
operator: false
deprecated: false
prerelease: true
keywords:
- kw1
- kw2
links:
- name: Link1
url: https://link1.url
readme: Readme content in markdown format
install: Brief install instructions in markdown format
changes:
- kind: added
description: feature 1
- kind: fixed
description: issue 1
maintainers:
- name: Maintainer
email: [email protected]
provider:
name: Provider
recommendations:
- url: https://artifacthub.io/packages/helm/artifact-hub/artifact-hub
annotations:
key1: value1
key2: value2
39 changes: 39 additions & 0 deletions cmd/ah/testdata/lint/test18/pkgs/pkg1/2.0.0/artifacthub-pkg.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
version: 2.0.0
name: pkg1
displayName: Package 1
createdAt: 2019-06-28T15:23:00Z
description: Description
digest: 0123456789
license: Apache-2.0
logoURL: https://home.url/logo.svg
homeURL: https://home.url
appVersion: 10.0.0
containersImages:
- image: registry/test/test:latest
containsSecurityUpdates: true
operator: false
deprecated: false
prerelease: true
keywords:
- kw1
- kw2
links:
- name: Link1
url: https://link1.url
readme: Readme content in markdown format
install: Brief install instructions in markdown format
changes:
- kind: added
description: feature 1
- kind: fixed
description: issue 1
maintainers:
- name: Maintainer
email: [email protected]
provider:
name: Provider
recommendations:
- url: https://artifacthub.io/packages/helm/artifact-hub/artifact-hub
annotations:
key1: value1
key2: value2
39 changes: 39 additions & 0 deletions cmd/ah/testdata/lint/test18/pkgs/pkg2/1.0.0/artifacthub-pkg.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
version: 1.0.0
name: pkg2
displayName: Package 2
createdAt: 2019-06-28T15:23:00Z
description: Description
digest: 0123456789
license: Apache-2.0
logoURL: https://home.url/logo.svg
homeURL: https://home.url
appVersion: 10.0.0
containersImages:
- image: registry/test/test:latest
containsSecurityUpdates: true
operator: false
deprecated: false
prerelease: true
keywords:
- kw1
- kw2
links:
- name: Link1
url: https://link1.url
readme: Readme content in markdown format
install: Brief install instructions in markdown format
changes:
- kind: added
description: feature 1
- kind: fixed
description: issue 1
maintainers:
- name: Maintainer
email: [email protected]
provider:
name: Provider
recommendations:
- url: https://artifacthub.io/packages/helm/artifact-hub/artifact-hub
annotations:
key1: value1
key2: value2
1 change: 1 addition & 0 deletions cmd/ah/testdata/lint/test18/pkgs/pkg2/2.0.0/2.0.0.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
policy content
39 changes: 39 additions & 0 deletions cmd/ah/testdata/lint/test18/pkgs/pkg2/2.0.0/artifacthub-pkg.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
version: 2.0.0
name: pkg2
displayName: Package 2
createdAt: 2019-06-28T15:23:00Z
description: Description
digest: 0123456789
license: Apache-2.0
logoURL: https://home.url/logo.svg
homeURL: https://home.url
appVersion: 10.0.0
containersImages:
- image: registry/test/test:latest
containsSecurityUpdates: true
operator: false
deprecated: false
prerelease: true
keywords:
- kw1
- kw2
links:
- name: Link1
url: https://link1.url
readme: Readme content in markdown format
install: Brief install instructions in markdown format
changes:
- kind: added
description: feature 1
- kind: fixed
description: issue 1
maintainers:
- name: Maintainer
email: [email protected]
provider:
name: Provider
recommendations:
- url: https://artifacthub.io/packages/helm/artifact-hub/artifact-hub
annotations:
key1: value1
key2: value2

0 comments on commit 503f7f2

Please sign in to comment.