Skip to content

Commit f8f496c

Browse files
committed
update body instead of title, stable since
1 parent f075baa commit f8f496c

File tree

2 files changed

+29
-18
lines changed

2 files changed

+29
-18
lines changed

scripts/release/main.go

+14-18
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ package main
33
import (
44
"context"
55
"errors"
6+
"fmt"
67
"os"
78
"slices"
89
"strings"
10+
"time"
911

1012
"github.com/google/go-cmp/cmp"
1113
"github.com/google/go-github/v61/github"
@@ -154,8 +156,9 @@ func promoteVersionToStable(ctx context.Context, inv *serpent.Invocation, logger
154156
// Update the release to latest.
155157
updatedNewStable := cloneRelease(newStable)
156158

157-
updatedNewStable.Name = github.String(newStable.GetName() + " (Stable)")
158-
updatedNewStable.Body = github.String(removeMainlineBlurb(newStable.GetBody()))
159+
updatedBody := removeMainlineBlurb(newStable.GetBody())
160+
updatedBody = addStableSince(time.Now().UTC(), updatedBody)
161+
updatedNewStable.Body = github.String(updatedBody)
159162
updatedNewStable.Prerelease = github.Bool(false)
160163
updatedNewStable.Draft = github.Bool(false)
161164
if !dryRun {
@@ -168,22 +171,6 @@ func promoteVersionToStable(ctx context.Context, inv *serpent.Invocation, logger
168171
logger.Info(ctx, "dry-run: release not updated", "uncommitted_changes", cmp.Diff(newStable, updatedNewStable))
169172
}
170173

171-
logger.Info(ctx, "updating title of the previous stable release (remove stable suffix)")
172-
173-
// Update the previous stable release to a regular release.
174-
updatedOldStable := cloneRelease(currentStable)
175-
currentStable.Name = github.String(strings.TrimSuffix(currentStable.GetName(), " (Stable)"))
176-
177-
if !dryRun {
178-
_, _, err = client.Repositories.EditRelease(ctx, owner, repo, currentStable.GetID(), currentStable)
179-
if err != nil {
180-
return err
181-
}
182-
logger.Info(ctx, "title of the previous stable release updated")
183-
} else {
184-
logger.Info(ctx, "dry-run: previous release not updated", "uncommitted_changes", cmp.Diff(currentStable, updatedOldStable))
185-
}
186-
187174
return nil
188175
}
189176

@@ -192,6 +179,15 @@ func cloneRelease(r *github.RepositoryRelease) *github.RepositoryRelease {
192179
return &rr
193180
}
194181

182+
// addStableSince adds a stable since note to the release body.
183+
//
184+
// Example:
185+
//
186+
// > ## Stable (since April 23, 2024)
187+
func addStableSince(date time.Time, body string) string {
188+
return fmt.Sprintf("> ## Stable (since %s)\n\n", date.Format("January 02, 2006")) + body
189+
}
190+
195191
// removeMainlineBlurb removes the mainline blurb from the release body.
196192
//
197193
// Example:

scripts/release/main_test.go

+15
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"testing"
5+
"time"
56

67
"github.com/google/go-cmp/cmp"
78
)
@@ -99,3 +100,17 @@ Refer to our docs to [install](https://coder.com/docs/v2/latest/install) or [upg
99100
})
100101
}
101102
}
103+
104+
func Test_addStableSince(t *testing.T) {
105+
t.Parallel()
106+
107+
date := time.Date(2024, time.April, 23, 0, 0, 0, 0, time.UTC)
108+
body := "## Changelog"
109+
110+
expected := "> ## Stable (since April 23, 2024)\n\n## Changelog"
111+
result := addStableSince(date, body)
112+
113+
if diff := cmp.Diff(expected, result); diff != "" {
114+
t.Errorf("addStableSince() mismatch (-want +got):\n%s", diff)
115+
}
116+
}

0 commit comments

Comments
 (0)