chore(scripts): fix stable release promote script (#13204)

This commit is contained in:
Mathias Fredriksson
2024-05-17 08:25:10 +00:00
committed by GitHub
parent 0998cedb5c
commit f66d0445da
4 changed files with 34 additions and 16 deletions
+7 -3
View File
@@ -62,9 +62,9 @@ func main() {
Value: serpent.BoolOf(&r.debug),
},
{
Flag: "gh-token",
Flag: "github-token",
Description: "GitHub personal access token.",
Env: "GH_TOKEN",
Env: "GITHUB_TOKEN",
Value: serpent.StringOf(&r.ghToken),
},
{
@@ -245,7 +245,7 @@ func (r *releaseCommand) promoteVersionToStable(ctx context.Context, inv *serpen
updatedNewStable.Prerelease = github.Bool(false)
updatedNewStable.Draft = github.Bool(false)
if !r.dryRun {
_, _, err = client.Repositories.EditRelease(ctx, owner, repo, newStable.GetID(), newStable)
_, _, err = client.Repositories.EditRelease(ctx, owner, repo, newStable.GetID(), updatedNewStable)
if err != nil {
return xerrors.Errorf("edit release failed: %w", err)
}
@@ -268,6 +268,10 @@ func cloneRelease(r *github.RepositoryRelease) *github.RepositoryRelease {
//
// > ## Stable (since April 23, 2024)
func addStableSince(date time.Time, body string) string {
// Protect against adding twice.
if strings.Contains(body, "> ## Stable (since") {
return body
}
return fmt.Sprintf("> ## Stable (since %s)\n\n", date.Format("January 02, 2006")) + body
}
+10 -3
View File
@@ -131,12 +131,19 @@ func Test_addStableSince(t *testing.T) {
date := time.Date(2024, time.April, 23, 0, 0, 0, 0, time.UTC)
body := "## Changelog"
expected := "> ## Stable (since April 23, 2024)\n\n## Changelog"
result := addStableSince(date, body)
want := "> ## Stable (since April 23, 2024)\n\n## Changelog"
got := addStableSince(date, body)
if diff := cmp.Diff(expected, result); diff != "" {
if diff := cmp.Diff(want, got); diff != "" {
require.Fail(t, "addStableSince() mismatch (-want +got):\n%s", diff)
}
// Test that it doesn't add twice.
got = addStableSince(date, got)
if diff := cmp.Diff(want, got); diff != "" {
require.Fail(t, "addStableSince() mismatch (-want +got):\n%s", diff, "addStableSince() should not add twice")
}
}
func Test_release_autoversion(t *testing.T) {