Documentation ¶
Index ¶
- Constants
- Variables
- func AppendVersionToName(validatorName, version string) string
- func Retry(maxN uint, name string, f func() error) error
- func ValidatorAndVersionsDiff(aStr, bStr string) string
- func ValidatorResultsDir(validatorId, version string) string
- type GithubPRUpdate
- type GithubRequestHandler
- func (g *GithubRequestHandler) AddGistComment(gistID, title, output string) (int64, error)
- func (g *GithubRequestHandler) AddPRComment(body *string, owner, repo string, prNumber int) error
- func (g *GithubRequestHandler) CreateCIOutputGist(description, content string) (string, string, error)
- func (g *GithubRequestHandler) DeleteLabel(labelName, owner, repo string, prNumber int) error
- func (g *GithubRequestHandler) IsPRApproved(owner, repo string, prNumber int) (bool, error)
- func (g *GithubRequestHandler) PostLabel(labelName, labelColor, owner, repo string, prNumber int) error
- func (g *GithubRequestHandler) UpdatePRStatus(update *GithubPRUpdate) error
- type ModelInfo
- type OpenConfigModelMap
- type Validator
- type ValidatorAndVersion
Constants ¶
const ( // RootDir is the base directory of the CI, which in GCB is /workspace. RootDir = "/workspace" // ResultsDir contains all results of the CI process. ResultsDir = "/workspace/results" // UserConfigDir by convention contains the user config that is // passed from cmd_gen to later stages of the CI. It is common to all // CI steps. UserConfigDir = "/workspace/user-config" // CompatReportValidatorsFile notifies later CI steps of the validators // that should be reported as a compatibility report. CompatReportValidatorsFile = UserConfigDir + "/compat-report-validators.txt" // ScriptFileName by convention is the script with the validator commands. ScriptFileName = "script.sh" // LatestVersionFileName by convention contains the version description // of the tool as output by the tool during the build. // Whenever the "latest" version of a tool has a version, it should // exist, and for now, it should be output into this file for display. LatestVersionFileName = "latest-version.txt" // OutFileName by convention contains the stdout of the script file. OutFileName = "out" // FailFileName by convention contains the stderr of the script file. FailFileName = "fail" )
Variables ¶
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{ Name: "pyang", IsPerModel: true, }, "oc-pyang": &Validator{ Name: "OpenConfig Linter", IsPerModel: true, }, "pyangbind": &Validator{ Name: "pyangbind", IsPerModel: true, }, "goyang-ygot": &Validator{ Name: "goyang/ygot", IsPerModel: true, }, "yanglint": &Validator{ Name: "yanglint", IsPerModel: true, }, "confd": &Validator{ Name: "ConfD Basic", IsPerModel: true, }, "regexp": &Validator{ Name: "regexp tests", IsPerModel: false, }, "misc-checks": &Validator{ Name: "Miscellaneous Checks", IsPerModel: true, IgnoreRunCi: true, }, "compat-report": &Validator{ Name: "Compatibility Report", IsPerModel: false, ReportOnly: true, }, } // LabelColors are some helper hex colours for posting to GitHub. LabelColors = map[string]string{ "yellow": "ffe200", "red": "ff0000", "orange": "ffa500", "blue": "00bfff", } )
Functions ¶
func AppendVersionToName ¶
AppendVersionToName appends the version to the given validator name
func Retry ¶
Retry retries a function maxN times or when it returns true. In between each retry there is a small delay. This is intended to be used for posting results to GitHub from GCB, which frequently experiences errors likely due to connection issues.
func ValidatorAndVersionsDiff ¶
ValidatorAndVersionsDiff removes the comma-separated list of <validatorId>@<version> entries in bStr from aStr.
func ValidatorResultsDir ¶
ValidatorResultsDir determines where a particular validator and version's results are stored.
Types ¶
type GithubPRUpdate ¶
type GithubPRUpdate struct { Owner string Repo string Ref string NewStatus string URL string Description string Context string }
GithubPRUpdate is used to specify how an update to the status of a PR should be made with the UpdatePRStatus method.
type GithubRequestHandler ¶
type GithubRequestHandler struct {
// contains filtered or unexported fields
}
GithubRequestHandler carries information relating to the GitHub session that is being used for the continuous integration.
func NewGitHubRequestHandler ¶
func NewGitHubRequestHandler() (*GithubRequestHandler, error)
NewGitHubRequestHandler sets up a new GithubRequestHandler struct which creates an oauth2 client with a GitHub access token (as specified by the GITHUB_ACCESS_TOKEN environment variable), and a connection to the GitHub API through the github.com/google/go-github/github library. It returns the initialised GithubRequestHandler struct, or an error as to why the initialisation failed.
func (*GithubRequestHandler) AddGistComment ¶
func (g *GithubRequestHandler) AddGistComment(gistID, title, output string) (int64, error)
AddGistComment adds a comment to a gist and returns its ID.
func (*GithubRequestHandler) AddPRComment ¶
func (g *GithubRequestHandler) AddPRComment(body *string, owner, repo string, prNumber int) error
AddPRComment posts a comment to the PR.
func (*GithubRequestHandler) CreateCIOutputGist ¶
func (g *GithubRequestHandler) CreateCIOutputGist(description, content string) (string, string, error)
CreateCIOutputGist creates a GitHub Gist, and appends a comment with the result of the validator into it. The function returns the URL and ID of the Gist that was created, and an error if experienced during processing.
func (*GithubRequestHandler) DeleteLabel ¶
func (g *GithubRequestHandler) DeleteLabel(labelName, owner, repo string, prNumber int) error
DeleteLabel removes the given label from the PR. It does not remove the label from the repo.
func (*GithubRequestHandler) IsPRApproved ¶
func (g *GithubRequestHandler) IsPRApproved(owner, repo string, prNumber int) (bool, error)
IsPRApproved checks whether a PR is approved or not. TODO: If this function is actually used, it should undergo testing due to having some logic. unit tests can be created based onon actual models-ci repo data that's sent back for a particular PR.
func (*GithubRequestHandler) PostLabel ¶
func (g *GithubRequestHandler) PostLabel(labelName, labelColor, owner, repo string, prNumber int) error
PostLabel posts the given label to the PR. It is idempotent. unit tests can be created based onon actual models-ci repo data that's sent back.
func (*GithubRequestHandler) UpdatePRStatus ¶
func (g *GithubRequestHandler) UpdatePRStatus(update *GithubPRUpdate) error
UpdatePRStatus takes an input githubPRUpdate struct and updates a GitHub pull request's status with the relevant details. It returns an error if the update was not successful.
type ModelInfo ¶
type ModelInfo struct { Name string DocFiles []string `yaml:"docs"` BuildFiles []string `yaml:"build"` RunCi bool `yaml:"run-ci"` }
ModelInfo represents the yaml model of an OpenConfig .spec.yml file.
type OpenConfigModelMap ¶
type OpenConfigModelMap struct { // ModelRoot is the path to the OpenConfig models root directory. ModelRoot string // ModelInfoMap stores all ModelInfo for each model directory keyed by // the relative path to the model directory's .spec.yml. ModelInfoMap map[string][]ModelInfo }
OpenConfigModelMap represents the directory structure and model information of the entire OpenConfig models required for CI.
func ParseOCModels ¶
func ParseOCModels(modelRoot string) (OpenConfigModelMap, error)
ParseOCModels walks the path given at modelRoot to populate the OpenConfigModelMap.
func (OpenConfigModelMap) SingleLineBuildFiles ¶
func (m OpenConfigModelMap) SingleLineBuildFiles() string
SingleLineBuildFiles returns all of the build files defined by all the .spec.yml files in the models, if run-ci is true, as a single, space-separated line.
type Validator ¶
type Validator struct { // The longer name of the validator. Name string // IsPerModel means the validator is run per-model, not across the // entire repo of YANG files. IsPerModel bool // IgnoreRunCi says that the validator's commands should be generated // regardless of what the "run-ci" value in the .spec.yml is -- namely, // that it is a per-build validator, and bypasses the "run-ci" flag // that turns on more advanced testing. IgnoreRunCi bool // ReportOnly indicates that it's not itself a validator, it's just a // CI item that does reporting on other validators. ReportOnly bool }
Validator describes a validation tool.
func (*Validator) StatusName ¶
StatusName determines the status description for the version of the validator.
type ValidatorAndVersion ¶
func GetValidatorAndVersionsFromString ¶
func GetValidatorAndVersionsFromString(validatorsAndVersionsStr string) ([]ValidatorAndVersion, map[string]map[string]bool)
GetValidatorAndVersionsFromString converts a comma-separated list of <validatorId>@<version> names to a list of ValidatorAndVersion and nested map of validatorId to version for checking existence.