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

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletionsscripts/lib.sh
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -134,18 +134,22 @@ requiredenvs() {
}

gh_auth() {
local fail=0
if [[ "${CODER:-}" == "true" ]]; then
if ! output=$(coder external-auth access-token github 2>&1); then
log "ERROR: Could not authenticate with GitHub."
log "$output"
fail=1
if [[ -z ${GITHUB_TOKEN:-} ]]; then
if [[ -n ${GH_TOKEN:-} ]]; then
Comment on lines +137 to +138
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

We should always get the new token. The token stored inGITHUB_TOKEN may be stale, so I opted to refresh this even though it's set.

coder external-auth access-token github handles the auto-refreshing automatically.

export GITHUB_TOKEN=${GH_TOKEN}
elif [[ ${CODER:-} == true ]]; then
if ! output=$(coder external-auth access-token github 2>&1); then
# TODO(mafredri): We could allow checking `gh auth token` here.
log "${output}"
error "Could not authenticate with GitHub using Coder external auth."
else
export GITHUB_TOKEN=${output}
fi
elif token="$(gh auth token --hostname github.com 2>/dev/null)"; then
export GITHUB_TOKEN=${token}
else
GITHUB_TOKEN=$(coder external-auth access-token github)
export GITHUB_TOKEN
error "GitHub authentication is required to run this command, please set GITHUB_TOKEN or run 'gh auth login'."
fi
else
log "Please authenticate gh CLI by running 'gh auth login'"
fi
}

Expand Down
10 changes: 7 additions & 3 deletionsscripts/release/main.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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),
},
{
Expand DownExpand Up@@ -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)
}
Expand All@@ -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
}

Expand Down
13 changes: 10 additions & 3 deletionsscripts/release/main_internal_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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) {
Expand Down
3 changes: 3 additions & 0 deletionsscripts/release_promote_stable.sh
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,6 +4,9 @@ set -euo pipefail
# shellcheck source=scripts/lib.sh
source"$(dirname"${BASH_SOURCE[0]}")/lib.sh"

# Make sure GITHUB_TOKEN is set for the release command.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This only works whenCODER=true i.e. inside a Coder workspaces.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Do we suggest adding an extra "echo" to indicate it?

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

That’s the expected use-case. And if it isn’t set outside a workspace it’ll print a notice to dogh auth login. Just realized that won’t work though, but we could updatelib.sh to fetch the token viagh auth token in this case.

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Perhaps we also shouldn't override GITHUB_TOKEN if it's set? And maybe support GH_TOKEN too (in lib.sh)? Thoughts@matifali?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Yes as far it works and make it more robust. Let's do this. I don't fully understand the difference betweenGH_ andGITHUB_ prefix for tokens.

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I thinkGH_ is legacy, sometimes still used.

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I refactored it a bit@matifali, if it still looks alright to you, I'll go ahead and merge:9417866

gh_auth

# This script is a convenience wrapper around the release promote command.
#
# Sed hack to make help text look like this script.
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp