Mage: Stop mutating release notes. (#11582)

* Mage: Implement static check recommendations.

* Mage: Stop mutating release notes.

---------

Co-authored-by: Marco Ebert <marco_ebert@icloud.com>
This commit is contained in:
k8s-infra-cherrypick-robot 2024-07-08 12:52:55 -07:00 committed by GitHub
parent 0300cb2214
commit 18735f0896
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 20 additions and 19 deletions

View file

@ -18,9 +18,7 @@ package steps
import ( import (
"bytes" "bytes"
"fmt"
"os" "os"
"strings"
semver "github.com/blang/semver/v4" semver "github.com/blang/semver/v4"
"github.com/helm/helm/pkg/chartutil" "github.com/helm/helm/pkg/chartutil"
@ -104,18 +102,21 @@ func updateVersion(version string) {
utils.CheckIfError(err, "HELM Saving new Chart") utils.CheckIfError(err, "HELM Saving new Chart")
} }
func updateChartReleaseNotes(releasesNotes []string) { func updateChartReleaseNotes(releaseNotes []string) {
utils.Info("HELM Updating the Chart Release notes") utils.Info("HELM Updating chart release notes")
chart, err := chartutil.LoadChartfile(HelmChartPath) chart, err := chartutil.LoadChartfile(HelmChartPath)
utils.CheckIfError(err, "HELM Could not Load Chart to update release notes %s", HelmChartPath) utils.CheckIfError(err, "HELM Failed to load chart manifest: %s", HelmChartPath)
for i := range releasesNotes {
releasesNotes[i] = fmt.Sprintf("- %q", releasesNotes[i]) releaseNotesBytes, err := yaml.Marshal(releaseNotes)
} utils.CheckIfError(err, "HELM Failed to marshal release notes")
releaseNoteString := strings.Join(releasesNotes, "\n")
utils.Info("HELM Release note string %s", releaseNoteString) releaseNotesString := string(releaseNotesBytes)
chart.Annotations["artifacthub.io/changes"] = releaseNoteString utils.Info("HELM Chart release notes:\n%s", releaseNotesString)
chart.Annotations["artifacthub.io/changes"] = releaseNotesString
utils.Info("HELM Saving chart release notes")
err = chartutil.SaveChartfile(HelmChartPath, chart) err = chartutil.SaveChartfile(HelmChartPath, chart)
utils.CheckIfError(err, "HELM Saving updated release notes for Chart") utils.CheckIfError(err, "HELM Failed to save chart manifest: %s", HelmChartPath)
} }
// UpdateChartValue Updates the Helm ChartValue // UpdateChartValue Updates the Helm ChartValue

View file

@ -74,7 +74,7 @@ func (Release) NewReleaseFromOld(version, oldversion string) {
func (Release) E2EDocs() { func (Release) E2EDocs() {
e2edocs, err := utils.GenerateE2EDocs() e2edocs, err := utils.GenerateE2EDocs()
utils.CheckIfError(err, "error on template") utils.CheckIfError(err, "error on template")
err = os.WriteFile("docs/e2e-tests.md", []byte(e2edocs), 644) err = os.WriteFile("docs/e2e-tests.md", []byte(e2edocs), 0644)
utils.CheckIfError(err, "Could not write new e2e test file ") utils.CheckIfError(err, "Could not write new e2e test file ")
} }
@ -158,7 +158,7 @@ func updateIndexMD(old, new string) error {
utils.CheckIfError(err, "Could not read INDEX_DOCS file %s", INDEX_DOCS) utils.CheckIfError(err, "Could not read INDEX_DOCS file %s", INDEX_DOCS)
datString := string(data) datString := string(data)
datString = strings.Replace(datString, old, new, -1) datString = strings.Replace(datString, old, new, -1)
err = os.WriteFile(INDEX_DOCS, []byte(datString), 644) err = os.WriteFile(INDEX_DOCS, []byte(datString), 0644)
if err != nil { if err != nil {
utils.ErrorF("Could not write new %s %s", INDEX_DOCS, err) utils.ErrorF("Could not write new %s %s", INDEX_DOCS, err)
return err return err
@ -255,7 +255,7 @@ func makeReleaseNotes(newVersion, oldVersion string) (*utils.ReleaseNote, error)
// the newControllerVersion should match the latest tag // the newControllerVersion should match the latest tag
if newControllerVersion != allControllerTags[0] { if newControllerVersion != allControllerTags[0] {
return nil, errors.New(fmt.Sprintf("Generating release new version %s didnt match the current latest tag %s", newControllerVersion, allControllerTags[0])) return nil, fmt.Errorf("generating release new version %s didnt match the current latest tag %s", newControllerVersion, allControllerTags[0])
} }
// previous version // previous version
newReleaseNotes.PreviousControllerVersion = allControllerTags[1] newReleaseNotes.PreviousControllerVersion = allControllerTags[1]
@ -272,8 +272,8 @@ func makeReleaseNotes(newVersion, oldVersion string) (*utils.ReleaseNote, error)
var allUpdates []string var allUpdates []string
var depUpdates []string var depUpdates []string
var helmUpdates []string var helmUpdates []string
prRegex := regexp.MustCompile("\\(#\\d+\\)") prRegex := regexp.MustCompile(`\(#\d+\)`)
depBot := regexp.MustCompile("^(\\w){1,10} Bump ") depBot := regexp.MustCompile(`^(\w){1,10} Bump `)
helmRegex := regexp.MustCompile("helm|chart") helmRegex := regexp.MustCompile("helm|chart")
for i, s := range commits { for i, s := range commits {
// matches on PR // matches on PR
@ -322,13 +322,13 @@ func makeReleaseNotes(newVersion, oldVersion string) (*utils.ReleaseNote, error)
controllerDigest := utils.FindImageDigest(data, "controller", newVersion) controllerDigest := utils.FindImageDigest(data, "controller", newVersion)
if len(controllerDigest) == 0 { if len(controllerDigest) == 0 {
utils.ErrorF("Controller Digest could not be found") utils.ErrorF("Controller Digest could not be found")
return nil, errors.New("Controller digest could not be found") return nil, errors.New("controller digest could not be found")
} }
controllerChrootDigest := utils.FindImageDigest(data, "controller-chroot", newVersion) controllerChrootDigest := utils.FindImageDigest(data, "controller-chroot", newVersion)
if len(controllerChrootDigest) == 0 { if len(controllerChrootDigest) == 0 {
utils.ErrorF("Controller Chroot Digest could not be found") utils.ErrorF("Controller Chroot Digest could not be found")
return nil, errors.New("Controller Chroot digest could not be found") return nil, errors.New("controller chroot digest could not be found")
} }
utils.Debug("Latest Controller Digest %v", controllerDigest) utils.Debug("Latest Controller Digest %v", controllerDigest)