Skip to content

Commit

Permalink
Merge pull request #2403 from puerco/pr-release-notes-files
Browse files Browse the repository at this point in the history
publish-release: Support adding release notes from a file
  • Loading branch information
k8s-ci-robot authored Jan 27, 2022
2 parents 13d49df + e885512 commit 085f84d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 17 deletions.
27 changes: 18 additions & 9 deletions cmd/publish-release/cmd/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,16 @@ to the asset file:
}

type githubPageCmdLineOptions struct {
noupdate bool
draft bool
sbom bool
name string
repo string
template string
repoPath string
substitutions []string
assets []string
noupdate bool
draft bool
sbom bool
name string
repo string
template string
repoPath string
ReleaseNotesFile string
substitutions []string
assets []string
}

var ghPageOpts = &githubPageCmdLineOptions{}
Expand Down Expand Up @@ -145,6 +146,13 @@ func init() {
"Path to the source code repository",
)

githubPageCmd.PersistentFlags().StringVar(
&ghPageOpts.ReleaseNotesFile,
"release-notes-file",
"",
"Path to a release notes markdown file to include in the release",
)

for _, f := range []string{"template", "asset"} {
if err := githubPageCmd.MarkPersistentFlagFilename(f); err != nil {
logrus.Error(err)
Expand Down Expand Up @@ -206,6 +214,7 @@ func runGithubPage(opts *githubPageCmdLineOptions) (err error) {
UpdateIfReleaseExists: !opts.noupdate,
Name: opts.name,
Draft: opts.draft,
ReleaseNotesFile: opts.ReleaseNotesFile,
}

// Assign the repository data
Expand Down
25 changes: 17 additions & 8 deletions pkg/announce/github_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,12 @@ const ghPageBody = `{{ if .Substitutions.logo }}
{{ if .Substitutions.changelog }}
See [the CHANGELOG]({{ .Substitutions.changelog }}) for more details.
{{ end }}
### Release Assets
{{ if .Substitutions.ReleaseNotes }}
### Release Notes
{{ range .Assets }}
<table>
<tr><td colspan="2">{{ if .name }}<b>{{ .name }}: </b> {{ .filename }}{{else}}<b>{{ .filename }}</b>{{end}}</td><tr>
<tr><td>SHA256</td><td>{{ .sha256 }}</td></tr>
<tr><td>SHA512</td><td>{{ .sha512 }}</td></tr>
</table>
{{ .Substitutions.ReleaseNotes }}
{{ end }}
{{end}}
`

// GitHubPageOptions data for building the release page
Expand Down Expand Up @@ -99,6 +95,9 @@ type GitHubPageOptions struct {
// file is a go template file that renders markdown.
PageTemplate string

// File to read the release notes from
ReleaseNotesFile string

// We automatizally calculate most values, but more substitutions for
// the template can be supplied
Substitutions map[string]string
Expand Down Expand Up @@ -208,6 +207,16 @@ func UpdateGitHubPage(opts *GitHubPageOptions) (err error) {
Assets: releaseAssets,
}

// If we have a release notes file defined and set a substitution
// entry for its contents
if opts.ReleaseNotesFile != "" {
rnData, err := os.ReadFile(opts.ReleaseNotesFile)
if err != nil {
return errors.Wrap(err, "reading release notes file")
}
subs.Substitutions["ReleaseNotes"] = string(rnData)
}

// Open the template file (if a custom)
templateText := ghPageBody
if opts.PageTemplate != "" {
Expand Down

0 comments on commit 085f84d

Please sign in to comment.