Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions cmd/update-rules/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"k8s.io/publishing-bot/cmd/publishing-bot/config"
)

const GitDefaultBranch = "master"
const gitDefaultBranch = "main"

type options struct {
branch string
Expand Down Expand Up @@ -149,7 +149,7 @@ func UpdateRules(rules *config.RepositoryRules, branch, goVer string, deleteRule
// find the mainBranch rules
for i := range r.Branches {
br := r.Branches[i]
if br.Name == GitDefaultBranch {
if br.Name == gitDefaultBranch {
cloneBranchRule(&br, &newBranchRule)
mainBranchRuleFound = true
break
Expand All @@ -158,7 +158,7 @@ func UpdateRules(rules *config.RepositoryRules, branch, goVer string, deleteRule

// if mainBranch rules not found for repo, it means it's removed from master tree, log warning and skip updating the rules
if !mainBranchRuleFound {
glog.Warningf("%s branch rules not found for repo %s, skipping to update branch %s rules", GitDefaultBranch, r.DestinationRepository, branch)
glog.Warningf("%s branch rules not found for repo %s, skipping to update branch %s rules", gitDefaultBranch, r.DestinationRepository, branch)
continue
}

Expand Down
30 changes: 15 additions & 15 deletions cmd/update-rules/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
var (
testdataRules = "testdata/rules.yaml"
testdataInvalidRules = "testdata/invalid_rules.yaml"
remoteRules = "https://raw.githubusercontent.com/kubernetes/kubernetes/master/staging/publishing/rules.yaml"
remoteRules = "https://raw.githubusercontent.com/kcp-dev/kcp/main/staging/publishing/rules.yaml"
)

func TestLoad(t *testing.T) {
Expand Down Expand Up @@ -100,8 +100,8 @@ func TestUpdateRules(t *testing.T) {
"1.16.1",
},
{
"master branch rule update for go version",
"master",
"main branch rule update for go version",
"main",
"1.16.4",
},
}
Expand All @@ -115,51 +115,51 @@ func TestUpdateRules(t *testing.T) {
UpdateRules(rules, tt.branch, tt.goVersion, false)

for _, repoRule := range rules.Rules {
var masterRulePresent, branchRulePresent bool
var masterRuleIndex, branchRuleIndex int
var mainRulePresent, branchRulePresent bool
var mainRuleIndex, branchRuleIndex int

for i, branchRule := range repoRule.Branches {
switch branchRule.Name {
case "master":
masterRulePresent = true
masterRuleIndex = i
case "main":
mainRulePresent = true
mainRuleIndex = i
case tt.branch:
branchRulePresent = true
branchRuleIndex = i
}
}
switch masterRulePresent {
switch mainRulePresent {
case true:
if !branchRulePresent && tt.branch != "master" {
if !branchRulePresent && tt.branch != "main" {
t.Errorf("error updating branch %s rule for repo %s", tt.branch, repoRule.DestinationRepository)
}
case false:
if branchRulePresent {
t.Errorf("incorrectly added branch %s rule for repo %s whose master branch rule does not exists", tt.branch, repoRule.DestinationRepository)
t.Errorf("incorrectly added branch %s rule for repo %s whose main branch rule does not exists", tt.branch, repoRule.DestinationRepository)
}
}

if repoRule.Branches[branchRuleIndex].Source.Branch != tt.branch {
t.Errorf("incorrect update to branch %s rule for source branch field for repo %s", tt.branch, repoRule.DestinationRepository)
}

if repoRule.Branches[masterRuleIndex].Source.Dir != repoRule.Branches[branchRuleIndex].Source.Dir {
if repoRule.Branches[mainRuleIndex].Source.Dir != repoRule.Branches[branchRuleIndex].Source.Dir {
t.Errorf("incorrect update to branch %s rule for source dir field for repo %s", tt.branch, repoRule.DestinationRepository)
}

if repoRule.Branches[branchRuleIndex].GoVersion != tt.goVersion {
t.Errorf("incorrect go version set for branch %s rule for repo %s", tt.branch, repoRule.DestinationRepository)
}

if len(repoRule.Branches[masterRuleIndex].Dependencies) != len(repoRule.Branches[branchRuleIndex].Dependencies) {
if len(repoRule.Branches[mainRuleIndex].Dependencies) != len(repoRule.Branches[branchRuleIndex].Dependencies) {
t.Errorf("incorrect update to branch %s rule dependencies for repo %s", tt.branch, repoRule.DestinationRepository)
}

if len(repoRule.Branches[masterRuleIndex].RequiredPackages) != len(repoRule.Branches[branchRuleIndex].RequiredPackages) {
if len(repoRule.Branches[mainRuleIndex].RequiredPackages) != len(repoRule.Branches[branchRuleIndex].RequiredPackages) {
t.Errorf("incorrect update to branch %s rule required packages for repo %s", tt.branch, repoRule.DestinationRepository)
}

if repoRule.Branches[masterRuleIndex].SmokeTest != repoRule.Branches[branchRuleIndex].SmokeTest {
if repoRule.Branches[mainRuleIndex].SmokeTest != repoRule.Branches[branchRuleIndex].SmokeTest {
t.Errorf("incorrect update to branch %s rule smoke-test for repo %s", tt.branch, repoRule.DestinationRepository)
}
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/update-rules/testdata/invalid_rules.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ rules:
- destination: code-generator
branches:
- source:
branch: master
branch: main
dir: staging/src/k8s.io/code-generator
name: master
name: main
- source:
branch: release-1.19
dir: staging/src/k8s.io/code-generator
Expand Down
Loading