needed to add ah and helm chart linting to release

Signed-off-by: James Strong <strong.james.e@gmail.com>
This commit is contained in:
James Strong 2023-02-01 15:06:44 -05:00
parent 1bf5317969
commit 2301148561
Failed to extract signature
2 changed files with 42 additions and 4 deletions

View file

@ -32,6 +32,7 @@ import (
const HelmChartPath = "charts/ingress-nginx/Chart.yaml"
const HelmChartValues = "charts/ingress-nginx/values.yaml"
const ArtHubImage = "public.ecr.aws/artifacthub/ah:v1.5.0"
type Helm mg.Namespace
@ -100,9 +101,13 @@ func updateChartReleaseNotes(releasesNotes []string) {
Info("HELM Updating the Chart Release notes")
chart, err := chartutil.LoadChartfile(HelmChartPath)
CheckIfError(err, "HELM Could not Load Chart to update release notes %s", HelmChartPath)
var releaseNoteString string
releaseNoteString := ""
for i := range releasesNotes {
releaseNoteString = fmt.Sprintf("%s - %s\n", releaseNoteString, releasesNotes[i])
if len(releaseNoteString) == 0 {
releaseNoteString = fmt.Sprintf("- \"%s\"\n", releasesNotes[i])
} else {
releaseNoteString = fmt.Sprintf("%s- \"%s\"\n", releaseNoteString, releasesNotes[i])
}
}
Info("HELM Release note string %s", releaseNoteString)
chart.Annotations["artifacthub.io/changes"] = releaseNoteString
@ -119,6 +124,36 @@ func (Helm) UpdateChartValue(key, value string) {
updateChartValue(key, value)
}
func runArtifactHub() error {
Info("---------------------Running Artifact Hub Lint on Charts---------------")
dir, err := os.Getwd()
if err != nil {
ErrorF("Could not get current dir %s", err)
return err
}
return sh.RunV("docker",
"run",
"--rm",
"-v", fmt.Sprintf("%s:/work", dir),
"-w", "/work",
ArtHubImage,
"ah", "lint", "-p", "charts/ingress-nginx")
}
func validateHelm() error {
err := runArtifactHub()
if err != nil {
return err
}
Info("---------------------Running Verify Charts Lint Script---------------")
err = sh.RunV("./build/run-in-docker.sh", "./hack/verify-chart-lint.sh")
if err != nil {
return err
}
return nil
}
func updateChartValue(key, value string) {
Info("HELM Updating Chart %s %s:%s", HelmChartValues, key, value)

View file

@ -158,6 +158,9 @@ func (Release) NewRelease(version string) {
releaseNotes.helmTemplate()
err = validateHelm()
CheckIfError(err, "RELEASE Validating Helm Chart Changes")
//update static manifest
CheckIfError(updateStaticManifest(), "Error Updating Static manifests")
@ -293,7 +296,7 @@ func makeReleaseNotes(newVersion string) (*ReleaseNote, error) {
var helmUpdates []string
prRegex := regexp.MustCompile("\\(#\\d+\\)")
depBot := regexp.MustCompile("^(\\w){1,10} Bump ")
helmRegex := regexp.MustCompile("helm|chart")
helmRegex := regexp.MustCompile("helm|chart|(?i)values")
for i, s := range commits {
//matches on PR
if prRegex.Match([]byte(s)) {
@ -413,7 +416,7 @@ func (r ReleaseNote) helmTemplate() {
Debug("ChangeLog Templates %s", string(changelogTemplate))
t := template.Must(template.New("changelog").Parse(string(changelogTemplate)))
// create a new file
file, err := os.Create(fmt.Sprintf("charts/ingress-nginx/changelog/Changelog-%s.md", r.Version))
file, err := os.Create(fmt.Sprintf("charts/ingress-nginx/changelog/Changelog-%s.md", r.NewHelmChartVersion))
if err != nil {
ErrorF("Could not create changelog file %s", err)
}