-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,21 @@ | ||
--- | ||
# yamllint disable rule:quoted-strings | ||
name: helm chart lint | ||
|
||
"on": | ||
- push | ||
|
||
jobs: | ||
fleet-symlinks: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: azure/[email protected] | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v3 | ||
with: | ||
go-version: 1.21 | ||
|
||
- name: helm chart lint | ||
run: go run ./utils/chart-lint.go |
This file contains 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,82 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"os" | ||
"os/exec" | ||
"path/filepath" | ||
) | ||
|
||
func main() { | ||
// recursively find Chart.yaml files | ||
charts, err := findChartDirs(".") | ||
if err != nil { | ||
fmt.Println("Error:", err) | ||
log.Fatal(err) | ||
} | ||
|
||
fmt.Println("Found", len(charts), "charts") | ||
fmt.Println(charts) | ||
|
||
// convert chart paths to absolute paths | ||
for i, chart := range charts { | ||
absPath, err := filepath.Abs(chart) | ||
if err != nil { | ||
fmt.Println("Error:", err) | ||
log.Fatal(err) | ||
} | ||
charts[i] = absPath | ||
} | ||
|
||
chartErrors := 0 | ||
|
||
// for each Chart.yaml file, run helm lint | ||
for _, chart := range charts { | ||
fmt.Println("Linting", chart) | ||
|
||
// cd to chart dir | ||
err := os.Chdir(chart) | ||
if err != nil { | ||
fmt.Println("Error:", err) | ||
log.Fatal(err) | ||
} | ||
|
||
// run helm lint | ||
cmd := exec.Command("helm", "lint") | ||
out, err := cmd.CombinedOutput() | ||
if err != nil { | ||
fmt.Println("Error blah:", string(out)) | ||
chartErrors++ | ||
continue | ||
} | ||
} | ||
|
||
// report total number of errors | ||
fmt.Println("Total errors:", chartErrors) | ||
if chartErrors > 0 { | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
func findChartDirs(path string) ([]string, error) { | ||
charts := []string{} | ||
|
||
err := filepath.Walk(path, func(path string, info os.FileInfo, err error) error { | ||
if err != nil { | ||
return err | ||
} | ||
// skip directories | ||
if info.IsDir() { | ||
return nil | ||
} | ||
// check if file is Chart.yaml | ||
if info.Name() == "Chart.yaml" { | ||
// then asssume that this is a chart directory | ||
dir := filepath.Dir(path) | ||
charts = append(charts, dir) | ||
} | ||
return nil | ||
}) | ||
return charts, err | ||
} |