diff --git a/cmd_gen/main.go b/cmd_gen/main.go index 66af861..1c4e38a 100644 --- a/cmd_gen/main.go +++ b/cmd_gen/main.go @@ -22,6 +22,7 @@ import ( "os" "path/filepath" "sort" + "strconv" "strings" "text/template" @@ -29,19 +30,20 @@ import ( ) var ( - // Commandline flags + // Commandline flags: should be string if it may not exist modelRoot string // modelRoot is the root directory of the models. repoSlug string // repoSlug is the "owner/repo" name of the models repo (e.g. openconfig/public). commitSHA string branchName string // branchName is the name of the branch where the commit occurred. - prNumber int + prNumberStr string // prNumberStr is the PR number. compatReports string // e.g. "goyang-ygot,pyangbind,pyang@1.7.8" extraPyangVersions string // e.g. "1.2.3,3.4.5" skippedValidators string // e.g. "yanglint,pyang@head" // Derived flags (for ease of use) - owner string - repo string + owner string + repo string + prNumber int // local run flags local bool // local run toggle @@ -68,7 +70,7 @@ func init() { flag.StringVar(&modelRoot, "modelRoot", "", "root directory to OpenConfig models") flag.StringVar(&repoSlug, "repo-slug", "openconfig/public", "repo where CI is run") flag.StringVar(&commitSHA, "commit-sha", "", "commit SHA of the PR") - flag.IntVar(&prNumber, "pr-number", 0, "PR number") + flag.StringVar(&prNumberStr, "pr-number", "", "PR number") flag.StringVar(&branchName, "branch", "", "branch name of commit") flag.StringVar(&compatReports, "compat-report", "", "comma-separated validators (e.g. goyang-ygot,pyang@1.7.8,pyang@head) in compatibility report instead of a standalone PR status") flag.StringVar(&skippedValidators, "skipped-validators", "", "comma-separated validators (e.g. goyang-ygot,pyang@1.7.8,pyang@head) not to be ran at all, not even in the compatibility report") @@ -305,6 +307,13 @@ func main() { log.Fatalf("modelDirName and validator can only be specified for local cmd generation") } + if prNumberStr != "" { + var err error + if prNumber, err = strconv.Atoi(prNumberStr); err != nil { + log.Fatalf("error encountered while parsing PR number: %s", err) + } + } + badgeOnly := false // If it's a push on master, just upload badge for normal validators as the only action. if prNumber == 0 { diff --git a/post_results/main.go b/post_results/main.go index a66d9da..b438012 100644 --- a/post_results/main.go +++ b/post_results/main.go @@ -21,6 +21,7 @@ import ( "os" "path/filepath" "sort" + "strconv" "strings" "text/template" @@ -45,18 +46,19 @@ const ( ) var ( - // flags + // flags: should be string if it may not exist. validatorId string // validatorId is the unique name identifying the validator (see commonci for all of them) modelRoot string // modelRoot is the root directory of the models. repoSlug string // repoSlug is the "owner/repo" name of the models repo (e.g. openconfig/public). - prNumber int + prNumberStr string // prNumberStr is the PR number. branchName string // branchName is the name of the branch where the commit occurred. commitSHA string version string // version is a specific version of the validator that's being run (empty means latest). // derived flags - owner string - repo string + owner string + repo string + prNumber int // badgeCmdTemplate is the badge creation and upload command generated for pushes to the master branch. badgeCmdTemplate = mustTemplate("badgeCmd", `REMOTE_PATH_PFX=gs://artifacts.disco-idea-817.appspot.com/compatibility-badges/{{ .RepoPrefix }}: @@ -91,7 +93,7 @@ func init() { flag.StringVar(&validatorId, "validator", "", "unique name of the validator") flag.StringVar(&modelRoot, "modelRoot", "", "root directory to OpenConfig models") flag.StringVar(&repoSlug, "repo-slug", "", "repo where CI is run") - flag.IntVar(&prNumber, "pr-number", 0, "PR number") + flag.StringVar(&prNumberStr, "pr-number", "", "PR number") flag.StringVar(&branchName, "branch", "", "branch name of commit") flag.StringVar(&commitSHA, "commit-sha", "", "commit SHA of the PR") flag.StringVar(&version, "version", "", "(optional) specific version of the validator tool.") @@ -754,6 +756,13 @@ func main() { if commitSHA == "" { log.Fatalf("no commit SHA") } + if prNumberStr != "" { + var err error + if prNumber, err = strconv.Atoi(prNumberStr); err != nil { + log.Fatalf("error encountered while parsing PR number: %s", err) + } + } + if prNumber == 0 && branchName != "master" { log.Fatalf("no PR branch name supplied or push trigger not on master branch") }