Skip to content

Commit

Permalink
added eks-a-releaser files
Browse files Browse the repository at this point in the history
  • Loading branch information
ibix16 committed Aug 15, 2024
1 parent 28ba8bf commit e649269
Show file tree
Hide file tree
Showing 22 changed files with 1,855 additions and 297 deletions.
8 changes: 8 additions & 0 deletions release/buildspecs/eks-a-releaser-buildspec/create-branch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: 0.2
env:
secrets-manager:
SECRET_PAT: "github-eks-distro-pr-bot:github-token"
phases:
build:
commands:
- ${CODEBUILD_SRC_DIR}/release/bin/eks-anywhere-release trigger create-branch
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: 0.2
env:
secrets-manager:
SECRET_PAT: "github-eks-distro-pr-bot:github-token"
phases:
build:
commands:
- ${CODEBUILD_SRC_DIR}/release/bin/eks-anywhere-release trigger create-release
14 changes: 14 additions & 0 deletions release/buildspecs/eks-a-releaser-buildspec/go-build-binary.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: 0.2

phases:
pre_build:
commands:
- ./release/scripts/setup.sh

build:
commands:
- make dev-release -C release

artifacts:
files:
- release/bin/eks-anywhere-release
8 changes: 8 additions & 0 deletions release/buildspecs/eks-a-releaser-buildspec/prod-bundle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: 0.2
env:
secrets-manager:
SECRET_PAT: "github-eks-distro-pr-bot:github-token"
phases:
build:
commands:
- ${CODEBUILD_SRC_DIR}/release/bin/eks-anywhere-release trigger prod-bundle
8 changes: 8 additions & 0 deletions release/buildspecs/eks-a-releaser-buildspec/prod-cli.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: 0.2
env:
secrets-manager:
SECRET_PAT: "github-eks-distro-pr-bot:github-token"
phases:
build:
commands:
- ${CODEBUILD_SRC_DIR}/release/bin/eks-anywhere-release trigger prod-cli
8 changes: 8 additions & 0 deletions release/buildspecs/eks-a-releaser-buildspec/stage-bundle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: 0.2
env:
secrets-manager:
SECRET_PAT: "github-eks-distro-pr-bot:github-token"
phases:
build:
commands:
- ${CODEBUILD_SRC_DIR}/release/bin/eks-anywhere-release trigger stage-bundle
8 changes: 8 additions & 0 deletions release/buildspecs/eks-a-releaser-buildspec/stage-cli.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: 0.2
env:
secrets-manager:
SECRET_PAT: "github-eks-distro-pr-bot:github-token"
phases:
build:
commands:
- ${CODEBUILD_SRC_DIR}/release/bin/eks-anywhere-release trigger stage-cli
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: 0.2
env:
secrets-manager:
SECRET_PAT: "github-eks-distro-pr-bot:github-token"
phases:
build:
commands:
- ${CODEBUILD_SRC_DIR}/release/bin/eks-anywhere-release trigger update-homebrew
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: 0.2
env:
secrets-manager:
SECRET_PAT: "github-eks-distro-pr-bot:github-token"
phases:
build:
commands:
- ${CODEBUILD_SRC_DIR}/release/bin/eks-anywhere-release trigger update-makefile
8 changes: 8 additions & 0 deletions release/buildspecs/eks-a-releaser-buildspec/update-prow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: 0.2
env:
secrets-manager:
SECRET_PAT: "github-eks-distro-pr-bot:github-token"
phases:
build:
commands:
- ${CODEBUILD_SRC_DIR}/release/bin/eks-anywhere-release trigger update-prow
182 changes: 182 additions & 0 deletions release/cli/cmd/create-branch.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
package cmd

/*
what does this command do?
if release type is "minor" then :
creates a new release branch in upstream eks-a repo based off "main" & build tooling repo
creates a new release branch in forked repo based off newly created release branch in upstream repo
else :
creates a new patch branch in users forked repo based off latest release branch upstream
*/

import (
"context"
"fmt"
"os"

"github.com/google/go-github/v62/github"
"github.com/spf13/cobra"
)

var (
buildToolingRepoName = "eks-anywhere-build-tooling"
upStreamRepoOwner = "testerIbix" // will eventually be replaced by actual upstream owner, aws
)

// createBranchCmd represents the createBranch command
var createBranchCmd = &cobra.Command{
Use: "create-branch",
Short: "Creates new release branch from updated trigger file",
Long: `A longer description that spans multiple lines and likely contains examples
and usage of using your command.`,

Run: func(cmd *cobra.Command, args []string) {

err := releaseDecision()
if err != nil {
fmt.Printf("error creating branch %s", err)
}
},
}

func releaseDecision() error {
RELEASE_TYPE := os.Getenv("RELEASE_TYPE")

if RELEASE_TYPE == "minor" {
err := createMinorBranches()
if err != nil {
fmt.Printf("error calling createMinorBranches %s", err)
}
return nil
}
// else
err := createPatchBranch()
if err != nil {
fmt.Printf("error calling createPatchBranch %s", err)
}
return nil
}

func createMinorBranches() error {

latestRelease := os.Getenv("LATEST_RELEASE")

//create client
accessToken := os.Getenv("SECRET_PAT")
ctx := context.Background()
client := github.NewClient(nil).WithAuthToken(accessToken)

// create branch in upstream repo based off main branch
ref := "refs/heads/" + latestRelease
baseRef := "main"

// Get the reference for the base branch
baseRefObj, _, err := client.Git.GetRef(ctx, upStreamRepoOwner, EKSAnyrepoName, "heads/"+baseRef)
if err != nil {
return fmt.Errorf("error getting base branch reference one: %v", err)
}

// Create a new branch
newBranchRef, _, err := client.Git.CreateRef(ctx, upStreamRepoOwner, EKSAnyrepoName, &github.Reference{
Ref: &ref,
Object: &github.GitObject{
SHA: baseRefObj.Object.SHA,
},
})
if err != nil {
return fmt.Errorf("error creating branch one: %v", err)
}

// branch created upstream
fmt.Printf("New release branch '%s' created upstream successfully\n", *newBranchRef.Ref)

// create branch in forked repo based off upstream
ref = "refs/heads/" + latestRelease
baseRef = latestRelease

// Get the reference for the base branch from the upstream repository
baseRefObj, _, err = client.Git.GetRef(ctx, upStreamRepoOwner, EKSAnyrepoName, "heads/"+baseRef)
if err != nil {
return fmt.Errorf("error getting base branch reference two: %v", err)
}

// Create a new branch
newBranchRef, _, err = client.Git.CreateRef(ctx, usersForkedRepoAccount, EKSAnyrepoName, &github.Reference{
Ref: &ref,
Object: &github.GitObject{
SHA: baseRefObj.Object.SHA,
},
})
if err != nil {
return fmt.Errorf("error creating branch two: %v", err)
}

// branch created upstream
fmt.Printf("New user fork branch '%s' created successfully\n", *newBranchRef.Ref)

// create branch in upstream build tooling repo based off main branch
ref = "refs/heads/" + latestRelease
baseRef = "main"

// Get the reference for the base branch
baseRefObj, _, err = client.Git.GetRef(ctx, upStreamRepoOwner, buildToolingRepoName, "heads/"+baseRef)
if err != nil {
return fmt.Errorf("error getting base branch reference three: %v", err)
}

// Create a new branch
newBranchRef, _, err = client.Git.CreateRef(ctx, upStreamRepoOwner, buildToolingRepoName, &github.Reference{
Ref: &ref,
Object: &github.GitObject{
SHA: baseRefObj.Object.SHA,
},
})
if err != nil {
return fmt.Errorf("error creating branch three: %v", err)
}

// branch created upstream
fmt.Printf("New build tooling branch '%s' created successfully\n", *newBranchRef.Ref)

return nil
}

func createPatchBranch() error {

latestRelease := os.Getenv("LATEST_RELEASE")

//create client
accessToken := os.Getenv("SECRET_PAT")
ctx := context.Background()
client := github.NewClient(nil).WithAuthToken(accessToken)

// create branch in forked repo based off upstream
ref := "refs/heads/" + latestRelease + "-releaser-patch"
baseRef := latestRelease

// Get the reference for the base branch from upstream
baseRefObj, _, err := client.Git.GetRef(ctx, upStreamRepoOwner, EKSAnyrepoName, "heads/"+baseRef)
if err != nil {
return fmt.Errorf("error getting base branch reference: %v", err)
}

// Create a new branch in fork
newBranchRef, _, err := client.Git.CreateRef(ctx, usersForkedRepoAccount, EKSAnyrepoName, &github.Reference{
Ref: &ref,
Object: &github.GitObject{
SHA: baseRefObj.Object.SHA,
},
})
if err != nil {
return fmt.Errorf("error creating branch: %v", err)
}

// branch created upstream
fmt.Printf("New branch '%s' created successfully\n", *newBranchRef.Ref)

return nil
}
Loading

0 comments on commit e649269

Please sign in to comment.