Skip to content

Commit

Permalink
Adding support for removing branch
Browse files Browse the repository at this point in the history
Adding support for removing branch
  • Loading branch information
Mohit Sharma committed Sep 19, 2023
1 parent 3c83c76 commit b5fddcb
Show file tree
Hide file tree
Showing 3 changed files with 1,989 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
_output
/coverage.out
.idea/*
19 changes: 16 additions & 3 deletions cmd/update-rules/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const GitDefaultBranch = "master"

type options struct {
branch string
remove bool
rulesFile string
goVersion string
out string
Expand All @@ -41,6 +42,7 @@ func parseOptions() options {
var o options
flag.StringVar(&o.branch, "branch", "", "[required] Branch to update rules for, e.g. --branch release-x.yy")
flag.StringVar(&o.rulesFile, "rules", "", "[required] URL or Path of the rules file to update rules for, e.g. --rules path/or/url/to/rules/file.yaml")
flag.BoolVar(&o.remove, "remove", false, "Remove old rules to deprecated branch")
flag.StringVar(&o.goVersion, "go", "", "Golang version to pin for this branch, e.g. --go 1.16.1")
flag.StringVar(&o.out, "o", "", "Path to export the updated rules to, e.g. -o /tmp/rules.yaml")

Expand All @@ -53,7 +55,10 @@ func parseOptions() options {
update-rules -branch release-1.21 -go 1.16.4 -rules https://raw.githubusercontent.com/kubernetes/kubernetes/master/staging/publishing/rules.yaml
# Update rules and export to /tmp/rules.yaml
update-rules -branch release-1.22 -go 1.17.1 -o /tmp/rules.yaml -rules /go/src/k8s.io/kubernetes/staging/publishing/rules.yaml`
update-rules -branch release-1.22 -go 1.17.1 -o /tmp/rules.yaml -rules /go/src/k8s.io/kubernetes/staging/publishing/rules.yaml
# Update rules to remove deprecated branch and export to /tmp/rules.yaml
update-rules -branch release-1.22 -remove -o /tmp/rules.yaml -rules /go/src/k8s.io/kubernetes/staging/publishing/rules.yaml`

flag.Usage = func() {
fmt.Fprintf(os.Stdout, "\n Usage: update-rules --branch BRANCH --rules PATHorURL [--go VERSION | -o PATH]")
Expand Down Expand Up @@ -86,7 +91,7 @@ func main() {
}

// update rules for all destination repos
UpdateRules(rules, o.branch, o.goVersion)
UpdateRules(rules, o.branch, o.goVersion, o.remove)

// validate rules after update
if err := config.Validate(rules); err != nil {
Expand Down Expand Up @@ -121,7 +126,7 @@ func load(rulesFile string) (*config.RepositoryRules, error) {
return rules, nil
}

func UpdateRules(rules *config.RepositoryRules, branch, goVer string) {
func UpdateRules(rules *config.RepositoryRules, branch, goVer string, removeRules bool) {
// run the update per destination repo in the rules
for j, r := range rules.Rules {
var mainBranchRuleFound bool
Expand Down Expand Up @@ -154,6 +159,14 @@ func UpdateRules(rules *config.RepositoryRules, branch, goVer string) {
break
}
}
for i, br := range r.Branches {
if removeRules && br.Name == branch {
glog.Infof("Will remove rule for %s %s", branch, r.DestinationRepository)
r.Branches = append(r.Branches[:i], r.Branches[i+1:]...)
branchRuleExists = true
break
}
}
// new rules, append to destination's branches
if !branchRuleExists {
r.Branches = append(r.Branches, newBranchRule)
Expand Down
Loading

0 comments on commit b5fddcb

Please sign in to comment.