Skip to content

Commit

Permalink
release-tool: Add CHANGELOG/README.md
Browse files Browse the repository at this point in the history
It is automatically updated so that it contains a link to the
release notes for the most recent version.

In the future it would be nice to have an ordered list of
releases in the file too, but that's a task for another day.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
  • Loading branch information
andreabolognani committed Nov 13, 2023
1 parent b90b821 commit 69daba2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
34 changes: 27 additions & 7 deletions releng/release-tool/release-tool.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,14 @@ type releaseData struct {
name string
newBranch string

tagBranch string
tag string
promoteRC string
promoteRCTime time.Time
previousTag string
releaseNotesFile string
skipReleaseNotes bool
tagBranch string
tag string
promoteRC string
promoteRCTime time.Time
previousTag string
releaseNotesFile string
releaseNotesReadme string
skipReleaseNotes bool

force bool

Expand Down Expand Up @@ -91,6 +92,7 @@ func (r *releaseData) generateReleaseNotes() error {

releaseNotesDir := fmt.Sprintf("%s/CHANGELOG", r.repoDir)
r.releaseNotesFile = fmt.Sprintf("%s/CHANGELOG-%s.md", releaseNotesDir, r.tag)
r.releaseNotesReadme = fmt.Sprintf("%s/README.md", releaseNotesDir)

err := os.Mkdir(releaseNotesDir, 0755)
if err != nil && !os.IsExist(err) {
Expand Down Expand Up @@ -219,6 +221,19 @@ func (r *releaseData) generateReleaseNotes() error {
}

f.WriteString(additionalResources)

g, err := os.Create(r.releaseNotesReadme)
if err != nil {
return err
}
defer g.Close()

g.WriteString(fmt.Sprintf("# %s release notes\n", r.name))
g.WriteString("\n")
g.WriteString(fmt.Sprintf("The most recent release is [%s](CHANGELOG-%s.md).\n", r.tag, r.tag))

// TODO list past releases too

return nil
}

Expand Down Expand Up @@ -340,6 +355,11 @@ func (r *releaseData) makeTag(branch string) error {
return err
}

_, err = gitCommand("-C", r.repoDir, "add", r.releaseNotesReadme)
if err != nil {
return err
}

_, err = gitCommand("-C", r.repoDir, "commit", "-s", "-m", fmt.Sprintf("CHANGELOG: Add release notes for %s", r.tag))
if err != nil {
return err
Expand Down
1 change: 1 addition & 0 deletions releng/release-tool/release-tool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@ func TestNewTag(t *testing.T) {
expectedGitCommands = append(expectedGitCommands, fmt.Sprintf("git [-C %s/fake-org/https-fake-repo checkout release-0.2]", r.cacheDir))
expectedGitCommands = append(expectedGitCommands, fmt.Sprintf("git [-C %s/fake-org/https-fake-repo pull origin release-0.2]", r.cacheDir))
expectedGitCommands = append(expectedGitCommands, fmt.Sprintf("git [-C %s/fake-org/https-fake-repo add %s/fake-org/https-fake-repo/CHANGELOG/CHANGELOG-v0.2.0.md]", r.cacheDir, r.cacheDir))
expectedGitCommands = append(expectedGitCommands, fmt.Sprintf("git [-C %s/fake-org/https-fake-repo add %s/fake-org/https-fake-repo/CHANGELOG/README.md]", r.cacheDir, r.cacheDir))
expectedGitCommands = append(expectedGitCommands, fmt.Sprintf("git [-C %s/fake-org/https-fake-repo commit -s -m CHANGELOG: Add release notes for v0.2.0]", r.cacheDir))
expectedGitCommands = append(expectedGitCommands, fmt.Sprintf("git [-C %s/fake-org/https-fake-repo tag -s -m FakeName v0.2.0 v0.2.0]", r.cacheDir))
expectedGitCommands = append(expectedGitCommands, fmt.Sprintf("git [-C %s/fake-org/https-fake-repo push https://fake-token@github.com/fake-org/fake-repo.git v0.2.0]", r.cacheDir))
Expand Down

0 comments on commit 69daba2

Please sign in to comment.