Skip to content

Commit

Permalink
Mage: Stop mutating release notes. (#11582)
Browse files Browse the repository at this point in the history
* Mage: Implement static check recommendations.

* Mage: Stop mutating release notes.

---------

Co-authored-by: Marco Ebert <marco_ebert@icloud.com>
  • Loading branch information
k8s-infra-cherrypick-robot and Gacko committed Jul 8, 2024
1 parent 0300cb2 commit 18735f0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
25 changes: 13 additions & 12 deletions magefiles/steps/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ package steps

import (
"bytes"
"fmt"
"os"
"strings"

semver "github.com/blang/semver/v4"
"github.com/helm/helm/pkg/chartutil"
Expand Down Expand Up @@ -104,18 +102,21 @@ func updateVersion(version string) {
utils.CheckIfError(err, "HELM Saving new Chart")
}

func updateChartReleaseNotes(releasesNotes []string) {
utils.Info("HELM Updating the Chart Release notes")
func updateChartReleaseNotes(releaseNotes []string) {
utils.Info("HELM Updating chart release notes")
chart, err := chartutil.LoadChartfile(HelmChartPath)
utils.CheckIfError(err, "HELM Could not Load Chart to update release notes %s", HelmChartPath)
for i := range releasesNotes {
releasesNotes[i] = fmt.Sprintf("- %q", releasesNotes[i])
}
releaseNoteString := strings.Join(releasesNotes, "\n")
utils.Info("HELM Release note string %s", releaseNoteString)
chart.Annotations["artifacthub.io/changes"] = releaseNoteString
utils.CheckIfError(err, "HELM Failed to load chart manifest: %s", HelmChartPath)

releaseNotesBytes, err := yaml.Marshal(releaseNotes)
utils.CheckIfError(err, "HELM Failed to marshal release notes")

releaseNotesString := string(releaseNotesBytes)
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)
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
Expand Down
14 changes: 7 additions & 7 deletions magefiles/steps/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (Release) NewReleaseFromOld(version, oldversion string) {
func (Release) E2EDocs() {
e2edocs, err := utils.GenerateE2EDocs()
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 ")
}

Expand Down Expand Up @@ -158,7 +158,7 @@ func updateIndexMD(old, new string) error {
utils.CheckIfError(err, "Could not read INDEX_DOCS file %s", INDEX_DOCS)
datString := string(data)
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 {
utils.ErrorF("Could not write new %s %s", INDEX_DOCS, err)
return err
Expand Down Expand Up @@ -255,7 +255,7 @@ func makeReleaseNotes(newVersion, oldVersion string) (*utils.ReleaseNote, error)

// the newControllerVersion should match the latest tag
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
newReleaseNotes.PreviousControllerVersion = allControllerTags[1]
Expand All @@ -272,8 +272,8 @@ func makeReleaseNotes(newVersion, oldVersion string) (*utils.ReleaseNote, error)
var allUpdates []string
var depUpdates []string
var helmUpdates []string
prRegex := regexp.MustCompile("\\(#\\d+\\)")
depBot := regexp.MustCompile("^(\\w){1,10} Bump ")
prRegex := regexp.MustCompile(`\(#\d+\)`)
depBot := regexp.MustCompile(`^(\w){1,10} Bump `)
helmRegex := regexp.MustCompile("helm|chart")
for i, s := range commits {
// matches on PR
Expand Down Expand Up @@ -322,13 +322,13 @@ func makeReleaseNotes(newVersion, oldVersion string) (*utils.ReleaseNote, error)
controllerDigest := utils.FindImageDigest(data, "controller", newVersion)
if len(controllerDigest) == 0 {
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)
if len(controllerChrootDigest) == 0 {
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)
Expand Down

0 comments on commit 18735f0

Please sign in to comment.