Skip to content

Commit 886956e

Browse files
authored
Merge pull request #11567 from Gacko/guurz
Mage: Stop mutating release notes.
2 parents 7617204 + 2d67ec2 commit 886956e

File tree

2 files changed

+20
-19
lines changed

2 files changed

+20
-19
lines changed

magefiles/steps/helm.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ package steps
1818

1919
import (
2020
"bytes"
21-
"fmt"
2221
"os"
23-
"strings"
2422

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

107-
func updateChartReleaseNotes(releasesNotes []string) {
108-
utils.Info("HELM Updating the Chart Release notes")
105+
func updateChartReleaseNotes(releaseNotes []string) {
106+
utils.Info("HELM Updating chart release notes")
109107
chart, err := chartutil.LoadChartfile(HelmChartPath)
110-
utils.CheckIfError(err, "HELM Could not Load Chart to update release notes %s", HelmChartPath)
111-
for i := range releasesNotes {
112-
releasesNotes[i] = fmt.Sprintf("- %q", releasesNotes[i])
113-
}
114-
releaseNoteString := strings.Join(releasesNotes, "\n")
115-
utils.Info("HELM Release note string %s", releaseNoteString)
116-
chart.Annotations["artifacthub.io/changes"] = releaseNoteString
108+
utils.CheckIfError(err, "HELM Failed to load chart manifest: %s", HelmChartPath)
109+
110+
releaseNotesBytes, err := yaml.Marshal(releaseNotes)
111+
utils.CheckIfError(err, "HELM Failed to marshal release notes")
112+
113+
releaseNotesString := string(releaseNotesBytes)
114+
utils.Info("HELM Chart release notes:\n%s", releaseNotesString)
115+
chart.Annotations["artifacthub.io/changes"] = releaseNotesString
116+
117+
utils.Info("HELM Saving chart release notes")
117118
err = chartutil.SaveChartfile(HelmChartPath, chart)
118-
utils.CheckIfError(err, "HELM Saving updated release notes for Chart")
119+
utils.CheckIfError(err, "HELM Failed to save chart manifest: %s", HelmChartPath)
119120
}
120121

121122
// UpdateChartValue Updates the Helm ChartValue

magefiles/steps/release.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func (Release) NewReleaseFromOld(version, oldversion string) {
7474
func (Release) E2EDocs() {
7575
e2edocs, err := utils.GenerateE2EDocs()
7676
utils.CheckIfError(err, "error on template")
77-
err = os.WriteFile("docs/e2e-tests.md", []byte(e2edocs), 644)
77+
err = os.WriteFile("docs/e2e-tests.md", []byte(e2edocs), 0644)
7878
utils.CheckIfError(err, "Could not write new e2e test file ")
7979
}
8080

@@ -158,7 +158,7 @@ func updateIndexMD(old, new string) error {
158158
utils.CheckIfError(err, "Could not read INDEX_DOCS file %s", INDEX_DOCS)
159159
datString := string(data)
160160
datString = strings.Replace(datString, old, new, -1)
161-
err = os.WriteFile(INDEX_DOCS, []byte(datString), 644)
161+
err = os.WriteFile(INDEX_DOCS, []byte(datString), 0644)
162162
if err != nil {
163163
utils.ErrorF("Could not write new %s %s", INDEX_DOCS, err)
164164
return err
@@ -255,7 +255,7 @@ func makeReleaseNotes(newVersion, oldVersion string) (*utils.ReleaseNote, error)
255255

256256
// the newControllerVersion should match the latest tag
257257
if newControllerVersion != allControllerTags[0] {
258-
return nil, errors.New(fmt.Sprintf("Generating release new version %s didnt match the current latest tag %s", newControllerVersion, allControllerTags[0]))
258+
return nil, fmt.Errorf("generating release new version %s didnt match the current latest tag %s", newControllerVersion, allControllerTags[0])
259259
}
260260
// previous version
261261
newReleaseNotes.PreviousControllerVersion = allControllerTags[1]
@@ -272,8 +272,8 @@ func makeReleaseNotes(newVersion, oldVersion string) (*utils.ReleaseNote, error)
272272
var allUpdates []string
273273
var depUpdates []string
274274
var helmUpdates []string
275-
prRegex := regexp.MustCompile("\\(#\\d+\\)")
276-
depBot := regexp.MustCompile("^(\\w){1,10} Bump ")
275+
prRegex := regexp.MustCompile(`\(#\d+\)`)
276+
depBot := regexp.MustCompile(`^(\w){1,10} Bump `)
277277
helmRegex := regexp.MustCompile("helm|chart")
278278
for i, s := range commits {
279279
// matches on PR
@@ -322,13 +322,13 @@ func makeReleaseNotes(newVersion, oldVersion string) (*utils.ReleaseNote, error)
322322
controllerDigest := utils.FindImageDigest(data, "controller", newVersion)
323323
if len(controllerDigest) == 0 {
324324
utils.ErrorF("Controller Digest could not be found")
325-
return nil, errors.New("Controller digest could not be found")
325+
return nil, errors.New("controller digest could not be found")
326326
}
327327

328328
controllerChrootDigest := utils.FindImageDigest(data, "controller-chroot", newVersion)
329329
if len(controllerChrootDigest) == 0 {
330330
utils.ErrorF("Controller Chroot Digest could not be found")
331-
return nil, errors.New("Controller Chroot digest could not be found")
331+
return nil, errors.New("controller chroot digest could not be found")
332332
}
333333

334334
utils.Debug("Latest Controller Digest %v", controllerDigest)

0 commit comments

Comments
 (0)