Skip to content

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

Merged
merged 21 commits into from
Jun 17, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions pkg/release/changelog/changelog.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ var knownComponentParseParams = map[string]parseParams{
start: commonStartPattern,
end: commonEndPattern,
},
"aws-pod-identity-webhook": {
Copy link
Member Author

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

tag: "https://github.com/giantswarm/aws-pod-identity-webhook/releases/tag/v{{.Version}}",
changelog: "https://raw.githubusercontent.com/giantswarm/aws-pod-identity-webhook/v{{.Version}}/CHANGELOG.md",
start: commonStartPattern,
end: commonEndPattern,
},
"cluster-aws": {
tag: "https://github.com/giantswarm/cluster-aws/releases/tag/v{{.Version}}",
changelog: "https://raw.githubusercontent.com/giantswarm/cluster-aws/v{{.Version}}/CHANGELOG.md",
Expand Down Expand Up @@ -199,6 +205,18 @@ var knownComponentParseParams = map[string]parseParams{
start: commonStartPattern,
end: commonEndPattern,
},
"coredns-extensions": {
tag: "https://github.com/giantswarm/coredns-extensions-app/releases/tag/v{{.Version}}",
changelog: "https://raw.githubusercontent.com/giantswarm/coredns-extensions-app/v{{.Version}}/CHANGELOG.md",
start: commonStartPattern,
end: commonEndPattern,
},
"etcd-defrag": {
tag: "https://github.com/giantswarm/etcd-defrag-app/releases/tag/v{{.Version}}",
changelog: "https://raw.githubusercontent.com/giantswarm/etcd-defrag-app/v{{.Version}}/CHANGELOG.md",
start: commonStartPattern,
end: commonEndPattern,
},
"etcd-k8s-res-count-exporter": {
tag: "https://github.com/giantswarm/etcd-kubernetes-resources-count-exporter/releases/tag/v{{.Version}}",
changelog: "https://raw.githubusercontent.com/giantswarm/etcd-kubernetes-resources-count-exporter/v{{.Version}}/CHANGELOG.md",
Expand Down
9 changes: 2 additions & 7 deletions pkg/release/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/giantswarm/release-operator/v4/api/v1alpha1"
"github.com/mohae/deepcopy"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/yaml"
)

// CreateRelease creates a release on the filesystem from the given parameters. This is the entry point
Expand Down Expand Up @@ -104,15 +103,11 @@ func CreateRelease(name, base, releases, provider string, components, apps []str

// Release CR
releaseYAMLPath := filepath.Join(releasePath, "release.yaml")
releaseYAML, err := yaml.Marshal(newRelease)
releaseYAML, err := marshalReleaseYAML(newRelease)
if err != nil {
return microerror.Mask(err)
}
// Prepend command used for creation
{
yamlComment := []byte(fmt.Sprintf("# Generated with:\n# %s\n", creationCommand))
releaseYAML = append(yamlComment, releaseYAML...)
}

err = os.WriteFile(releaseYAMLPath, releaseYAML, 0644) //nolint:gosec
if err != nil {
return microerror.Mask(err)
Expand Down
63 changes: 63 additions & 0 deletions pkg/release/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Copy link
Member Author

Choose a reason for hiding this comment

The 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 status fields or creationTimestamp.

Also it is super hard to change the order for yaml when using any libraries because the ordering would look like:

- dependsOn:
  - cloud-provider-aws
  name: aws-ebs-csi-driver
  version: 3.0.5

instead of what we have:

- name: aws-ebs-csi-driver
  version: 3.0.5
  dependsOn:
  - cloud-provider-aws

I know looks hacky but it is the simplest way of not getting any headaches.

Using the default YAML marshaler with custom struct tags wouldn't give us the precise field ordering control needed.

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
}
62 changes: 34 additions & 28 deletions pkg/release/release_notes.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package release

import (
"regexp"
"strings"
"text/template"

Expand All @@ -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 }}
{{ 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 {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Copy link
Member Author

Choose a reason for hiding this comment

The 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
}