-
Notifications
You must be signed in to change notification settings - Fork 1
Align release files with our current approach #1326
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
7db8b4f
71ebe42
aacbf2b
6189692
23314c4
f9c0cac
70e202b
51005f2
234d07b
46f1798
c8a90f6
21c689f
bc0e5a8
6b803df
f5b1e6b
5be074b
99edf53
b0a4328
5924d25
55701df
1ebfb31
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -144,3 +144,66 @@ func findRelease(providerDirectory string, targetVersion semver.Version) (v1alph | |
|
||
return release, releaseYAMLPath, nil | ||
} | ||
|
||
// marshalReleaseYAML creates a custom YAML representation of the release | ||
// with proper field ordering and without unwanted fields like status and creationTimestamp | ||
func marshalReleaseYAML(release v1alpha1.Release) ([]byte, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That is the simplest way of creating a release yaml without any extra fields like Also it is super hard to change the order for
instead of what we have:
|
||
var sb strings.Builder | ||
|
||
// API version and kind | ||
sb.WriteString("apiVersion: release.giantswarm.io/v1alpha1\n") | ||
sb.WriteString("kind: Release\n") | ||
|
||
// Metadata (without creationTimestamp) | ||
sb.WriteString("metadata:\n") | ||
sb.WriteString(" name: " + release.Name + "\n") | ||
|
||
// Spec | ||
sb.WriteString("spec:\n") | ||
|
||
// Apps section | ||
if len(release.Spec.Apps) > 0 { | ||
sb.WriteString(" apps:\n") | ||
for _, app := range release.Spec.Apps { | ||
sb.WriteString(" - name: " + app.Name + "\n") | ||
|
||
// Add catalog if present | ||
if app.Catalog != "" { | ||
sb.WriteString(" catalog: " + app.Catalog + "\n") | ||
} | ||
|
||
sb.WriteString(" version: " + app.Version + "\n") | ||
|
||
// Add dependsOn if present | ||
if len(app.DependsOn) > 0 { | ||
sb.WriteString(" dependsOn:\n") | ||
for _, dep := range app.DependsOn { | ||
sb.WriteString(" - " + dep + "\n") | ||
} | ||
} | ||
} | ||
} | ||
|
||
// Components section | ||
if len(release.Spec.Components) > 0 { | ||
sb.WriteString(" components:\n") | ||
for _, component := range release.Spec.Components { | ||
sb.WriteString(" - name: " + component.Name + "\n") | ||
|
||
// Add catalog if present | ||
if component.Catalog != "" { | ||
sb.WriteString(" catalog: " + component.Catalog + "\n") | ||
} | ||
|
||
sb.WriteString(" version: " + component.Version + "\n") | ||
} | ||
} | ||
|
||
// Date and state | ||
if release.Spec.Date != nil { | ||
sb.WriteString(" date: \"" + release.Spec.Date.Format("2006-01-02T15:04:05Z") + "\"\n") | ||
} | ||
sb.WriteString(" state: " + string(release.Spec.State) + "\n") | ||
|
||
return []byte(sb.String()), nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
package release | ||
|
||
import ( | ||
"regexp" | ||
"strings" | ||
"text/template" | ||
|
||
|
@@ -18,40 +19,17 @@ const releaseNotesTemplate = `# :zap: Giant Swarm Release {{ .Name }} for {{ .Pr | |
|
||
### Components | ||
|
||
{{ range .Components }} | ||
{{ if eq .PreviousVersion "" }} | ||
* Added {{ .Name }} [{{ .Version }}]({{ .Link }}) | ||
{{ else if eq .Name "kubernetes" }} | ||
* {{ .Name }} from v{{ .PreviousVersion }} to [v{{ .Version }}]({{ .Link }}) | ||
{{ else }} | ||
* {{ .Name }} from {{ .PreviousVersion }} to [{{ .Version }}]({{ .Link }}) | ||
{{ end }} | ||
{{ end }} | ||
|
||
{{ range .Components }} | ||
{{ if or (eq .Name "kubernetes") (eq .Name "flatcar") }} | ||
{{continue}} | ||
{{ range .Components }}- {{ if eq .PreviousVersion "" }}Added {{ .Name }} {{ .Version }}{{ else if eq .Name "kubernetes" }}Kubernetes from v{{ .PreviousVersion }} to [v{{ .Version }}]({{ .Link }}){{ else if eq .Name "flatcar" }}Flatcar from {{ .PreviousVersion }} to [{{ .Version }}]({{ .Link }}){{ else }}{{ .Name }} from v{{ .PreviousVersion }} to v{{ .Version }}{{ end }} | ||
njuettner marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{{ end }} | ||
|
||
{{ .Changelog }} | ||
|
||
{{ end }} | ||
{{ range .Components }}{{ if or (eq .Name "kubernetes") (eq .Name "flatcar") }}{{ continue }}{{ end }}{{ .Changelog }}{{ end }} | ||
|
||
### Apps | ||
|
||
{{ range .Apps }} | ||
{{ if eq .PreviousVersion "" }} | ||
* Added {{ .Name }} [{{ .Version }}]({{ .Link }}) | ||
{{ else }} | ||
* {{ .Name }} from {{ .PreviousVersion }} to [{{ .Version }}]({{ .Link }}) | ||
{{ range .Apps }}- {{ if eq .PreviousVersion "" }}Added {{ .Name }} {{ .Version }}{{ else }}{{ .Name }} from {{ .PreviousVersion }} to {{ .Version }}{{ end }} | ||
{{ end }} | ||
{{ end }} | ||
|
||
{{ range .Apps }} | ||
|
||
{{ .Changelog }} | ||
|
||
{{ end }} | ||
{{ range .Apps }}{{ .Changelog }}{{ end }} | ||
` | ||
|
||
type releaseNotes struct { | ||
|
@@ -110,6 +88,7 @@ func createReleaseNotes(release, baseRelease v1alpha1.Release, provider string) | |
if err != nil { | ||
return "", microerror.Mask(err) | ||
} | ||
|
||
components = append(components, releaseNotes{ | ||
Name: component.Name, | ||
Version: component.Version, | ||
|
@@ -161,5 +140,32 @@ func createReleaseNotes(release, baseRelease v1alpha1.Release, provider string) | |
return "", microerror.Mask(err) | ||
} | ||
|
||
return writer.String(), nil | ||
result := writer.String() | ||
|
||
// Clean up the output to remove excess blank lines | ||
result = cleanReleaseNotes(result) | ||
return result, nil | ||
} | ||
|
||
// cleanReleaseNotes removes excess blank lines from the generated release notes | ||
func cleanReleaseNotes(notes string) string { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I need that for making nice formatting. I highlighted an example in the PR body |
||
multipleNewlines := regexp.MustCompile(`\n{3,}`) | ||
notes = multipleNewlines.ReplaceAllString(notes, "\n\n") | ||
|
||
compList := regexp.MustCompile(`(- [^\n]+\n)(\n*)(### [^\n]+)`) | ||
notes = compList.ReplaceAllString(notes, "$1\n\n$3") | ||
|
||
betweenChangelogs := regexp.MustCompile(`(### [^\n]+[\s\S]+?)(\n{2,})(### [^\n]+)`) | ||
notes = betweenChangelogs.ReplaceAllString(notes, "$1\n\n$3") | ||
|
||
endNewlines := regexp.MustCompile(`\n{2,}$`) | ||
notes = endNewlines.ReplaceAllString(notes, "\n") | ||
|
||
notes = regexp.MustCompile(`### Components\n{2,}`).ReplaceAllString(notes, "### Components\n\n") | ||
notes = regexp.MustCompile(`### Apps\n{2,}`).ReplaceAllString(notes, "### Apps\n\n") | ||
|
||
bulletPoints := regexp.MustCompile(`(- [^\n]+)\n{2,}(- [^\n]+)`) | ||
notes = bulletPoints.ReplaceAllString(notes, "$1\n$2") | ||
|
||
return notes | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added new components, those were missing