Skip to content

Commit

Permalink
Regenerate rollouts E2E test script and update README
Browse files Browse the repository at this point in the history
Signed-off-by: Jonathan West <[email protected]>
  • Loading branch information
jgwest committed Jan 30, 2024
1 parent f95ebf8 commit a5ca828
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 33 deletions.
21 changes: 12 additions & 9 deletions hack/upgrade-rollouts-script/README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
# Update argo-rollouts-manager to latest release of Argo Rollouts

The Go code and script this in this directory will automatically open a pull request to update the argo-rollouts-manager to the latest official argo-rollouts release:
- Update container image version in 'default.go'
- Update go.mod to point to latest module version
- Update container image version in `default.go`
- Update `go.mod` to point to latest module version
- Update CRDs to latest
- Update target Rollouts version in `hack/run-upstream-argo-rollouts-e2e-tests.sh`
- Open Pull Request using 'gh' CLI

## Instructions

### Pre-requisites:
### Prerequisites
- GitHub CLI (_gh_) installed and on PATH
- Operator-sdk v1.28.0 installed (as of January 2024), and on PATH
- Go installed an on PATH
- [Operator-sdk v1.28.0](https://github.com/operator-framework/operator-sdk/releases/tag/v1.28.0) installed (as of January 2024), and on PATH
- You must have your own fork of the [argo-rollouts-manager](https://github.com/argoproj-labs/argo-rollouts-manager) repository (example: `jgwest/argo-rollouts-manager`)
- Your local SSH key registered (e.g. `~/.ssh/id_rsa.pub`) with GitHub to allow git clone via SSH

### To run the tool
### Configure and run the tool

Modify the `init-repo.sh` file, updating the GitHub URL with a fork.

Then run the script:
```bash
export GITHUB_FORK_USERNAME="(your username here)"
export GH_TOKEN="(a GitHub personal access token that can clone/push/open PRs against argo-rollouts-manager repo)"
./init-repo.sh
./go-run.sh
```
```
9 changes: 9 additions & 0 deletions hack/upgrade-rollouts-script/go-run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

cd $SCRIPT_DIR

go run .


14 changes: 14 additions & 0 deletions hack/upgrade-rollouts-script/init-repo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

cd $SCRIPT_DIR

rm -rf "$SCRIPT_DIR/argo-rollouts-manager" || true

git clone "[email protected]:$GITHUB_FORK_USERNAME/argo-rollouts-manager"
cd argo-rollouts-manager

git remote add parent "[email protected]:argoproj-labs/argo-rollouts-manager"
git fetch parent

115 changes: 91 additions & 24 deletions hack/upgrade-rollouts-script/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ const (

argoprojlabsRepoOrg = "argoproj-labs"
argoRolloutsManagerRepoName = "argo-rollouts-manager"

skipInitialPRCheck = false // default to false

// if readOnly is true:
// - PRs will not be opened
// - Git commits will not be pushed to fork
// This is roughly equivalent to a dry run
readOnly = false // default to false
)

func main() {
Expand All @@ -39,17 +47,19 @@ func main() {

// 1) Check for existing version update PRs on the repo

// prList, _, err := client.PullRequests.List(context.Background(), argoprojlabsRepoOrg, argoRolloutsManagerRepoName, &github.PullRequestListOptions{})
// if err != nil {
// exitWithError(err)
// return
// }
// for _, pr := range prList {
// if strings.HasPrefix(*pr.Title, PRTitle) {
// exitWithError(fmt.Errorf("PR already exists"))
// return
// }
// }
if !skipInitialPRCheck {
prList, _, err := client.PullRequests.List(context.Background(), argoprojlabsRepoOrg, argoRolloutsManagerRepoName, &github.PullRequestListOptions{})
if err != nil {
exitWithError(err)
return
}
for _, pr := range prList {
if strings.HasPrefix(*pr.Title, PRTitle) {
exitWithError(fmt.Errorf("PR already exists"))
return
}
}
}

// 2) Pull the latest releases from rollouts repo

Expand Down Expand Up @@ -83,14 +93,23 @@ func main() {
return
}

// // 4) Create PR if it doesn't exist
// if stdout, stderr, err := runCommandWithWD(pathToGitHubRepo, "gh", "pr", "create",
// "-R", argoprojlabsRepoOrg+"/"+argoRolloutsManagerRepoName,
// "--title", PRTitle+(*firstProperRelease.TagName), "--body", "Update to latest release of Argo Rollouts"); err != nil {
// fmt.Println(stdout, stderr)
// exitWithError(err)
// return
// }
if !readOnly {

bodyText := "Update to latest release of Argo Rollouts"

if firstProperRelease != nil && firstProperRelease.HTMLURL != nil && *firstProperRelease.HTMLURL != "" {
bodyText += ": " + *firstProperRelease.HTMLURL
}

// 4) Create PR if it doesn't exist
if stdout, stderr, err := runCommandWithWD(pathToGitHubRepo, "gh", "pr", "create",
"-R", argoprojlabsRepoOrg+"/"+argoRolloutsManagerRepoName,
"--title", PRTitle+(*firstProperRelease.TagName), "--body", bodyText); err != nil {
fmt.Println(stdout, stderr)
exitWithError(err)
return
}
}

}

Expand All @@ -103,7 +122,7 @@ func createNewCommitAndBranch(latestReleaseVersionTag string, latestReleaseVersi
{"git", "checkout", "-b", newBranchName},
}

if err := runCommandListWithWD(pathToGitRepo, commands); err != nil {
if err := runCommandListWithWorkDir(pathToGitRepo, commands); err != nil {
return err
}

Expand All @@ -115,6 +134,10 @@ func createNewCommitAndBranch(latestReleaseVersionTag string, latestReleaseVersi
return err
}

if err := regenerateArgoRolloutsE2ETestScriptMod(latestReleaseVersionTag, pathToGitRepo); err != nil {
return err
}

rolloutsRepoPath, err := checkoutRolloutsRepo(latestReleaseVersionTag)
if err != nil {
return err
Expand Down Expand Up @@ -177,14 +200,23 @@ func createNewCommitAndBranch(latestReleaseVersionTag string, latestReleaseVersi
{"go", "mod", "tidy"},
{"make", "generate", "manifests"},
{"make", "bundle"},
{"make", "fmt"},
{"git", "add", "--all"},
{"git", "commit", "-s", "-m", PRTitle + latestReleaseVersionTag},
{"git", "push", "-f", "--set-upstream", "origin", newBranchName},
}
if err := runCommandListWithWD(pathToGitRepo, commands); err != nil {
if err := runCommandListWithWorkDir(pathToGitRepo, commands); err != nil {
return err
}

if !readOnly {
commands = [][]string{
{"git", "push", "-f", "--set-upstream", "origin", newBranchName},
}
if err := runCommandListWithWorkDir(pathToGitRepo, commands); err != nil {
return err
}
}

return nil

}
Expand All @@ -206,14 +238,14 @@ func checkoutRolloutsRepo(latestReleaseVersionTag string) (string, error) {
{"git", "checkout", latestReleaseVersionTag},
}

if err := runCommandListWithWD(newWD, commands); err != nil {
if err := runCommandListWithWorkDir(newWD, commands); err != nil {
return "", err
}

return newWD, nil
}

func runCommandListWithWD(workingDir string, commands [][]string) error {
func runCommandListWithWorkDir(workingDir string, commands [][]string) error {

for _, command := range commands {

Expand All @@ -227,6 +259,7 @@ func runCommandListWithWD(workingDir string, commands [][]string) error {

func regenerateGoMod(latestReleaseVersionTag string, pathToGitRepo string) error {

// Format of string to modify:
// github.com/argoproj/argo-rollouts v1.6.3

path := filepath.Join(pathToGitRepo, "go.mod")
Expand Down Expand Up @@ -258,6 +291,40 @@ func regenerateGoMod(latestReleaseVersionTag string, pathToGitRepo string) error

}

func regenerateArgoRolloutsE2ETestScriptMod(latestReleaseVersionTag string, pathToGitRepo string) error {

// Format of string to modify:
// CURRENT_ROLLOUTS_VERSION=v1.6.4

path := filepath.Join(pathToGitRepo, "hack/run-upstream-argo-rollouts-e2e-tests.sh")

fileBytes, err := os.ReadFile(path)
if err != nil {
return err
}

var res string

for _, line := range strings.Split(string(fileBytes), "\n") {

if strings.Contains(line, "CURRENT_ROLLOUTS_VERSION=") {

res += "CURRENT_ROLLOUTS_VERSION=" + latestReleaseVersionTag + "\n"

} else {
res += line + "\n"
}

}

if err := os.WriteFile(path, []byte(res), 0600); err != nil {
return err
}

return nil

}

func regenerateControllersDefaultGo(latestReleaseVersionTag string, latestReleaseVersionImage, pathToGitRepo string) error {

// DefaultArgoRolloutsVersion = "sha256:995450a0a7f7843d68e96d1a7f63422fa29b245c58f7b57dd0cf9cad72b8308f" //v1.4.1
Expand Down

0 comments on commit a5ca828

Please sign in to comment.