mirror of
https://github.com/coder/coder.git
synced 2026-06-02 20:48:20 +00:00
chore(scripts): fix stable release promote script (#13204)
This commit is contained in:
committed by
GitHub
parent
0998cedb5c
commit
f66d0445da
+12
-8
@@ -134,18 +134,22 @@ requiredenvs() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
gh_auth() {
|
gh_auth() {
|
||||||
local fail=0
|
if [[ -z ${GITHUB_TOKEN:-} ]]; then
|
||||||
if [[ "${CODER:-}" == "true" ]]; then
|
if [[ -n ${GH_TOKEN:-} ]]; then
|
||||||
|
export GITHUB_TOKEN=${GH_TOKEN}
|
||||||
|
elif [[ ${CODER:-} == true ]]; then
|
||||||
if ! output=$(coder external-auth access-token github 2>&1); then
|
if ! output=$(coder external-auth access-token github 2>&1); then
|
||||||
log "ERROR: Could not authenticate with GitHub."
|
# TODO(mafredri): We could allow checking `gh auth token` here.
|
||||||
log "$output"
|
log "${output}"
|
||||||
fail=1
|
error "Could not authenticate with GitHub using Coder external auth."
|
||||||
else
|
else
|
||||||
GITHUB_TOKEN=$(coder external-auth access-token github)
|
export GITHUB_TOKEN=${output}
|
||||||
export GITHUB_TOKEN
|
|
||||||
fi
|
fi
|
||||||
|
elif token="$(gh auth token --hostname github.com 2>/dev/null)"; then
|
||||||
|
export GITHUB_TOKEN=${token}
|
||||||
else
|
else
|
||||||
log "Please authenticate gh CLI by running 'gh auth login'"
|
error "GitHub authentication is required to run this command, please set GITHUB_TOKEN or run 'gh auth login'."
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -62,9 +62,9 @@ func main() {
|
|||||||
Value: serpent.BoolOf(&r.debug),
|
Value: serpent.BoolOf(&r.debug),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Flag: "gh-token",
|
Flag: "github-token",
|
||||||
Description: "GitHub personal access token.",
|
Description: "GitHub personal access token.",
|
||||||
Env: "GH_TOKEN",
|
Env: "GITHUB_TOKEN",
|
||||||
Value: serpent.StringOf(&r.ghToken),
|
Value: serpent.StringOf(&r.ghToken),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -245,7 +245,7 @@ func (r *releaseCommand) promoteVersionToStable(ctx context.Context, inv *serpen
|
|||||||
updatedNewStable.Prerelease = github.Bool(false)
|
updatedNewStable.Prerelease = github.Bool(false)
|
||||||
updatedNewStable.Draft = github.Bool(false)
|
updatedNewStable.Draft = github.Bool(false)
|
||||||
if !r.dryRun {
|
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 {
|
if err != nil {
|
||||||
return xerrors.Errorf("edit release failed: %w", err)
|
return xerrors.Errorf("edit release failed: %w", err)
|
||||||
}
|
}
|
||||||
@@ -268,6 +268,10 @@ func cloneRelease(r *github.RepositoryRelease) *github.RepositoryRelease {
|
|||||||
//
|
//
|
||||||
// > ## Stable (since April 23, 2024)
|
// > ## Stable (since April 23, 2024)
|
||||||
func addStableSince(date time.Time, body string) string {
|
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
|
return fmt.Sprintf("> ## Stable (since %s)\n\n", date.Format("January 02, 2006")) + body
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -131,12 +131,19 @@ func Test_addStableSince(t *testing.T) {
|
|||||||
date := time.Date(2024, time.April, 23, 0, 0, 0, 0, time.UTC)
|
date := time.Date(2024, time.April, 23, 0, 0, 0, 0, time.UTC)
|
||||||
body := "## Changelog"
|
body := "## Changelog"
|
||||||
|
|
||||||
expected := "> ## Stable (since April 23, 2024)\n\n## Changelog"
|
want := "> ## Stable (since April 23, 2024)\n\n## Changelog"
|
||||||
result := addStableSince(date, body)
|
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)
|
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) {
|
func Test_release_autoversion(t *testing.T) {
|
||||||
|
|||||||
@@ -4,6 +4,9 @@ set -euo pipefail
|
|||||||
# shellcheck source=scripts/lib.sh
|
# shellcheck source=scripts/lib.sh
|
||||||
source "$(dirname "${BASH_SOURCE[0]}")/lib.sh"
|
source "$(dirname "${BASH_SOURCE[0]}")/lib.sh"
|
||||||
|
|
||||||
|
# Make sure GITHUB_TOKEN is set for the release command.
|
||||||
|
gh_auth
|
||||||
|
|
||||||
# This script is a convenience wrapper around the release promote command.
|
# This script is a convenience wrapper around the release promote command.
|
||||||
#
|
#
|
||||||
# Sed hack to make help text look like this script.
|
# Sed hack to make help text look like this script.
|
||||||
|
|||||||
Reference in New Issue
Block a user