Skip to content

Commit 0e2e866

Browse files
committed
add gh token
1 parent 2f5d178 commit 0e2e866

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ require (
218218
github.com/benbjohnson/clock v1.3.5
219219
github.com/coder/serpent v0.7.0
220220
github.com/gomarkdown/markdown v0.0.0-20231222211730-1d6d20845b47
221+
github.com/google/go-github/v61 v61.0.0
221222
)
222223

223224
require (

go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,8 @@ github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
469469
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
470470
github.com/google/go-github/v43 v43.0.1-0.20220414155304-00e42332e405 h1:DdHws/YnnPrSywrjNYu2lEHqYHWp/LnEx56w59esd54=
471471
github.com/google/go-github/v43 v43.0.1-0.20220414155304-00e42332e405/go.mod h1:4RgUDSnsxP19d65zJWqvqJ/poJxBCvmna50eXmIvoR8=
472+
github.com/google/go-github/v61 v61.0.0 h1:VwQCBwhyE9JclCI+22/7mLB1PuU9eowCXKY5pNlu1go=
473+
github.com/google/go-github/v61 v61.0.0/go.mod h1:0WR+KmsWX75G2EbpyGsGmradjo3IiciuI4BmdVCobQY=
472474
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
473475
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
474476
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=

scripts/release/main.go

+16-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"strings"
99

1010
"github.com/google/go-cmp/cmp"
11-
"github.com/google/go-github/v43/github"
11+
"github.com/google/go-github/v61/github"
1212
"golang.org/x/mod/semver"
1313
"golang.org/x/xerrors"
1414

@@ -26,12 +26,19 @@ const (
2626
func main() {
2727
logger := slog.Make(sloghuman.Sink(os.Stderr)).Leveled(slog.LevelDebug)
2828

29+
var ghToken string
2930
var dryRun bool
3031

3132
cmd := serpent.Command{
3233
Use: "release <subcommand>",
3334
Short: "Prepare, create and publish releases.",
3435
Options: serpent.OptionSet{
36+
{
37+
Flag: "gh-token",
38+
Description: "GitHub personal access token.",
39+
Env: "GH_TOKEN",
40+
Value: serpent.StringOf(&ghToken),
41+
},
3542
{
3643
Flag: "dry-run",
3744
FlagShorthand: "n",
@@ -48,8 +55,11 @@ func main() {
4855
if len(inv.Args) == 0 {
4956
return xerrors.New("version argument missing")
5057
}
58+
if !dryRun && ghToken == "" {
59+
return xerrors.New("GitHub personal access token is required, use --gh-token or GH_TOKEN")
60+
}
5161

52-
err := promoteVersionToStable(ctx, inv, logger, dryRun, inv.Args[0])
62+
err := promoteVersionToStable(ctx, inv, logger, ghToken, dryRun, inv.Args[0])
5363
if err != nil {
5464
return err
5565
}
@@ -71,8 +81,11 @@ func main() {
7181
}
7282

7383
//nolint:revive // Allow dryRun control flag.
74-
func promoteVersionToStable(ctx context.Context, inv *serpent.Invocation, logger slog.Logger, dryRun bool, version string) error {
84+
func promoteVersionToStable(ctx context.Context, inv *serpent.Invocation, logger slog.Logger, ghToken string, dryRun bool, version string) error {
7585
client := github.NewClient(nil)
86+
if ghToken != "" {
87+
client = client.WithAuthToken(ghToken)
88+
}
7689

7790
logger = logger.With(slog.F("dry_run", dryRun), slog.F("version", version))
7891

0 commit comments

Comments
 (0)