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

added eks-a-releaser files #8617

Open
wants to merge 21 commits into
base: main
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
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
13 changes: 13 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,13 @@
---
version: 0.2
phases:
pre_build:
commands:
- ./release/scripts/setup.sh
build:
commands:
- make build -C release
artifacts:
files:
- release/bin/eks-anywhere-release
- release/buildspecs/**/*
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
185 changes: 185 additions & 0 deletions release/cli/cmd/create-branch.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
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"
"log"
"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
latestRelease = os.Getenv("LATEST_RELEASE")
RELEASE_TYPE = os.Getenv("RELEASE_TYPE")
latestVersion = os.Getenv("LATEST_VERSION")
releaseNumber = os.Getenv("RELEASE_NUMBER")
accessToken = os.Getenv("SECRET_PAT")
)

// 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 {
log.Printf("error creating branch %s", err)
}
},
}

func releaseDecision() error {

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

func createMinorBranches() error {

//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
log.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
log.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
log.Printf("New build tooling branch '%s' created successfully\n", *newBranchRef.Ref)

return nil
}

func createPatchBranch() error {

//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
log.Printf("New branch '%s' created successfully\n", *newBranchRef.Ref)

return nil
}
Loading