Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release tool] add making draft releases public #9513

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,13 @@ release/bin/release: $(shell find ./release -type f -name '*.go')
bin/ghr:
$(DOCKER_RUN) -e GOBIN=/go/src/$(PACKAGE_NAME)/bin/ $(CALICO_BUILD) go install github.com/tcnksm/ghr@$(GHR_VERSION)

# Install GitHub CLI
bin/gh:
curl -sSL -o bin/gh.tgz https://github.com/cli/cli/releases/download/v$(GITHUB_CLI_VERSION)/gh_$(GITHUB_CLI_VERSION)_linux_amd64.tar.gz
tar -zxvf bin/gh.tgz -C bin/ gh_$(GITHUB_CLI_VERSION)_linux_amd64/bin/gh --strip-components=2
chmod +x $@
rm bin/gh.tgz

# Build a release.
release: release/bin/release
@release/bin/release release build
Expand All @@ -129,6 +136,9 @@ release: release/bin/release
release-publish: release/bin/release bin/ghr
@release/bin/release release publish

release-public: bin/gh release/bin/release
@release/bin/release release public

# Create a release branch.
create-release-branch: release/bin/release
@release/bin/release branch cut -git-publish
Expand Down
1 change: 1 addition & 0 deletions metadata.mk
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ KIND_VERSION=v0.24.0
PROTOC_VER=v0.1
UBI_VERSION=8.10
GHR_VERSION=v0.17.0
GITHUB_CLI_VERSION=2.26.0

# Configuration for Semaphore/Github integration.
ORGANIZATION = projectcalico
Expand Down
45 changes: 45 additions & 0 deletions release/build/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,9 @@ func hashreleaseSubCommands(cfg *config.Config) []*cli.Command {
operator.WithValidate(!c.Bool(skipValidationFlag)),
operator.WithReleaseBranchValidation(!c.Bool(skipBranchCheckFlag)),
operator.WithVersion(versions.OperatorVersion.FormattedString()),
operator.WithGithubOrg(c.String(operatorOrgFlag)),
operator.WithRepoName(c.String(operatorRepoFlag)),
operator.WithRepoRemote(cfg.Operator.GitRemote),
}
o := operator.NewManager(operatorOpts...)
if err := o.Build(cfg.TmpFolderPath()); err != nil {
Expand Down Expand Up @@ -461,6 +464,48 @@ func releaseSubCommands(cfg *config.Config) []*cli.Command {
return r.PublishRelease()
},
},

// Make a published release available to the public.
{
Name: "public",
Usage: "Make a published release available to the public",
Flags: []cli.Flag{
&cli.StringFlag{Name: orgFlag, Usage: "Git organization", EnvVars: []string{"ORGANIZATION"}, Value: config.DefaultOrg},
&cli.StringFlag{Name: repoFlag, Usage: "Git repository", EnvVars: []string{"GIT_REPO"}, Value: config.DefaultRepo},
&cli.StringFlag{Name: operatorOrgFlag, Usage: "Operator git organization", EnvVars: []string{"OPERATOR_GIT_ORGANIZATION"}, Value: config.OperatorDefaultOrg},
&cli.StringFlag{Name: operatorRepoFlag, Usage: "Operator git repository", EnvVars: []string{"OPERATOR_GIT_REPO"}, Value: config.OperatorDefaultRepo},
},
Action: func(c *cli.Context) error {
configureLogging("release-public.log")
ver, operatorVer, err := version.VersionsFromManifests(cfg.RepoRootDir)
if err != nil {
return err
}
opts := []calico.Option{
calico.WithRepoRoot(cfg.RepoRootDir),
calico.WithVersions(&version.Data{
ProductVersion: ver,
OperatorVersion: operatorVer,
}),
calico.WithGithubOrg(c.String(orgFlag)),
calico.WithRepoName(c.String(repoFlag)),
calico.WithRepoRemote(cfg.GitRemote),
}
m := calico.NewManager(opts...)
if err := m.ReleasePublic(); err != nil {
return err
}
opOpts := []operator.Option{
operator.WithVersion(operatorVer.FormattedString()),
operator.WithCalicoDirectory(cfg.RepoRootDir),
operator.WithGithubOrg(c.String(operatorOrgFlag)),
operator.WithRepoName(c.String(operatorRepoFlag)),
operator.WithRepoRemote(cfg.Operator.GitRemote),
}
o := operator.NewManager(opOpts...)
return o.ReleasePublic()
},
},
}
}

Expand Down
28 changes: 28 additions & 0 deletions release/pkg/manager/calico/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (

"github.com/projectcalico/calico/release/internal/command"
"github.com/projectcalico/calico/release/internal/utils"
"github.com/projectcalico/calico/release/internal/version"
)

// Global configuration for releases.
Expand Down Expand Up @@ -457,6 +458,33 @@ func (r *CalicoManager) PublishRelease() error {
return nil
}

func (r *CalicoManager) ReleasePublic() error {
// Get the latest version
args := []string{
"release", "list", "--repo", fmt.Sprintf("%s/%s", r.githubOrg, r.repo),
"--exclude-drafts", "--exclude-prereleases", "--json 'name,isLatest'",
"--jq '.[] | select(.isLatest) | .name'",
}
out, err := r.runner.RunInDir(r.repoRoot, "./bin/gh", args, nil)
if err != nil {
return fmt.Errorf("failed to get latest release: %s", err)
}
args = []string{
"release", "edit", r.calicoVersion, "--draft=false",
"--repo", fmt.Sprintf("%s/%s", r.githubOrg, r.repo),
}
latest := version.New(strings.TrimSpace(out))
current := version.New(r.calicoVersion)
if current.Semver().GreaterThan(latest.Semver()) {
args = append(args, "--latest")
}
_, err = r.runner.RunInDir(r.repoRoot, "./bin/gh", args, nil)
if err != nil {
return fmt.Errorf("failed to publish %s draft release: %s", err)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return fmt.Errorf("failed to publish %s draft release: %s", err)
return fmt.Errorf("failed to publish %s draft release: %s", r.version, err)

}
return nil
}

// Check general prerequisites for cutting and publishing a release.
func (r *CalicoManager) releasePrereqs() error {
// Check that we're not on the master branch. We never cut releases from master.
Expand Down
49 changes: 47 additions & 2 deletions release/pkg/manager/operator/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/projectcalico/calico/release/internal/pinnedversion"
"github.com/projectcalico/calico/release/internal/registry"
"github.com/projectcalico/calico/release/internal/utils"
"github.com/projectcalico/calico/release/internal/version"
"github.com/projectcalico/calico/release/pkg/manager/branch"
)

Expand All @@ -43,6 +44,9 @@ type OperatorManager struct {
// dir is the absolute path to the root directory of the operator repository
dir string

// calicoDir is the absolute path to the root directory of the calico repository
calicoDir string

// origin remote repository
remote string

Expand Down Expand Up @@ -91,8 +95,17 @@ func NewManager(opts ...Option) *OperatorManager {
}
}

if o.dir == "" {
logrus.Fatal("No repository root specified")
if o.githubOrg == "" {
logrus.Fatal("GitHub organization not specified")
}
if o.repoName == "" {
logrus.Fatal("GitHub repository not specified")
}
if o.remote == "" {
logrus.Fatal("No git remote specified")
}
if o.version == "" {
logrus.Fatal("No operator version specified")
}

return o
Expand Down Expand Up @@ -149,6 +162,9 @@ func (o *OperatorManager) Build(outputDir string) error {
}

func (o *OperatorManager) PreBuildValidation(outputDir string) error {
if o.dir == "" {
logrus.Fatal("No repository root specified")
}
if !o.isHashRelease {
return fmt.Errorf("operator manager builds only for hash releases")
}
Expand Down Expand Up @@ -247,6 +263,35 @@ func (o *OperatorManager) PrePublishValidation() error {
return nil
}

func (r *OperatorManager) ReleasePublic() error {
// Get the latest version
args := []string{
"release", "list", "--repo", fmt.Sprintf("%s/%s", r.githubOrg, r.repoName),
"--exclude-drafts", "--exclude-prereleases", "--json 'name,isLatest'",
"--jq '.[] | select(.isLatest) | .name'",
}
out, err := r.runner.RunInDir(r.calicoDir, "./bin/gh", args, nil)
if err != nil {
return fmt.Errorf("failed to get latest release: %s", err)
}

// Publish the draft release
args = []string{
"release", "edit", r.version, "--draft=false",
"--repo", fmt.Sprintf("%s/%s", r.githubOrg, r.repoName),
}
latest := version.New(strings.TrimSpace(out))
current := version.New(r.version)
if current.Semver().GreaterThan(latest.Semver()) {
args = append(args, "--latest")
}
_, err = r.runner.RunInDir(r.calicoDir, "./bin/gh", args, nil)
if err != nil {
return fmt.Errorf("failed to publish %s draft release: %s", r.version, err)
}
return nil
}

func (o *OperatorManager) CutBranch(version string) error {
m := branch.NewManager(branch.WithRepoRoot(o.dir),
branch.WithRepoRemote(o.remote),
Expand Down
7 changes: 7 additions & 0 deletions release/pkg/manager/operator/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ func WithOperatorDirectory(root string) Option {
}
}

func WithCalicoDirectory(dir string) Option {
return func(o *OperatorManager) error {
o.calicoDir = dir
return nil
}
}

func WithRepoRemote(remote string) Option {
return func(o *OperatorManager) error {
o.remote = remote
Expand Down