-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add release command to bump release files
- Loading branch information
Showing
4 changed files
with
104 additions
and
5 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
tools/eksDistroBuildToolingOpsTools/cmd/eksGoRelease/cmd/release.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
tools/eksDistroBuildToolingOpsTools/pkg/eksGoRelease/release.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
) | ||
|