Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf66d044

Browse files
authored
chore(scripts): fix stable release promote script (#13204)
1 parent0998ced commitf66d044

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 github2>&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 github2>&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.com2>/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
iferr!=nil {
250250
returnxerrors.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
funcaddStableSince(date time.Time,bodystring)string {
271+
// Protect against adding twice.
272+
ifstrings.Contains(body,"> ## Stable (since") {
273+
returnbody
274+
}
271275
returnfmt.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-
ifdiff:=cmp.Diff(expected,result);diff!="" {
137+
ifdiff:=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+
ifdiff:=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
funcTest_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)

[8]ページ先頭

©2009-2025 Movatter.jp