From 238ba6a0558fe93ffe1d2f6c8af5b2b6fe70a07b Mon Sep 17 00:00:00 2001 From: Pedro Tashima Date: Tue, 28 Nov 2023 19:12:32 -0300 Subject: [PATCH 1/9] add rancher tag release command --- cmd/rancher_release/main.go | 1 + cmd/rancher_release/tag_release.go | 60 ++++++++++++++++++++++++++++++ release/rancher/rancher.go | 38 +++++++++++++++++++ 3 files changed, 99 insertions(+) create mode 100644 cmd/rancher_release/tag_release.go diff --git a/cmd/rancher_release/main.go b/cmd/rancher_release/main.go index d2bfd995..326b3667 100644 --- a/cmd/rancher_release/main.go +++ b/cmd/rancher_release/main.go @@ -33,6 +33,7 @@ func main() { setChartsBranchReferencesCommand(), checkRancherRCDepsCommand(), labelIssuesCommand(), + tagReleaseCommand(), } app.Flags = rootFlags diff --git a/cmd/rancher_release/tag_release.go b/cmd/rancher_release/tag_release.go new file mode 100644 index 00000000..405fb36d --- /dev/null +++ b/cmd/rancher_release/tag_release.go @@ -0,0 +1,60 @@ +package main + +import ( + "context" + + "github.com/rancher/ecm-distro-tools/release/rancher" + "github.com/rancher/ecm-distro-tools/repository" + "github.com/urfave/cli/v2" +) + +func tagReleaseCommand() *cli.Command { + return &cli.Command{ + Name: "tag-release", + Usage: "tag a rancher release", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "github-token", + Aliases: []string{"g"}, + EnvVars: []string{"GITHUB_TOKEN"}, + Required: true, + }, + &cli.StringFlag{ + Name: "tag", + Aliases: []string{"t"}, + Usage: "release tag", + Required: true, + }, + &cli.StringFlag{ + Name: "remote-branch", + Aliases: []string{"r"}, + Usage: "rancher remote branch", + Required: true, + }, + &cli.BoolFlag{ + Name: "general-availability", + Aliases: []string{"a"}, + Usage: "by default, the release will be created as a pre-release, make sure it absolutely needs to be a GA release before setting this", + Required: false, + }, + &cli.BoolFlag{ + Name: "ignore-draft", + Aliases: []string{"d"}, + Usage: "by default, the release will be created as a draft, so you can verify all information is correct before unmarking it", + Required: false, + }, + }, + Action: tagRelease, + } +} + +func tagRelease(c *cli.Context) error { + token := c.String("github-token") + tag := c.String("tag") + remoteBranch := c.String("remote-branch") + generalAvailability := c.Bool("general-availability") + ignoreDraft := c.Bool("ignore-draft") + ctx := context.Background() + ghClient := repository.NewGithub(ctx, token) + return rancher.TagRancherRelease(ctx, ghClient, tag, remoteBranch, generalAvailability, ignoreDraft) +} diff --git a/release/rancher/rancher.go b/release/rancher/rancher.go index 5660716d..2436ca60 100644 --- a/release/rancher/rancher.go +++ b/release/rancher/rancher.go @@ -20,10 +20,13 @@ import ( ecmHTTP "github.com/rancher/ecm-distro-tools/http" "github.com/rancher/ecm-distro-tools/repository" "github.com/sirupsen/logrus" + "golang.org/x/mod/semver" "gopkg.in/yaml.v2" ) const ( + rancherOrg = "rancher" + rancherRepo = rancherOrg rancherImagesBaseURL = "https://github.com/rancher/rancher/releases/download/" rancherImagesFileName = "/rancher-images.txt" rancherHelmRepositoryURL = "https://releases.rancher.com/server-charts/latest/index.yaml" @@ -317,6 +320,41 @@ func SetChartBranchReferences(ctx context.Context, forkPath, rancherBaseBranch, return nil } +func TagRancherRelease(ctx context.Context, ghClient *github.Client, tag, remoteBranch string, generalAvailability, ignoreDraft bool) error { + logrus.Info("validating tag semver format") + if !semver.IsValid(tag) { + return errors.New("the tag `" + tag + "` isn't a valid semantic versioning string") + } + logrus.Info("getting remote branch information from rancher/rancher") + branch, _, err := ghClient.Repositories.GetBranch(ctx, rancherOrg, rancherRepo, remoteBranch, true) + if err != nil { + return err + } + logrus.Info("the latest commit on branch " + remoteBranch + "is: " + *branch.Commit.SHA) + logrus.Info("creating release ") + releaseBody := "" // TODO: generate the release body using the script + createAsDraft := !ignoreDraft + createAsPrerelease := !generalAvailability + ghClient.Repositories.CreateRelease(ctx, rancherOrg, rancherRepo, &github.RepositoryRelease{ + TagName: github.String(tag), + Name: github.String(rancherReleaseName(generalAvailability, tag)), + Body: github.String(releaseBody), + Draft: &createAsDraft, + Prerelease: &createAsPrerelease, + GenerateReleaseNotes: github.Bool(false), + }) + return nil +} + +func rancherReleaseName(generalAvailability bool, tag string) string { + releaseName := "" + if !generalAvailability { + releaseName += "Pre-release " + } + releaseName += tag + return releaseName +} + func createPRFromRancher(ctx context.Context, rancherBaseBranch, title, branchName, forkOwner string, ghClient *github.Client) error { pull := &github.NewPullRequest{ Title: github.String(title), From ab10716767c8ad1f78b788070cc32440a872895a Mon Sep 17 00:00:00 2001 From: Pedro Tashima Date: Wed, 29 Nov 2023 12:30:16 -0300 Subject: [PATCH 2/9] add release body generation with rancher/rancher --- cmd/rancher_release/tag_release.go | 26 +++++++- release/rancher/rancher.go | 97 ++++++++++++++++++++++++++---- 2 files changed, 109 insertions(+), 14 deletions(-) diff --git a/cmd/rancher_release/tag_release.go b/cmd/rancher_release/tag_release.go index 405fb36d..95bf680d 100644 --- a/cmd/rancher_release/tag_release.go +++ b/cmd/rancher_release/tag_release.go @@ -27,10 +27,23 @@ func tagReleaseCommand() *cli.Command { }, &cli.StringFlag{ Name: "remote-branch", - Aliases: []string{"r"}, + Aliases: []string{"b"}, Usage: "rancher remote branch", Required: true, }, + &cli.StringFlag{ + Name: "repo-owner", + Aliases: []string{"o"}, + Usage: "repo owner for the rancher repo, default is rancher, this is only used for testing purposes", + Value: "rancher", + Required: false, + }, + &cli.StringFlag{ + Name: "repo-path", + Aliases: []string{"p"}, + Usage: "rancher repo path, if not provided the repo will be cloned at /tmp/rancher", + Required: false, + }, &cli.BoolFlag{ Name: "general-availability", Aliases: []string{"a"}, @@ -43,6 +56,12 @@ func tagReleaseCommand() *cli.Command { Usage: "by default, the release will be created as a draft, so you can verify all information is correct before unmarking it", Required: false, }, + &cli.BoolFlag{ + Name: "dry-run", + Aliases: []string{"r"}, + Usage: "skip all changes that have side effects, like creating a release in a remote repo.", + Required: false, + }, }, Action: tagRelease, } @@ -52,9 +71,12 @@ func tagRelease(c *cli.Context) error { token := c.String("github-token") tag := c.String("tag") remoteBranch := c.String("remote-branch") + repoOwner := c.String("repo-owner") + repoPath := c.String("repo-path") generalAvailability := c.Bool("general-availability") ignoreDraft := c.Bool("ignore-draft") + dryRun := c.Bool("dry-run") ctx := context.Background() ghClient := repository.NewGithub(ctx, token) - return rancher.TagRancherRelease(ctx, ghClient, tag, remoteBranch, generalAvailability, ignoreDraft) + return rancher.TagRancherRelease(ctx, ghClient, tag, remoteBranch, repoOwner, repoPath, generalAvailability, ignoreDraft, dryRun) } diff --git a/release/rancher/rancher.go b/release/rancher/rancher.go index 2436ca60..5547a1bf 100644 --- a/release/rancher/rancher.go +++ b/release/rancher/rancher.go @@ -9,7 +9,10 @@ import ( "io" "net/http" "os" +<<<<<<< HEAD "regexp" +======= +>>>>>>> 7bf8fcd (add release body generation with rancher/rancher) "strconv" "strings" "text/template" @@ -33,7 +36,9 @@ const ( setKDMBranchReferencesScriptFileName = "set_kdm_branch_references.sh" setChartReferencesScriptFileName = `set_chart_references.sh` - cloneCheckoutRancherScript = `#!/bin/sh + runComponentsFileScriptFileName = `run_components_file.sh` + scriptsWorkingDir = `/tmp` + navigateCheckoutRancherScript = `#!/bin/sh set -e BRANCH_NAME={{ .BranchName }} @@ -108,6 +113,33 @@ git commit --all --signoff -m "update chart branch references to {{ .NewBranch } if [ "${DRY_RUN}" = false ]; then git push --set-upstream origin ${BRANCH_NAME} fi` + cloneRancherRunComponentsFileScript = `#!/bin/sh +set -e +REPO_NAME={{ .RepoName }} +REPO_OWNER={{ .RepoOwner }} +REPO_PATH={{ .RepoPath }} +BRANCH={{ .Branch }} +echo "repo name: ${REPO_NAME}" +echo "org name: ${REPO_OWNER}" +echo "cloning ${REPO_OWNER}/${REPO_NAME} into ${REPO_PATH}" +git clone "git@github.com:${REPO_OWNER}/${REPO_NAME}.git" "${REPO_PATH}" +cd "${REPO_PATH}" +git switch "${BRANCH}" +./scripts/create-components-file.sh` + navigateRunComponentsFileScript = `#!/bin/sh +set -e +REPO_PATH={{ .RepoPath }} +BRANCH={{ .Branch }} +cd "${REPO_PATH}" +echo "stashing local changes" +git stash +echo "fetching changes" +git fetch +echo "switch to branch ${BRANCH}" +git switch "${BRANCH}" +echo "pulling latests changes" +git pull +./scripts/create-components-file.sh` ) const templateCheckRCDevDeps = `{{- define "componentsFile" -}} @@ -145,6 +177,13 @@ type SetBranchReferencesArgs struct { DryRun bool } +type RunComponentsFileArgs struct { + RepoName string + RepoOwner string + RepoPath string + Branch string +} + type HelmIndex struct { Entries struct { Rancher []struct { @@ -260,7 +299,7 @@ func SetKDMBranchReferences(ctx context.Context, forkPath, rancherBaseBranch, ne BranchName: branchName, } - script := cloneCheckoutRancherScript + setKDMBranchReferencesScript + pushChangesScript + script := navigateCheckoutRancherScript + setKDMBranchReferencesScript + pushChangesScript logrus.Info("running update files and apply updates script...") output, err := exec.RunTemplatedScript(forkPath, setKDMBranchReferencesScriptFileName, script, data) if err != nil { @@ -294,7 +333,7 @@ func SetChartBranchReferences(ctx context.Context, forkPath, rancherBaseBranch, DryRun: dryRun, BranchName: branchName, } - script := cloneCheckoutRancherScript + setChartBranchReferencesScript + pushChangesScript + script := navigateCheckoutRancherScript + setChartBranchReferencesScript + pushChangesScript logrus.Info("running update files script") output, err := exec.RunTemplatedScript(forkPath, setChartReferencesScriptFileName, script, data) if err != nil { @@ -320,30 +359,40 @@ func SetChartBranchReferences(ctx context.Context, forkPath, rancherBaseBranch, return nil } -func TagRancherRelease(ctx context.Context, ghClient *github.Client, tag, remoteBranch string, generalAvailability, ignoreDraft bool) error { +func TagRancherRelease(ctx context.Context, ghClient *github.Client, tag, remoteBranch, repoOwner, repoPath string, generalAvailability, ignoreDraft, dryRun bool) error { logrus.Info("validating tag semver format") if !semver.IsValid(tag) { return errors.New("the tag `" + tag + "` isn't a valid semantic versioning string") } - logrus.Info("getting remote branch information from rancher/rancher") - branch, _, err := ghClient.Repositories.GetBranch(ctx, rancherOrg, rancherRepo, remoteBranch, true) + logrus.Info("getting remote branch information from " + repoOwner + "/" + rancherRepo) + branch, _, err := ghClient.Repositories.GetBranch(ctx, repoOwner, rancherRepo, remoteBranch, true) + if err != nil { + return err + } + logrus.Info("the latest commit on branch " + remoteBranch + " is: " + *branch.Commit.SHA) + logrus.Info("running components file") + releaseBody, err := rancherComponents(remoteBranch, repoOwner, repoPath) if err != nil { return err } - logrus.Info("the latest commit on branch " + remoteBranch + "is: " + *branch.Commit.SHA) - logrus.Info("creating release ") - releaseBody := "" // TODO: generate the release body using the script createAsDraft := !ignoreDraft createAsPrerelease := !generalAvailability - ghClient.Repositories.CreateRelease(ctx, rancherOrg, rancherRepo, &github.RepositoryRelease{ + logrus.Info("creating release ") + ghRelease := github.RepositoryRelease{ TagName: github.String(tag), Name: github.String(rancherReleaseName(generalAvailability, tag)), Body: github.String(releaseBody), Draft: &createAsDraft, Prerelease: &createAsPrerelease, GenerateReleaseNotes: github.Bool(false), - }) - return nil + } + logrus.Infof("github release: %+v", ghRelease) + if dryRun { + logrus.Info("dry run, skipping release creation") + return nil + } + _, _, err = ghClient.Repositories.CreateRelease(ctx, repoOwner, rancherRepo, &ghRelease) + return err } func rancherReleaseName(generalAvailability bool, tag string) string { @@ -499,3 +548,27 @@ func formatContentLine(line string) string { line = re.ReplaceAllString(line, " ") return strings.TrimSpace(line) } +func rancherComponents(branch, repoOwner, repoPath string) (string, error) { + script := navigateRunComponentsFileScript + if repoPath == "" { + repoPath = scriptsWorkingDir + "/" + rancherRepo + script = cloneRancherRunComponentsFileScript + } + output, err := exec.RunTemplatedScript(scriptsWorkingDir, runComponentsFileScriptFileName, script, + RunComponentsFileArgs{ + RepoName: rancherRepo, + RepoOwner: repoOwner, + RepoPath: repoPath, + Branch: branch, + }, + ) + if err != nil { + return "", err + } + logrus.Info(output) + components, err := os.ReadFile(repoPath + "/bin/rancher-components.txt") + if err != nil { + return "", err + } + return string(components), nil +} From 5397d8d4e096fbe30a6c6e2f1d505f59ccda5777 Mon Sep 17 00:00:00 2001 From: Pedro Tashima Date: Wed, 29 Nov 2023 12:55:32 -0300 Subject: [PATCH 3/9] add documentation --- cmd/rancher_release/README.md | 59 +++++++++++++++++++++++++----- cmd/rancher_release/tag_release.go | 2 +- 2 files changed, 50 insertions(+), 11 deletions(-) diff --git a/cmd/rancher_release/README.md b/cmd/rancher_release/README.md index e5806522..1b62de9a 100644 --- a/cmd/rancher_release/README.md +++ b/cmd/rancher_release/README.md @@ -17,7 +17,7 @@ Results are printed in MD, and can be pasted into Slack, but formatting is trick **Examples** -``` +```sh rancher_release list-nonmirrored-rc-images --tag v2.8.0-rc1 ``` @@ -31,7 +31,7 @@ Checks if there’s an available Helm Chart and Docker images for amd64, arm and **Examples** -``` +```sh rancher_release check-rancher-image --tag v2.8.0-rc1 ``` @@ -56,24 +56,24 @@ Optional flags can be automatically set if you are inside your rancher fork. ⚠ **Examples** -``` +```sh rancher_release set-kdm-branch-refs -n dev-v2.8-september-patches --create-pr --dry-run ``` -``` +```sh export GITHUB_TOKEN={YOUR_GITHUB_TOKEN} rancher_release set-kdm-branch-refs -n dev-v2.8-september-patches -p -r ``` -``` +```sh rancher_release set-kdm-branch-refs --fork-path $GOPATH/src/github.com/{YOUR_USERNAME}/rancher \ --base-branch release/v2.8 \ --current-kdm-branch dev-v2.8 \ --new-kdm-branch dev-v2.8-september-patches ``` -``` +```sh export GITHUB_TOKEN={YOUR_GITHUB_TOKEN} rancher_release set-kdm-branch-refs -f $GOPATH/src/github.com/{YOUR_USERNAME}/rancher -b release/v2.8 -c dev-v2.8 -n dev-v2.8-september-patches -p -u {YOUR_USERNAME} @@ -100,19 +100,19 @@ Non-required flags can be automatically set, if you are inside your rancher fork **Examples** -``` +```sh export GITHUB_TOKEN={YOUR_GITHUB_TOKEN} rancher_release set-charts-branch-refs --new-charts-branch dev-v2.9 --create-pr --dry-run ``` -``` +```sh export GITHUB_TOKEN={YOUR_GITHUB_TOKEN} rancher_release set-charts-branch-refs -n dev-v2.9 -p -r ``` -``` +```sh rancher_release set-charts-branch-refs --fork-path $GOPATH/src/github.com/{YOUR_USERNAME}/rancher \ --base-branch release/v2.8 \ --current-charts-branch dev-v2.8 \ @@ -120,13 +120,52 @@ rancher_release set-charts-branch-refs --fork-path $GOPATH/src/github.com/{YOUR_ ``` -``` +```sh export GITHUB_TOKEN={YOUR_GITHUB_TOKEN} rancher_release set-charts-branch-refs -f $GOPATH/src/github.com/{YOUR_USERNAME}/rancher -b release/v2.8 -c dev-v2.8 -n dev-v2.9 -p -o {YOUR_USERNAME} ``` +### tag-release +Tags releases in GitHub for Rancher. + +When tagging a new release using the `tag-release` command, always prefer to use the default behavior of creating as a draft and verifying the release in the UI before publishing it. +If you are running this locally, you'll need to generate a GitHub Token, use the fine-grained personal access token, scoped to only the rancher repo and with the `contents read and write` scope. + + +| **Flag** | **Description** | **Required** | +| ------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------ | +| `github-token`, `g`, `GITHUB_TOKEN` | GitHub generated token as described above. | TRUE | +| `tag`, `t` | The tag that you want to create. | TRUE | +| `remote-branch`, `b` | The branch which you want to create the tag against. | TRUE | +| `repo-owner`, `o` | Username of the rancher repo owner. Default is `rancher`, only customize this for testing purposes. | FALSE | +| `repo-path`, `p` | If you already have the rancher repo cloned in your computer, it will be used to run the components script. Before running, your local changes will be stashed. If this isn't provided, the rancher repo will be cloned at `/tmp/rancher` | FALSE | +| `general-availability`, `a` | By default, the release will be created as a pre-release, before setting this as true, make sure it absolutely needs to be a GA release. | FALSE | +| `ignore-draft`, `d` | By default, the release will be created as a draft, so you can verify everything is correct before publishing it. | FALSE | +| `dry-run`, `r` | The release will not be created, just logged. | FALSE | + +**Examples** + +```sh +export GITHUB_TOKEN={YOUR_GITHUB_TOKEN} + +rancher_release tag-release --tag v2.8.0-rc1 --remote-branch release/v2.8 --dry-run +``` + +```sh +export GITHUB_TOKEN={YOUR_GITHUB_TOKEN} + +rancher_release tag-release --tag v2.8.0-rc1 --remote-branch release/v2.8 --repo-owner tashima42 --repo-path $HOME/code/tashima42/rancher --dry-run +``` + +```sh +export GITHUB_TOKEN={YOUR_GITHUB_TOKEN} + +rancher_release tag-release -t v2.8.0 -b release/v2.8 -a -r +``` + + ### label-issues Given a release candidate, updates each GitHub issue belonging to its milestone with the tag `[zube]: To Test` and adds a comment with the prerelease version to test. diff --git a/cmd/rancher_release/tag_release.go b/cmd/rancher_release/tag_release.go index 95bf680d..30730381 100644 --- a/cmd/rancher_release/tag_release.go +++ b/cmd/rancher_release/tag_release.go @@ -53,7 +53,7 @@ func tagReleaseCommand() *cli.Command { &cli.BoolFlag{ Name: "ignore-draft", Aliases: []string{"d"}, - Usage: "by default, the release will be created as a draft, so you can verify all information is correct before unmarking it", + Usage: "by default, the release will be created as a draft, so you can verify all information is correct before publishing it", Required: false, }, &cli.BoolFlag{ From 9a6aaba941ba3428bdda6acd5754655f05b9184c Mon Sep 17 00:00:00 2001 From: Pedro Tashima Date: Wed, 29 Nov 2023 13:01:04 -0300 Subject: [PATCH 4/9] fix import --- release/rancher/rancher.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/release/rancher/rancher.go b/release/rancher/rancher.go index 5547a1bf..d04affc4 100644 --- a/release/rancher/rancher.go +++ b/release/rancher/rancher.go @@ -9,10 +9,7 @@ import ( "io" "net/http" "os" -<<<<<<< HEAD "regexp" -======= ->>>>>>> 7bf8fcd (add release body generation with rancher/rancher) "strconv" "strings" "text/template" From d4617fc8ad4bccb23847e35c6f2f6429723ffced Mon Sep 17 00:00:00 2001 From: Pedro Tashima Date: Wed, 29 Nov 2023 13:23:23 -0300 Subject: [PATCH 5/9] fix pull --- release/rancher/rancher.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/release/rancher/rancher.go b/release/rancher/rancher.go index d04affc4..2e560c81 100644 --- a/release/rancher/rancher.go +++ b/release/rancher/rancher.go @@ -135,7 +135,7 @@ git fetch echo "switch to branch ${BRANCH}" git switch "${BRANCH}" echo "pulling latests changes" -git pull +git pull origin "${BRANCH}" ./scripts/create-components-file.sh` ) From 8e1a9a8bbd7bed6c553614dcb7c850d0db867995 Mon Sep 17 00:00:00 2001 From: Pedro Tashima Date: Wed, 29 Nov 2023 13:26:32 -0300 Subject: [PATCH 6/9] move types to top --- release/rancher/rancher.go | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/release/rancher/rancher.go b/release/rancher/rancher.go index 2e560c81..2b8b03b7 100644 --- a/release/rancher/rancher.go +++ b/release/rancher/rancher.go @@ -189,6 +189,20 @@ type HelmIndex struct { } `yaml:"entries"` } +type ContentLine struct { + Line int + File string + Content string +} + +type Content struct { + RancherImages []ContentLine + FilesWithRC []ContentLine + MinFilesWithRC []ContentLine + ChartsWithDev []ContentLine + KDMWithDev []ContentLine +} + func ListRancherImagesRC(tag string) (string, error) { downloadURL := rancherImagesBaseURL + tag + rancherImagesFileName imagesFile, err := rancherImages(downloadURL) @@ -413,20 +427,6 @@ func createPRFromRancher(ctx context.Context, rancherBaseBranch, title, branchNa return err } -type ContentLine struct { - Line int - File string - Content string -} - -type Content struct { - RancherImages []ContentLine - FilesWithRC []ContentLine - MinFilesWithRC []ContentLine - ChartsWithDev []ContentLine - KDMWithDev []ContentLine -} - func CheckRancherRCDeps(ctx context.Context, local, forCi bool, org, repo, commitHash, files string) error { var ( content Content From 716a7bf355a0cf6e73ad2ad41ba5cd92cb495bb0 Mon Sep 17 00:00:00 2001 From: Pedro Tashima Date: Wed, 29 Nov 2023 13:32:35 -0300 Subject: [PATCH 7/9] add tests --- release/rancher/rancher_test.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/release/rancher/rancher_test.go b/release/rancher/rancher_test.go index 8b1baffa..ad7e081c 100644 --- a/release/rancher/rancher_test.go +++ b/release/rancher/rancher_test.go @@ -1,6 +1,7 @@ package rancher import ( + "errors" "net/http" "net/http/httptest" "reflect" @@ -59,3 +60,18 @@ func TestRancherHelmChartVersions(t *testing.T) { t.Errorf("expected %v, got %v", expectedVersions, versions) } } + +func TestRancherReleaseName(t *testing.T) { + const tag = "v2.8.0" + const expectedGAReleaseName = tag + const expectedPreReleaseName = "Pre-release " + tag + + gaReleaseName := rancherReleaseName(true, tag) + if expectedGAReleaseName != gaReleaseName { + t.Error(errors.New("expected GA release name to be '" + expectedGAReleaseName + "' got '" + gaReleaseName + "' instead")) + } + preReleaseName := rancherReleaseName(false, tag) + if expectedPreReleaseName != preReleaseName { + t.Error(errors.New("expected GA release name to be '" + expectedPreReleaseName + "' got '" + preReleaseName + "' instead")) + } +} From 434471031cc7e746aec35fed8cd70995956eec03 Mon Sep 17 00:00:00 2001 From: Pedro Tashima Date: Wed, 29 Nov 2023 13:54:07 -0300 Subject: [PATCH 8/9] remove components file --- cmd/rancher_release/README.md | 3 +- cmd/rancher_release/tag_release.go | 9 +---- release/rancher/rancher.go | 62 +----------------------------- 3 files changed, 4 insertions(+), 70 deletions(-) diff --git a/cmd/rancher_release/README.md b/cmd/rancher_release/README.md index 1b62de9a..ef6dd6ff 100644 --- a/cmd/rancher_release/README.md +++ b/cmd/rancher_release/README.md @@ -140,7 +140,6 @@ If you are running this locally, you'll need to generate a GitHub Token, use the | `tag`, `t` | The tag that you want to create. | TRUE | | `remote-branch`, `b` | The branch which you want to create the tag against. | TRUE | | `repo-owner`, `o` | Username of the rancher repo owner. Default is `rancher`, only customize this for testing purposes. | FALSE | -| `repo-path`, `p` | If you already have the rancher repo cloned in your computer, it will be used to run the components script. Before running, your local changes will be stashed. If this isn't provided, the rancher repo will be cloned at `/tmp/rancher` | FALSE | | `general-availability`, `a` | By default, the release will be created as a pre-release, before setting this as true, make sure it absolutely needs to be a GA release. | FALSE | | `ignore-draft`, `d` | By default, the release will be created as a draft, so you can verify everything is correct before publishing it. | FALSE | | `dry-run`, `r` | The release will not be created, just logged. | FALSE | @@ -156,7 +155,7 @@ rancher_release tag-release --tag v2.8.0-rc1 --remote-branch release/v2.8 --dry- ```sh export GITHUB_TOKEN={YOUR_GITHUB_TOKEN} -rancher_release tag-release --tag v2.8.0-rc1 --remote-branch release/v2.8 --repo-owner tashima42 --repo-path $HOME/code/tashima42/rancher --dry-run +rancher_release tag-release --tag v2.8.0-rc1 --remote-branch release/v2.8 --repo-owner tashima42 --dry-run ``` ```sh diff --git a/cmd/rancher_release/tag_release.go b/cmd/rancher_release/tag_release.go index 30730381..0241d9b8 100644 --- a/cmd/rancher_release/tag_release.go +++ b/cmd/rancher_release/tag_release.go @@ -38,12 +38,6 @@ func tagReleaseCommand() *cli.Command { Value: "rancher", Required: false, }, - &cli.StringFlag{ - Name: "repo-path", - Aliases: []string{"p"}, - Usage: "rancher repo path, if not provided the repo will be cloned at /tmp/rancher", - Required: false, - }, &cli.BoolFlag{ Name: "general-availability", Aliases: []string{"a"}, @@ -72,11 +66,10 @@ func tagRelease(c *cli.Context) error { tag := c.String("tag") remoteBranch := c.String("remote-branch") repoOwner := c.String("repo-owner") - repoPath := c.String("repo-path") generalAvailability := c.Bool("general-availability") ignoreDraft := c.Bool("ignore-draft") dryRun := c.Bool("dry-run") ctx := context.Background() ghClient := repository.NewGithub(ctx, token) - return rancher.TagRancherRelease(ctx, ghClient, tag, remoteBranch, repoOwner, repoPath, generalAvailability, ignoreDraft, dryRun) + return rancher.TagRancherRelease(ctx, ghClient, tag, remoteBranch, repoOwner, generalAvailability, ignoreDraft, dryRun) } diff --git a/release/rancher/rancher.go b/release/rancher/rancher.go index 2b8b03b7..3bc0df52 100644 --- a/release/rancher/rancher.go +++ b/release/rancher/rancher.go @@ -33,8 +33,6 @@ const ( setKDMBranchReferencesScriptFileName = "set_kdm_branch_references.sh" setChartReferencesScriptFileName = `set_chart_references.sh` - runComponentsFileScriptFileName = `run_components_file.sh` - scriptsWorkingDir = `/tmp` navigateCheckoutRancherScript = `#!/bin/sh set -e @@ -110,33 +108,6 @@ git commit --all --signoff -m "update chart branch references to {{ .NewBranch } if [ "${DRY_RUN}" = false ]; then git push --set-upstream origin ${BRANCH_NAME} fi` - cloneRancherRunComponentsFileScript = `#!/bin/sh -set -e -REPO_NAME={{ .RepoName }} -REPO_OWNER={{ .RepoOwner }} -REPO_PATH={{ .RepoPath }} -BRANCH={{ .Branch }} -echo "repo name: ${REPO_NAME}" -echo "org name: ${REPO_OWNER}" -echo "cloning ${REPO_OWNER}/${REPO_NAME} into ${REPO_PATH}" -git clone "git@github.com:${REPO_OWNER}/${REPO_NAME}.git" "${REPO_PATH}" -cd "${REPO_PATH}" -git switch "${BRANCH}" -./scripts/create-components-file.sh` - navigateRunComponentsFileScript = `#!/bin/sh -set -e -REPO_PATH={{ .RepoPath }} -BRANCH={{ .Branch }} -cd "${REPO_PATH}" -echo "stashing local changes" -git stash -echo "fetching changes" -git fetch -echo "switch to branch ${BRANCH}" -git switch "${BRANCH}" -echo "pulling latests changes" -git pull origin "${BRANCH}" -./scripts/create-components-file.sh` ) const templateCheckRCDevDeps = `{{- define "componentsFile" -}} @@ -370,7 +341,7 @@ func SetChartBranchReferences(ctx context.Context, forkPath, rancherBaseBranch, return nil } -func TagRancherRelease(ctx context.Context, ghClient *github.Client, tag, remoteBranch, repoOwner, repoPath string, generalAvailability, ignoreDraft, dryRun bool) error { +func TagRancherRelease(ctx context.Context, ghClient *github.Client, tag, remoteBranch, repoOwner string, generalAvailability, ignoreDraft, dryRun bool) error { logrus.Info("validating tag semver format") if !semver.IsValid(tag) { return errors.New("the tag `" + tag + "` isn't a valid semantic versioning string") @@ -381,18 +352,13 @@ func TagRancherRelease(ctx context.Context, ghClient *github.Client, tag, remote return err } logrus.Info("the latest commit on branch " + remoteBranch + " is: " + *branch.Commit.SHA) - logrus.Info("running components file") - releaseBody, err := rancherComponents(remoteBranch, repoOwner, repoPath) - if err != nil { - return err - } + createAsDraft := !ignoreDraft createAsPrerelease := !generalAvailability logrus.Info("creating release ") ghRelease := github.RepositoryRelease{ TagName: github.String(tag), Name: github.String(rancherReleaseName(generalAvailability, tag)), - Body: github.String(releaseBody), Draft: &createAsDraft, Prerelease: &createAsPrerelease, GenerateReleaseNotes: github.Bool(false), @@ -545,27 +511,3 @@ func formatContentLine(line string) string { line = re.ReplaceAllString(line, " ") return strings.TrimSpace(line) } -func rancherComponents(branch, repoOwner, repoPath string) (string, error) { - script := navigateRunComponentsFileScript - if repoPath == "" { - repoPath = scriptsWorkingDir + "/" + rancherRepo - script = cloneRancherRunComponentsFileScript - } - output, err := exec.RunTemplatedScript(scriptsWorkingDir, runComponentsFileScriptFileName, script, - RunComponentsFileArgs{ - RepoName: rancherRepo, - RepoOwner: repoOwner, - RepoPath: repoPath, - Branch: branch, - }, - ) - if err != nil { - return "", err - } - logrus.Info(output) - components, err := os.ReadFile(repoPath + "/bin/rancher-components.txt") - if err != nil { - return "", err - } - return string(components), nil -} From a2371b67c465dfc56c33fff96edbfbb03cd185b7 Mon Sep 17 00:00:00 2001 From: Pedro Tashima Date: Wed, 29 Nov 2023 13:57:13 -0300 Subject: [PATCH 9/9] remove unued struct run component files args --- release/rancher/rancher.go | 7 ------- 1 file changed, 7 deletions(-) diff --git a/release/rancher/rancher.go b/release/rancher/rancher.go index 3bc0df52..8a578306 100644 --- a/release/rancher/rancher.go +++ b/release/rancher/rancher.go @@ -145,13 +145,6 @@ type SetBranchReferencesArgs struct { DryRun bool } -type RunComponentsFileArgs struct { - RepoName string - RepoOwner string - RepoPath string - Branch string -} - type HelmIndex struct { Entries struct { Rancher []struct {