Skip to content

Commit

Permalink
add release command to bump release files
Browse files Browse the repository at this point in the history
  • Loading branch information
rcrozean committed Oct 24, 2023
1 parent 3ff8fa5 commit 999281d
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package cmd

import (
"fmt"

"github.com/spf13/cobra"
"github.com/spf13/viper"

"github.com/aws/eks-distro-build-tooling/tools/eksDistroBuildToolingOpsTools/pkg/eksGoRelease"
)

var releaseCmd = &cobra.Command{
Use: "release",
Short: "Release EKS Go",
Long: "Tool to create PRs for releasing EKS Go versions",
RunE: func(cmd *cobra.Command, args []string) error {
var eksGoReleases []*eksGoRelease.Release
for _, v := range viper.GetStringSlice(eksGoReleasesFlag) {
r, err := eksGoRelease.NewEksGoReleaseObject(v)
if err != nil {
return err
}
eksGoReleases = append(eksGoReleases, r)
}

for _, r := range eksGoReleases {
err := eksGoRelease.ReleaseArtifacts(cmd.Context(), r, viper.GetBool(dryrunFlag), viper.GetString(emailFlag), viper.GetString(userFlag))
if err != nil {
return fmt.Errorf("you have failed this automation: %w", err)
}
}
return nil
},
}

func init() {
rootCmd.AddCommand(releaseCmd)
}
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,6 @@ func updateGoSpecPatchVersion(fc *string, r *Release) string {
return strings.Replace(*fc, gpO, gpN, 1)
}

func addPatchGoSpec(fc *string, r *Release, patch string) string {
return ""
}

// TODO: Fix logic to apply previous patches, cherry pick fix, and create patch file
func createPatchFile(ctx context.Context, r *Release, gClient git.Client, golangClient git.Client, commit string) error {
// Attempt patch generation if it fails, skip updating gospec with new patch number
Expand Down
65 changes: 65 additions & 0 deletions tools/eksDistroBuildToolingOpsTools/pkg/eksGoRelease/release.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package eksGoRelease

import (
"context"
"fmt"

"github.com/aws/eks-distro-build-tooling/tools/eksDistroBuildToolingOpsTools/pkg/constants"
"github.com/aws/eks-distro-build-tooling/tools/eksDistroBuildToolingOpsTools/pkg/git"
"github.com/aws/eks-distro-build-tooling/tools/eksDistroBuildToolingOpsTools/pkg/github"
"github.com/aws/eks-distro-build-tooling/tools/eksDistroBuildToolingOpsTools/pkg/logger"
"github.com/go-git/go-git/v5/plumbing/transport/http"
)

const (
releasePRCommitFmt = "Release EKS Go version %s"
releasePRDescriptionFmt = "Increment release file to publish new EKS Go artifacts for %s"
releasePRSubjectFmt = "Release EKS Go: %s"
)

// UpdatePatchVersion is for updating the files in https://github.com/aws/eks-distro-build-tooling/golang/go for golang versions still maintained by upstream.
// For EKS Go versions that aren't maintained by upstream, the function is
func ReleaseArtifacts(ctx context.Context, r *Release, dryrun bool, email, user string) error {
// Setup Git Clients
token, err := github.GetGithubToken()
if err != nil {
logger.V(4).Error(err, "no github token found")
return fmt.Errorf("getting Github PAT from environment at variable %s: %v", github.PersonalAccessTokenEnvVar, err)
}

ghUser := github.NewGitHubUser(user, email, token)
// Creating git client in memory and clone 'eks-distro-build-tooling
forkUrl := fmt.Sprintf(constants.EksGoRepoUrl, ghUser.User())
gClient := git.NewClient(git.WithInMemoryFilesystem(), git.WithRepositoryUrl(forkUrl), git.WithAuth(&http.BasicAuth{Username: ghUser.User(), Password: ghUser.Token()}))
if err := gClient.Clone(ctx); err != nil {
logger.Error(err, "Cloning repo", "user", ghUser.User())
return err
}

// Increment Release
if err := bumpRelease(gClient, r); err != nil {
logger.Error(err, "increment release")
return err
}

// Create new branch
if err := gClient.Branch(fmt.Sprintf("release-%s", r.GoMinorVersion())); err != nil {
logger.Error(err, "git branch", "branch name", r.GoMinorVersion(), "repo", forkUrl, "client", gClient)
return err
}

// Increment release files
if err := updateRelease(gClient, r); err != nil {
logger.Error(err, "updating release file", "release", r.EksGoReleaseVersion())
return err
}

// Commit files and create PR
prSubject := fmt.Sprintf(releasePRSubjectFmt, r.EksGoReleaseVersion())
prDescription := fmt.Sprintf(releasePRDescriptionFmt, r.EksGoReleaseVersion())
commitMsg := fmt.Sprintf(releasePRCommitFmt, r.EksGoReleaseVersion())
if err := createReleasePR(ctx, dryrun, r, ghUser, gClient, prSubject, prDescription, commitMsg); err != nil {
logger.Error(err, "Create Release PR")
}
return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

const (
updatePRCommitFmt = "Update EKS Go files for version: %s"
updatePRCommitFmt = "Update EKS Go files for version %s"
updatePRDescriptionFmt = "Update EKS Go Patch Version: %s\nSPEC FILE STILL NEEDS THE '%%changelog' UPDATED\nPLEASE UPDATE WITH THE FOLLOWING FORMAT\n```\n* Wed Sep 06 2023 Cameron Rozean <[email protected]> - 1.20.8-1\n- Bump tracking patch version to 1.20.8 from 1.20.7\n```"
updatePRSubjectFmt = "New patch release of Golang: %s"
)
Expand Down

0 comments on commit 999281d

Please sign in to comment.