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
28 changes: 2 additions & 26 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,7 @@ on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:

build:
name: Build
runs-on: ubuntu-latest
strategy:
fail-fast: false

steps:
- name: Set up Go 1.x
uses: actions/setup-go@v2
# Use default go version so that we don't have to update it every time a new one comes out.
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v2

- name: Get dependencies
run: |
go get -v -t -d ./...

- name: Build
run: go build -v ./...

- name: Test
run: go test -v ./cmd_gen ./commonci ./post_results
go:
uses: openconfig/common-ci/.github/workflows/basic_go.yml@c2294c3c86c90e75e58c24a40d6f7f3364bbae9d
2 changes: 1 addition & 1 deletion cmd/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ openconfig-ci diff --oldp public_old/third_party --newp public_new/third_party -
os.Exit(1)
}
} else {
fmt.Printf(report.Report(opts...))
fmt.Print(report.Report(opts...))
}
return nil
},
Expand Down
2 changes: 1 addition & 1 deletion cmd_gen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ func main() {
if err != nil {
log.Fatal(err)
}
fmt.Printf(cmdStr)
fmt.Print(cmdStr)
return
} else if localModelDirName != "" || localValidatorId != "" {
log.Fatalf("modelDirName and validator can only be specified for local cmd generation")
Expand Down
26 changes: 13 additions & 13 deletions commonci/commonci.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,50 +133,50 @@ var (
// Validators contains the set of supported validators to be run under CI.
// The key is a unique identifier that's safe to use as a directory name.
Validators = map[string]*Validator{
"pyang": &Validator{
"pyang": {
Name: "pyang",
IsPerModel: true,
IsWidelyUsedTool: true,
SupportedVersion: "2.2",
},
"oc-pyang": &Validator{
"oc-pyang": {
Name: "OpenConfig Linter",
IsPerModel: true,
IsWidelyUsedTool: true,
},
"pyangbind": &Validator{
"pyangbind": {
Name: "pyangbind",
IsPerModel: true,
IsWidelyUsedTool: true,
},
"goyang-ygot": &Validator{
"goyang-ygot": {
Name: "goyang/ygot",
IsPerModel: true,
IsWidelyUsedTool: true,
},
"yanglint": &Validator{
"yanglint": {
Name: "yanglint",
IsPerModel: true,
IsWidelyUsedTool: true,
},
"confd": &Validator{
"confd": {
Name: "ConfD Basic",
IsPerModel: true,
IsWidelyUsedTool: true,
},
"regexp": &Validator{
"regexp": {
Name: "regexp tests",
IsPerModel: false,
},
"misc-checks": &Validator{
"misc-checks": {
Name: "Miscellaneous Checks",
IsPerModel: true,
IgnoreRunCi: true,
},
// This is a report-only entry for all validators configured to
// report as a compatibility check instead of as a standalone
// PR status.
"compat-report": &Validator{
"compat-report": {
Name: "Compatibility Report",
IsPerModel: false,
ReportOnly: true,
Expand Down Expand Up @@ -246,16 +246,16 @@ func ParseOCModels(modelRoot string) (OpenConfigModelMap, error) {
modelInfoMap := map[string][]ModelInfo{}
err := filepath.Walk(modelRoot, func(path string, info os.FileInfo, err error) error {
if err != nil {
return fmt.Errorf("prevent panic by handling failure accessing a path %q: %v\n", path, err)
return fmt.Errorf("prevent panic by handling failure accessing a path %q: %v", path, err)
}
if !info.IsDir() && info.Name() == ".spec.yml" {
file, err := os.Open(path)
if err != nil {
return fmt.Errorf("failed to open spec file at path %q: %v\n", path, err)
return fmt.Errorf("failed to open spec file at path %q: %v", path, err)
}
m := []ModelInfo{}
if err := yaml.NewDecoder(file).Decode(&m); err != nil {
return fmt.Errorf("error while unmarshalling spec file at path %q: %v\n", path, err)
return fmt.Errorf("error while unmarshalling spec file at path %q: %v", path, err)
}

// Change the build paths to the absolute correct paths.
Expand All @@ -267,7 +267,7 @@ func ParseOCModels(modelRoot string) (OpenConfigModelMap, error) {

relPath, err := filepath.Rel(modelRoot, filepath.Dir(path))
if err != nil {
return fmt.Errorf("failed to calculate relpath at path %q (modelRoot %q): %v\n", path, modelRoot, err)
return fmt.Errorf("failed to calculate relpath at path %q (modelRoot %q): %v", path, modelRoot, err)
}
// Allow nested model directories to be used later on as a partial file name.
relPath = strings.ReplaceAll(relPath, "/", ":")
Expand Down
22 changes: 11 additions & 11 deletions commonci/commonci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var (
basicModelMap = OpenConfigModelMap{
ModelRoot: "testdata",
ModelInfoMap: map[string][]ModelInfo{
"acl": []ModelInfo{{
"acl": {{
Name: "openconfig-acl",
DocFiles: []string{
"yang/acl/openconfig-packet-match-types.yang",
Expand All @@ -36,7 +36,7 @@ var (
},
RunCi: true,
}},
"optical-transport": []ModelInfo{{
"optical-transport": {{
Name: "openconfig-terminal-device",
DocFiles: []string{
"yang/optical-transport/openconfig-transport-types.yang",
Expand Down Expand Up @@ -135,27 +135,27 @@ func TestGetValidatorAndVersionsFromString(t *testing.T) {
desc: "single no version",
inStr: "pyang",
wantVVList: []ValidatorAndVersion{{ValidatorId: "pyang"}},
wantVVMap: map[string]map[string]bool{"pyang": map[string]bool{"": true}},
wantVVMap: map[string]map[string]bool{"pyang": {"": true}},
}, {
desc: "ending comma",
inStr: "pyang,",
wantVVList: []ValidatorAndVersion{{ValidatorId: "pyang"}},
wantVVMap: map[string]map[string]bool{"pyang": map[string]bool{"": true}},
wantVVMap: map[string]map[string]bool{"pyang": {"": true}},
}, {
desc: "ending comma with spaces around before",
inStr: " pyang, ",
wantVVList: []ValidatorAndVersion{{ValidatorId: "pyang"}},
wantVVMap: map[string]map[string]bool{"pyang": map[string]bool{"": true}},
wantVVMap: map[string]map[string]bool{"pyang": {"": true}},
}, {
desc: "single with version",
inStr: "[email protected]",
wantVVList: []ValidatorAndVersion{{ValidatorId: "pyang", Version: "1.7.2"}},
wantVVMap: map[string]map[string]bool{"pyang": map[string]bool{"1.7.2": true}},
wantVVMap: map[string]map[string]bool{"pyang": {"1.7.2": true}},
}, {
desc: "single with version and comma",
inStr: "[email protected],",
wantVVList: []ValidatorAndVersion{{ValidatorId: "pyang", Version: "1.7.2"}},
wantVVMap: map[string]map[string]bool{"pyang": map[string]bool{"1.7.2": true}},
wantVVMap: map[string]map[string]bool{"pyang": {"1.7.2": true}},
}, {
desc: "more than one version with an extraneous comma",
inStr: "[email protected],,pyang,oc-pyang,pyang@head",
Expand All @@ -166,12 +166,12 @@ func TestGetValidatorAndVersionsFromString(t *testing.T) {
{ValidatorId: "pyang", Version: "head"},
},
wantVVMap: map[string]map[string]bool{
"pyang": map[string]bool{
"pyang": {
"": true,
"head": true,
"1.7.2": true,
},
"oc-pyang": map[string]bool{
"oc-pyang": {
"": true,
},
},
Expand All @@ -185,12 +185,12 @@ func TestGetValidatorAndVersionsFromString(t *testing.T) {
{ValidatorId: "pyang", Version: "head"},
},
wantVVMap: map[string]map[string]bool{
"pyang": map[string]bool{
"pyang": {
"": true,
"head": true,
"1.7.2": true,
},
"oc-pyang": map[string]bool{
"oc-pyang": {
"": true,
},
},
Expand Down
5 changes: 1 addition & 4 deletions commonci/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ import (
// GithubRequestHandler carries information relating to the GitHub session that
// is being used for the continuous integration.
type GithubRequestHandler struct {
// hashSecret is the GitHub secret that is specified with the hook, it is
// used to validate whether the response that is received is from GitHub.
hashSecret string
// Client is the connection to GitHub that should be utilised.
client *github.Client
// accessToken is the OAuth token that should be used for interactions with
Expand Down Expand Up @@ -323,7 +320,7 @@ func NewGitHubRequestHandler() (*GithubRequestHandler, error) {
ts := oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: strings.TrimSpace(accesstk)},
)
tc := oauth2.NewClient(oauth2.NoContext, ts)
tc := oauth2.NewClient(context.Background(), ts)

// Set the timeout for the oauth client such that we do not hang around
// waiting for the client to complete.
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ go 1.18
require (
github.com/Masterminds/semver/v3 v3.1.1
github.com/golang/glog v1.1.0
github.com/golang/protobuf v1.5.3
github.com/google/go-cmp v0.5.9
github.com/google/go-github v17.0.0+incompatible
github.com/openconfig/gnmi v0.10.0
Expand All @@ -21,6 +20,7 @@ require (

require (
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/go-querystring v1.0.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
Expand Down
16 changes: 8 additions & 8 deletions post_results/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func sprintSummaryHTML(status, title, format string, a ...interface{}) string {
func readFile(path string) (string, error) {
outBytes, err := ioutil.ReadFile(path)
if err != nil {
return "", fmt.Errorf("failed to read file at path %q: %v\n", path, err)
return "", fmt.Errorf("failed to read file at path %q: %v", path, err)
}
return string(outBytes), nil
}
Expand All @@ -131,7 +131,7 @@ func processStandardOutput(rawOut string, pass, noWarnings bool) (string, error)
// Convert file path to relative path.
var err error
if errLine.Path, err = filepath.Rel(modelRoot, errLine.Path); err != nil {
return "", fmt.Errorf("failed to calculate relpath at path %q (modelRoot %q) parsed from error message: %v\n", errLine.Path, modelRoot, err)
return "", fmt.Errorf("failed to calculate relpath at path %q (modelRoot %q) parsed from error message: %v", errLine.Path, modelRoot, err)
}

processedLine := fmt.Sprintf("%s (%d): %s: <pre>%s</pre>", errLine.Path, errLine.LineNo, errLine.Status, errLine.Message)
Expand Down Expand Up @@ -174,7 +174,7 @@ func processPyangOutput(rawOut string, pass, noWarnings bool) (string, error) {
// Convert file path to relative path.
var err error
if msgLine.Path, err = filepath.Rel(modelRoot, msgLine.Path); err != nil {
return "", fmt.Errorf("failed to calculate relpath at path %q (modelRoot %q) parsed from error message: %v\n", msgLine.Path, modelRoot, err)
return "", fmt.Errorf("failed to calculate relpath at path %q (modelRoot %q) parsed from error message: %v", msgLine.Path, modelRoot, err)
}

processedLine := fmt.Sprintf("%s (%d): %s: <pre>%s</pre>", msgLine.Path, msgLine.Line, msgLine.Type, msgLine.Message)
Expand Down Expand Up @@ -227,7 +227,7 @@ func parseModelResultsHTML(validatorId, validatorResultDir string, condensed boo
// (Note that each modelDir has multiple models. Each model corresponds to a result file).
if err := filepath.Walk(validatorResultDir, func(path string, info os.FileInfo, err error) error {
if err != nil {
return fmt.Errorf("handle failure accessing a path %q: %v\n", path, err)
return fmt.Errorf("handle failure accessing a path %q: %v", path, err)
}

components := strings.Split(info.Name(), "==")
Expand All @@ -248,7 +248,7 @@ func parseModelResultsHTML(validatorId, validatorResultDir string, condensed boo
// Get output string.
outString, err := readFile(path)
if err != nil {
return fmt.Errorf("failed to read file at path %q: %v\n", path, err)
return fmt.Errorf("failed to read file at path %q: %v", path, err)
}

modelPass := true
Expand Down Expand Up @@ -326,7 +326,7 @@ func parseModelResultsHTML(validatorId, validatorResultDir string, condensed boo
func getResult(validatorId, resultsDir string, condensed bool) (string, bool, versionRecordSlice, error) {
validator, ok := commonci.Validators[validatorId]
if !ok {
return "", false, nil, fmt.Errorf("validator %q not found!", validatorId)
return "", false, nil, fmt.Errorf("validator %q not found", validatorId)
}

// outString is parsed stdout.
Expand Down Expand Up @@ -400,7 +400,7 @@ func WriteBadgeUploadCmdFile(validatorDesc, validatorUniqueStr string, pass bool
func getGistHeading(validatorId, version, resultsDir string) (string, string, error) {
validator, ok := commonci.Validators[validatorId]
if !ok {
return "", "", fmt.Errorf("getGistHeading: validator %q not found!", validatorId)
return "", "", fmt.Errorf("getGistHeading: validator %q not found", validatorId)
}

validatorDesc := validator.StatusName(version)
Expand Down Expand Up @@ -529,7 +529,7 @@ func postBreakingChangeLabel(g *commonci.GithubRequestHandler, versionRecords ve
func postResult(validatorId, version string) error {
validator, ok := commonci.Validators[validatorId]
if !ok {
return fmt.Errorf("postResult: validator %q not found!", validatorId)
return fmt.Errorf("postResult: validator %q not found", validatorId)
}
resultsDir := commonci.ValidatorResultsDir(validatorId, version)

Expand Down
16 changes: 7 additions & 9 deletions proto/results/results.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions proto/results/results.proto
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ message PyangOutput {
repeated PyangMessage messages = 1;
}

// PyangMessage represents an output line from pyang parsed using the option
// --msg-template='messages:{{path:"{file}" line:{line} code:"{code}" type:"{type}" level:{level} message:'"'{msg}'}}"
// PyangMessage represents a parsed output from pyang
//
// This is parsed using the option
// --msg-template='messages:{{path:"{file}" line:{line} code:"{code}" type:"{type}" level:{level} message:'"'{msg}'}}"
//
// Reference: https://github.com/mbj4668/pyang/blob/master/bin/pyang
message PyangMessage {
string path = 1;
Expand Down
Loading