Skip to content

Commit

Permalink
Merge pull request #30 from openconfig/master-push-fix
Browse files Browse the repository at this point in the history
Be resilient to PR-only flags that don't exist during pushes to master
  • Loading branch information
wenovus authored Jun 16, 2020
2 parents 3842ece + 1074a13 commit c1e39cc
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
19 changes: 14 additions & 5 deletions cmd_gen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,28 @@ import (
"os"
"path/filepath"
"sort"
"strconv"
"strings"
"text/template"

"github.com/openconfig/models-ci/commonci"
)

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,[email protected]"
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
Expand All @@ -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,[email protected],pyang@head) in compatibility report instead of a standalone PR status")
flag.StringVar(&skippedValidators, "skipped-validators", "", "comma-separated validators (e.g. goyang-ygot,[email protected],pyang@head) not to be ran at all, not even in the compatibility report")
Expand Down Expand Up @@ -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 {
Expand Down
19 changes: 14 additions & 5 deletions post_results/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"os"
"path/filepath"
"sort"
"strconv"
"strings"
"text/template"

Expand All @@ -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 }}:
Expand Down Expand Up @@ -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.")
Expand Down Expand Up @@ -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")
}
Expand Down

0 comments on commit c1e39cc

Please sign in to comment.