Skip to content

Commit f66d044

Browse files
authored
chore(scripts): fix stable release promote script (#13204)
1 parent 0998ced commit f66d044

File tree

4 files changed

+34
-16
lines changed

4 files changed

+34
-16
lines changed

scripts/lib.sh

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -134,18 +134,22 @@ requiredenvs() {
134134
}
135135

136136
gh_auth() {
137-
local fail=0
138-
if [[ "${CODER:-}" == "true" ]]; then
139-
if ! output=$(coder external-auth access-token github 2>&1); then
140-
log "ERROR: Could not authenticate with GitHub."
141-
log "$output"
142-
fail=1
137+
if [[ -z ${GITHUB_TOKEN:-} ]]; then
138+
if [[ -n ${GH_TOKEN:-} ]]; then
139+
export GITHUB_TOKEN=${GH_TOKEN}
140+
elif [[ ${CODER:-} == true ]]; then
141+
if ! output=$(coder external-auth access-token github 2>&1); then
142+
# TODO(mafredri): We could allow checking `gh auth token` here.
143+
log "${output}"
144+
error "Could not authenticate with GitHub using Coder external auth."
145+
else
146+
export GITHUB_TOKEN=${output}
147+
fi
148+
elif token="$(gh auth token --hostname github.com 2>/dev/null)"; then
149+
export GITHUB_TOKEN=${token}
143150
else
144-
GITHUB_TOKEN=$(coder external-auth access-token github)
145-
export GITHUB_TOKEN
151+
error "GitHub authentication is required to run this command, please set GITHUB_TOKEN or run 'gh auth login'."
146152
fi
147-
else
148-
log "Please authenticate gh CLI by running 'gh auth login'"
149153
fi
150154
}
151155

scripts/release/main.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ func main() {
6262
Value: serpent.BoolOf(&r.debug),
6363
},
6464
{
65-
Flag: "gh-token",
65+
Flag: "github-token",
6666
Description: "GitHub personal access token.",
67-
Env: "GH_TOKEN",
67+
Env: "GITHUB_TOKEN",
6868
Value: serpent.StringOf(&r.ghToken),
6969
},
7070
{
@@ -245,7 +245,7 @@ func (r *releaseCommand) promoteVersionToStable(ctx context.Context, inv *serpen
245245
updatedNewStable.Prerelease = github.Bool(false)
246246
updatedNewStable.Draft = github.Bool(false)
247247
if !r.dryRun {
248-
_, _, err = client.Repositories.EditRelease(ctx, owner, repo, newStable.GetID(), newStable)
248+
_, _, err = client.Repositories.EditRelease(ctx, owner, repo, newStable.GetID(), updatedNewStable)
249249
if err != nil {
250250
return xerrors.Errorf("edit release failed: %w", err)
251251
}
@@ -268,6 +268,10 @@ func cloneRelease(r *github.RepositoryRelease) *github.RepositoryRelease {
268268
//
269269
// > ## Stable (since April 23, 2024)
270270
func addStableSince(date time.Time, body string) string {
271+
// Protect against adding twice.
272+
if strings.Contains(body, "> ## Stable (since") {
273+
return body
274+
}
271275
return fmt.Sprintf("> ## Stable (since %s)\n\n", date.Format("January 02, 2006")) + body
272276
}
273277

scripts/release/main_internal_test.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,19 @@ func Test_addStableSince(t *testing.T) {
131131
date := time.Date(2024, time.April, 23, 0, 0, 0, 0, time.UTC)
132132
body := "## Changelog"
133133

134-
expected := "> ## Stable (since April 23, 2024)\n\n## Changelog"
135-
result := addStableSince(date, body)
134+
want := "> ## Stable (since April 23, 2024)\n\n## Changelog"
135+
got := addStableSince(date, body)
136136

137-
if diff := cmp.Diff(expected, result); diff != "" {
137+
if diff := cmp.Diff(want, got); diff != "" {
138138
require.Fail(t, "addStableSince() mismatch (-want +got):\n%s", diff)
139139
}
140+
141+
// Test that it doesn't add twice.
142+
got = addStableSince(date, got)
143+
144+
if diff := cmp.Diff(want, got); diff != "" {
145+
require.Fail(t, "addStableSince() mismatch (-want +got):\n%s", diff, "addStableSince() should not add twice")
146+
}
140147
}
141148

142149
func Test_release_autoversion(t *testing.T) {

scripts/release_promote_stable.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ set -euo pipefail
44
# shellcheck source=scripts/lib.sh
55
source "$(dirname "${BASH_SOURCE[0]}")/lib.sh"
66

7+
# Make sure GITHUB_TOKEN is set for the release command.
8+
gh_auth
9+
710
# This script is a convenience wrapper around the release promote command.
811
#
912
# Sed hack to make help text look like this script.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy