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

Feature: auto chart bumps for development branches #152

Merged
merged 26 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
a5e17ff
small refactor at main.go
nicholasSUSE Oct 9, 2024
6c2ad0a
adding auto-chart-bump feature
nicholasSUSE Nov 5, 2024
7d9ed5e
adding implementation of auto chart bumps
nicholasSUSE Nov 5, 2024
beaee9d
adding parse chart name from package feature
nicholasSUSE Nov 5, 2024
98ac6fc
re-utilizing 2 functions from other packages:
nicholasSUSE Nov 5, 2024
5b3b386
modififying GetPackage()/GetPackages()
nicholasSUSE Nov 5, 2024
8cd96b0
adding parsePackageYaml method
nicholasSUSE Nov 5, 2024
07c5753
continuing the previous commit.
nicholasSUSE Nov 5, 2024
f4a9ab3
continuing previous commit n.2
nicholasSUSE Nov 5, 2024
ca81640
load release yaml object, we must modify after the chart bump is comp…
nicholasSUSE Nov 5, 2024
0241adf
BumpChart() implementation start
nicholasSUSE Nov 5, 2024
cb08d8a
calculateNextVersion
nicholasSUSE Nov 5, 2024
2415042
calculateNextVersion n.2
nicholasSUSE Nov 5, 2024
3a059da
calculateNextVersion n.3
nicholasSUSE Nov 5, 2024
bc86473
calculateNextVersion() n.4
nicholasSUSE Nov 5, 2024
75d9d76
calculateNextVersion n.5
nicholasSUSE Nov 5, 2024
9d01e6f
calculateNextVersion() n.6 - final
nicholasSUSE Nov 5, 2024
b463f3f
unit-tests
nicholasSUSE Nov 5, 2024
e637cc9
refactoring structs for better maintainance
nicholasSUSE Nov 5, 2024
2b312e3
Finishing BumpChart
nicholasSUSE Nov 5, 2024
003bc51
additionalchart.go -> adding the AutoGeneratedBumpVersion that was ge…
nicholasSUSE Nov 5, 2024
6f9fea6
refactor ExportHelmChart n.1
nicholasSUSE Nov 5, 2024
8fe5305
refactor ExportHelmChart n.2
nicholasSUSE Nov 5, 2024
f67dec4
refactor ExportHelmChart n.3
nicholasSUSE Nov 5, 2024
1179b67
enabling fields for UpstreamOptions
nicholasSUSE Nov 5, 2024
7c885dd
updating make validate to use the auto-bump procedure when enabled in…
nicholasSUSE Nov 5, 2024
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
183 changes: 114 additions & 69 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" OR
BRANCH="dev-v2.y" make <command>
Available branches: (release-v2.8; dev-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,22 @@ 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: "chart-bump",
Usage: `Generate a new chart bump PR.
`,
Action: chartBump,
Before: setupCache,
Flags: []cli.Flag{packageFlag, branchFlag},
},
}

Expand Down Expand Up @@ -454,8 +455,25 @@ func generateCharts(c *cli.Context) {
}
chartsScriptOptions := parseScriptOptions()
for _, p := range packages {
if err := p.GenerateCharts(chartsScriptOptions.OmitBuildMetadataOnExport); err != nil {
logrus.Fatal(err)
if p.Auto == false {
if err := p.GenerateCharts(chartsScriptOptions.OmitBuildMetadataOnExport); err != nil {
logrus.Fatal(err)
}
} else {
repoRoot := getRepoRoot()

bump, err := auto.SetupBump(repoRoot, p.Name, "dev-v2.10", chartsScriptOptions)
if err != nil {
fmt.Printf("failed to initialize the chart bump: %s", err.Error())
bump.Pkg.Clean()
os.Exit(1)
}

if err := bump.BumpChart(); err != nil {
fmt.Printf("failed to bump the chart: %s", err.Error())
bump.Pkg.Clean()
os.Exit(1)
}
}
}
}
Expand Down Expand Up @@ -621,7 +639,7 @@ func cleanCache(c *cli.Context) {
}

func parseScriptOptions() *options.ChartsScriptOptions {
configYaml, err := ioutil.ReadFile(ChartsScriptOptionsFile)
configYaml, err := ioutil.ReadFile(defaultChartsScriptOptionsFile)
if err != nil {
logrus.Fatalf("Unable to find configuration file: %s", err)
}
Expand Down Expand Up @@ -836,3 +854,30 @@ func compareIndexFiles(c *cli.Context) {
}
fmt.Println("index.yaml files are the same at git repository and charts.rancher.io")
}

func chartBump(c *cli.Context) {
if CurrentPackage == "" {
fmt.Println("CurrentPackage environment variable must be set")
os.Exit(1)
}
if Branch == "" {
fmt.Println("Branch environment variable must be set")
os.Exit(1)
}

repoRoot := getRepoRoot()
chartsScriptOptions := parseScriptOptions()

bump, err := auto.SetupBump(repoRoot, CurrentPackage, Branch, chartsScriptOptions)
if err != nil {
fmt.Printf("failed to initialize the chart bump: %s", err.Error())
bump.Pkg.Clean()
os.Exit(1)
}

if err := bump.BumpChart(); err != nil {
fmt.Printf("failed to bump the chart: %s", err.Error())
bump.Pkg.Clean()
os.Exit(1)
}
}
Loading
Loading