Skip to content

Commit

Permalink
small refactor at main.go
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholasSUSE committed Oct 9, 2024
1 parent d59848e commit a5e17ff
Showing 1 changed file with 70 additions and 66 deletions.
136 changes: 70 additions & 66 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,12 @@ func main() {
if len(os.Getenv("DEBUG")) > 0 {
logrus.SetLevel(logrus.DebugLevel)
}

app := cli.NewApp()
app.Name = "charts-build-scripts"
app.Version = fmt.Sprintf("%s (%s)", Version, GitCommit)
app.Usage = "Build scripts used to maintain patches on Helm charts forked from other repositories"
// Flags
configFlag := cli.StringFlag{
Name: "config",
Usage: "A configuration file with additional options for allowing this branch to interact with other branches",
Expand Down Expand Up @@ -180,6 +182,59 @@ func main() {
Destination: &ChartVersion,
EnvVar: defaultChartVersionEnvironmentVariable,
}
branchFlag := cli.StringFlag{
Name: "branch,b",
Usage: `Usage:
./bin/charts-build-scripts <command> --branch="release-v2.y"
BRANCH="release-v2.y" make <command>
Available branches for release: (release-v2.8; release-v2.9; release-v2.10...)
`,
Required: true,
EnvVar: defaultBranchEnvironmentVariable,
Destination: &Branch,
}
localModeFlag := cli.BoolFlag{
Name: "local,l",
Usage: "Only perform local validation of the contents of assets and charts",
Required: false,
Destination: &LocalMode,
}
remoteModeFlag := cli.BoolFlag{
Name: "remote,r",
Usage: "Only perform upstream validation of the contents of assets and charts",
Required: false,
Destination: &RemoteMode,
}
ghTokenFlag := cli.StringFlag{
Name: "gh_token",
Usage: `Usage:
./bin/charts-build-scripts <command> --gh_token="********"
GH_TOKEN="*********" make <command>
Github Auth Token provided by Github Actions job
`,
Required: true,
EnvVar: defaultGHTokenEnvironmentVariable,
Destination: &GithubToken,
}
prNumberFlag := cli.StringFlag{
Name: "pr_number",
Usage: `Usage:
./bin/charts-build-scripts <command> --pr_number="****"
PR_NUMBER="****" make <command>
Pull Request identifying number provided by Github Actions job
`,
Required: true,
EnvVar: defaultPRNumberEnvironmentVariable,
Destination: &PullRequest,
}
skipFlag := cli.BoolFlag{
Name: "skip",
Usage: "Skip the execution and return success",
}

// Commands
app.Commands = []cli.Command{
{
Name: "list",
Expand Down Expand Up @@ -245,18 +300,7 @@ func main() {
Name: "validate",
Usage: "Run validation to ensure that contents of assets and charts won't overwrite released charts",
Action: validateRepo,
Flags: []cli.Flag{packageFlag, configFlag, cli.BoolFlag{
Name: "local,l",
Usage: "Only perform local validation of the contents of assets and charts",
Required: false,
Destination: &LocalMode,
}, cli.BoolFlag{
Name: "remote,r",
Usage: "Only perform upstream validation of the contents of assets and charts",
Required: false,
Destination: &RemoteMode,
},
},
Flags: []cli.Flag{packageFlag, configFlag, localModeFlag, remoteModeFlag},
},
{
Name: "standardize",
Expand All @@ -269,6 +313,7 @@ func main() {
Name: "template",
Action: createOrUpdateTemplate,
Flags: []cli.Flag{
// TODO: verify if this is the correct way to pass the variables
configFlag,
cli.StringFlag{
Name: "repositoryUrl,r",
Expand Down Expand Up @@ -331,66 +376,21 @@ func main() {
Usage: `Check charts to release in PR.
`,
Action: validateRelease,
Flags: []cli.Flag{
cli.StringFlag{
Name: "branch,b",
Usage: `Usage:
./bin/charts-build-scripts <command> --branch="release-v2.y"
BRANCH="release-v2.y" make <command>
Available branches for release: (release-v2.8; release-v2.9; release-v2.10...)
`,
Required: true,
EnvVar: defaultBranchEnvironmentVariable,
Destination: &Branch,
},
cli.StringFlag{
Name: "gh_token",
Usage: `Usage:
./bin/charts-build-scripts <command> --gh_token="********"
GH_TOKEN="*********" make <command>
Github Auth Token provided by Github Actions job
`,
Required: true,
EnvVar: defaultGHTokenEnvironmentVariable,
Destination: &GithubToken,
},
cli.StringFlag{
Name: "pr_number",
Usage: `Usage:
./bin/charts-build-scripts <command> --pr_number="****"
PR_NUMBER="****" make <command>
Pull Request identifying number provided by Github Actions job
`,
Required: true,
EnvVar: defaultPRNumberEnvironmentVariable,
Destination: &PullRequest,
},
cli.BoolFlag{
Name: "skip",
Usage: "Skip the execution and return success",
},
},
Flags: []cli.Flag{branchFlag, ghTokenFlag, prNumberFlag, skipFlag},
},
{
Name: "compare-index-files",
Usage: `Compare the index.yaml between github repository and charts.rancher.io.
`,
Action: compareIndexFiles,
Flags: []cli.Flag{
cli.StringFlag{
Name: "branch,b",
Usage: `Usage:
./bin/charts-build-scripts <command> --branch="release-v2.y"
BRANCH="release-v2.y" make <command>
Available branches for release: (release-v2.8; release-v2.9; release-v2.10...)
`,
Required: true,
EnvVar: defaultBranchEnvironmentVariable,
Destination: &Branch,
},
},
Flags: []cli.Flag{branchFlag},
},
{
Name: "auto-chart-bump",
Usage: `Generate a new chart bump PR.
`,
Action: autoChartBump,
Flags: []cli.Flag{branchFlag},
},
}

Expand All @@ -399,6 +399,10 @@ func main() {
}
}

func autoChartBump(c *cli.Context) {

}

func listPackages(c *cli.Context) {
repoRoot := getRepoRoot()
packageList, err := charts.ListPackages(repoRoot, CurrentPackage)
Expand Down

0 comments on commit a5e17ff

Please sign in to comment.