Skip to content

Commit

Permalink
[release tool] pass in GitHub token as flag for actual release (#9596)
Browse files Browse the repository at this point in the history
* pass in GitHub token as flag for actual release

* CI fix
  • Loading branch information
radTuti authored Dec 13, 2024
1 parent cbcdac2 commit 889f33c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
6 changes: 6 additions & 0 deletions release/cmd/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,12 @@ var (
Name: "publish-github-release",
Usage: "Publish the release to GitHub",
Value: true,
Action: func(c *cli.Context, b bool) error {
if b && c.String(githubTokenFlag.Name) == "" {
return fmt.Errorf("GitHub token is required to publish release")
}
return nil
},
}
)

Expand Down
3 changes: 3 additions & 0 deletions release/cmd/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ func releaseSubCommands(cfg *Config) []*cli.Command {
calico.WithPublishImages(c.Bool(publishImagesFlag.Name)),
calico.WithPublishGitTag(c.Bool(publishGitTagFlag.Name)),
calico.WithPublishGithubRelease(c.Bool(publishGitHubReleaseFlag.Name)),
calico.WithGithubToken(c.String(githubTokenFlag.Name)),
}
if reg := c.StringSlice(registryFlag.Name); len(reg) > 0 {
opts = append(opts, calico.WithImageRegistries(reg))
Expand All @@ -155,6 +156,7 @@ func releaseBuildFlags() []cli.Flag {
archFlag,
registryFlag,
buildImagesFlag,
githubTokenFlag,
skipValidationFlag)
return f
}
Expand All @@ -166,6 +168,7 @@ func releasePublishFlags() []cli.Flag {
publishImagesFlag,
publishGitTagFlag,
publishGitHubReleaseFlag,
githubTokenFlag,
skipValidationFlag)
return f
}
10 changes: 3 additions & 7 deletions release/pkg/manager/calico/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@ type CalicoManager struct {
// image scanning configuration.
imageScanning bool
imageScanningConfig imagescanner.Config

// external configuration.
githubToken string
}

func releaseImages(version, operatorVersion string) []string {
Expand Down Expand Up @@ -520,13 +523,6 @@ func (r *CalicoManager) releasePrereqs() error {
return fmt.Errorf("cannot cut release from branch: %s", branch)
}

// Make sure we have a github token - needed for publishing to GH.
// Strictly only needed for publishing, but we check during release anyway so
// that we don't get all the way through the build to find out we're missing it!
if token := os.Getenv("GITHUB_TOKEN"); token == "" {
return fmt.Errorf("no GITHUB_TOKEN present in environment")
}

// If we are releasing to projectcalico/calico, make sure we are releasing to the default registries.
if r.githubOrg == utils.ProjectCalicoOrg && r.repo == utils.CalicoRepoName {
if !reflect.DeepEqual(r.imageRegistries, defaultRegistries) {
Expand Down
7 changes: 7 additions & 0 deletions release/pkg/manager/calico/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,10 @@ func WithImageScanning(scanning bool, cfg imagescanner.Config) Option {
return nil
}
}

func WithGithubToken(token string) Option {
return func(r *CalicoManager) error {
r.githubToken = token
return nil
}
}

0 comments on commit 889f33c

Please sign in to comment.