Skip to content

Commit

Permalink
(WIP) (gha) add helm chart lint
Browse files Browse the repository at this point in the history
  • Loading branch information
jhoblitt committed Mar 25, 2024
1 parent ba91463 commit 90a50ca
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 0 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/chart-lint.yaml
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
82 changes: 82 additions & 0 deletions utils/chart-lint.go
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
}

0 comments on commit 90a50ca

Please sign in to comment.