Skip to content
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

publish-release: Support adding release notes from a file #2403

Merged
merged 1 commit into from
Jan 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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