Skip to content

Commit

Permalink
Automate Bottlerocket release version updates
Browse files Browse the repository at this point in the history
  • Loading branch information
abhay-krishna committed Feb 28, 2024
1 parent c6d1bda commit 8b33ed6
Show file tree
Hide file tree
Showing 6 changed files with 382 additions and 118 deletions.
407 changes: 316 additions & 91 deletions tools/version-tracker/pkg/commands/upgrade/upgrade.go

Large diffs are not rendered by default.

60 changes: 36 additions & 24 deletions tools/version-tracker/pkg/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,33 @@ import (

// Constants used across the version-tracker source code.
const (
BaseRepoOwnerEnvvar = "BASE_REPO_OWNER"
HeadRepoOwnerEnvvar = "HEAD_REPO_OWNER"
GitHubTokenEnvvar = "GITHUB_TOKEN"
CommitAuthorNameEnvvar = "COMMIT_AUTHOR_NAME"
CommitAuthorEmailEnvvar = "COMMIT_AUTHOR_EMAIL"
DefaultCommitAuthorName = "EKS Distro PR Bot"
DefaultCommitAuthorEmail = "aws-model-rocket-bots+eksdistroprbot@amazon.com"
BuildToolingRepoName = "eks-anywhere-build-tooling"
BuildToolingRepoURL = "https://github.com/aws/eks-anywhere-build-tooling"
ReadmeFile = "README.md"
ReadmeUpdateScriptFile = "build/lib/readme_check.sh"
LicenseBoilerplateFile = "hack/boilerplate.yq.txt"
SkippedProjectsFile = "SKIPPED_PROJECTS"
UpstreamProjectsTrackerFile = "UPSTREAM_PROJECTS.yaml"
GitTagFile = "GIT_TAG"
GoVersionFile = "GOLANG_VERSION"
ChecksumsFile = "CHECKSUMS"
AttributionsFilePattern = "*ATTRIBUTION.txt"
PatchesDirectory = "patches"
GithubPerPage = 100
datetimeFormat = "%Y-%m-%dT%H:%M:%SZ"
MainBranchName = "main"
BaseRepoHeadRevision = "refs/remotes/origin/main"
PullRequestBody = `This PR bumps %[1]s/%[2]s to the latest Git revision, along with other updates such as Go version, checksums and attribution files.
BaseRepoOwnerEnvvar = "BASE_REPO_OWNER"
HeadRepoOwnerEnvvar = "HEAD_REPO_OWNER"
GitHubTokenEnvvar = "GITHUB_TOKEN"
CommitAuthorNameEnvvar = "COMMIT_AUTHOR_NAME"
CommitAuthorEmailEnvvar = "COMMIT_AUTHOR_EMAIL"
DefaultCommitAuthorName = "EKS Distro PR Bot"
DefaultCommitAuthorEmail = "aws-model-rocket-bots+eksdistroprbot@amazon.com"
BuildToolingRepoName = "eks-anywhere-build-tooling"
BuildToolingRepoURL = "https://github.com/aws/eks-anywhere-build-tooling"
ReadmeFile = "README.md"
ReadmeUpdateScriptFile = "build/lib/readme_check.sh"
LicenseBoilerplateFile = "hack/boilerplate.yq.txt"
SkippedProjectsFile = "SKIPPED_PROJECTS"
UpstreamProjectsTrackerFile = "UPSTREAM_PROJECTS.yaml"
GitTagFile = "GIT_TAG"
GoVersionFile = "GOLANG_VERSION"
ChecksumsFile = "CHECKSUMS"
AttributionsFilePattern = "*ATTRIBUTION.txt"
PatchesDirectory = "patches"
BottlerocketReleasesFile = "BOTTLEROCKET_RELEASES"
BottlerocketAdminContainerMetadataFile = "BOTTLEROCKET_ADMIN_CONTAINER_METADATA"
BottlerocketControlContainerMetadataFile = "BOTTLEROCKET_CONTROL_CONTAINER_METADATA"
GithubPerPage = 100
datetimeFormat = "%Y-%m-%dT%H:%M:%SZ"
MainBranchName = "main"
BaseRepoHeadRevision = "refs/remotes/origin/main"
PullRequestBody = `This PR bumps %[1]s/%[2]s to the latest Git revision, along with other updates such as Go version, checksums and attribution files.
[Compare changes](https://github.com/%[1]s/%[2]s/compare/%[3]s...%[4]s)
[Release notes](https://github.com/%[1]s/%[2]s/releases/%[4]s)
Expand Down Expand Up @@ -218,4 +221,13 @@ var (
GoVersionSearchString: `GO_VERSION: "(1\.\d\d)"`,
},
}

ProjectsWithUnconventionalUpgradeFlows = []string{
"cilium/cilium",
"kubernetes-sigs/image-builder",
}

BottlerocketImageFormats = []string{"ami", "ova", "raw"}

BottlerocketHostContainers = []string{"admin", "control"}
)
2 changes: 1 addition & 1 deletion tools/version-tracker/pkg/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func Checkout(worktree *git.Worktree, branch string) error {

err := worktree.Checkout(&git.CheckoutOptions{
Branch: plumbing.NewBranchReferenceName(branch),
Force: true,
Keep: true,
Create: true,
})
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions tools/version-tracker/pkg/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ func GetGoVersionForLatestRevision(client *github.Client, org, repo, latestRevis
}

// CreatePullRequest creates a pull request from the head branch to the base branch on the base repository.
func CreatePullRequest(client *github.Client, org, repo, baseRepoOwner, baseBranch, headRepoOwner, headBranch, currentRevision, latestRevision string, projectHasPatches bool) error {
func CreatePullRequest(client *github.Client, org, repo, title, baseRepoOwner, baseBranch, headRepoOwner, headBranch, currentRevision, latestRevision string, projectHasPatches bool) error {
logger.V(6).Info(fmt.Sprintf("Creating pull request with updated versions for [%s/%s] repository\n", org, repo))

pullRequests, _, err := client.PullRequests.List(context.Background(), baseRepoOwner, constants.BuildToolingRepoName, &github.PullRequestListOptions{
Expand All @@ -346,7 +346,7 @@ func CreatePullRequest(client *github.Client, org, repo, baseRepoOwner, baseBran
}

newPR := &github.NewPullRequest{
Title: github.String(fmt.Sprintf("Bump %s/%s to latest release", org, repo)),
Title: github.String(title),
Head: github.String(fmt.Sprintf("%s:%s", headRepoOwner, headBranch)),
Base: github.String(baseBranch),
Body: github.String(fmt.Sprintf(constants.PullRequestBody, org, repo, currentRevision, latestRevision)),
Expand Down
15 changes: 15 additions & 0 deletions tools/version-tracker/pkg/util/file/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,18 @@ func Download(url, filepath string) error {
_, err = io.Copy(out, resp.Body)
return err
}

func ReadURL(url string) ([]byte, error) {
resp, err := http.Get(url)
if err != nil {
return nil, err
}
defer resp.Body.Close()

data, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}

return data, nil
}
12 changes: 12 additions & 0 deletions tools/version-tracker/pkg/util/slices/slices.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,15 @@ func Contains(s []string, str string) bool {
}
return false
}

func IsSubset(s1, s2 []string) bool {
if len(s1) > len(s2) {
return false
}
for _, e := range s1 {
if !Contains(s2, e) {
return false
}
}
return true
}

0 comments on commit 8b33ed6

Please sign in to comment.