本文整理汇总了Golang中github.com/bitrise-io/stepman/models.StepModel.Audit方法的典型用法代码示例。如果您正苦于以下问题:Golang StepModel.Audit方法的具体用法?Golang StepModel.Audit怎么用?Golang StepModel.Audit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/bitrise-io/stepman/models.StepModel
的用法示例。
在下文中一共展示了StepModel.Audit方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: ParseStepYml
// ParseStepYml ...
func ParseStepYml(pth string, validate bool) (models.StepModel, error) {
bytes, err := fileutil.ReadBytesFromFile(pth)
if err != nil {
return models.StepModel{}, err
}
var stepModel models.StepModel
if err := yaml.Unmarshal(bytes, &stepModel); err != nil {
return models.StepModel{}, err
}
if err := stepModel.Normalize(); err != nil {
return models.StepModel{}, err
}
if validate {
if err := stepModel.Audit(); err != nil {
return models.StepModel{}, err
}
}
if err := stepModel.FillMissingDefaults(); err != nil {
return models.StepModel{}, err
}
return stepModel, nil
}
示例2: auditStepModelBeforeSharePullRequest
func auditStepModelBeforeSharePullRequest(step models.StepModel, stepID, version string) error {
if err := step.Audit(); err != nil {
return fmt.Errorf("Failed to audit step infos, error: %s", err)
}
pth, err := pathutil.NormalizedOSTempDirPath(stepID + version)
if err != nil {
return fmt.Errorf("Failed to create a temporary directory for the step's audit, error: %s", err)
}
if step.Source == nil {
return fmt.Errorf("Missing Source porperty")
}
err = retry.Times(2).Wait(3 * time.Second).Try(func(attempt uint) error {
return cmdex.GitCloneTag(step.Source.Git, pth, version)
})
if err != nil {
return fmt.Errorf("Failed to git-clone the step (url: %s) version (%s), error: %s",
step.Source.Git, version, err)
}
latestCommit, err := cmdex.GitGetLatestCommitHashOnHead(pth)
if err != nil {
return fmt.Errorf("Failed to get git-latest-commit-hash, error: %s", err)
}
if latestCommit != step.Source.Commit {
return fmt.Errorf("Step commit hash (%s) should be the latest commit hash (%s) on git tag", step.Source.Commit, latestCommit)
}
return nil
}
示例3: auditStepModelBeforeSharePullRequest
func auditStepModelBeforeSharePullRequest(step models.StepModel, stepID, version string) error {
if err := step.Audit(); err != nil {
return err
}
pth, err := pathutil.NormalizedOSTempDirPath(stepID + version)
if err != nil {
return err
}
if err := cmdex.GitCloneTag(step.Source.Git, pth, version); err != nil {
return err
}
latestCommit, err := cmdex.GitGetLatestCommitHashOnHead(pth)
if err != nil {
return err
}
if latestCommit != step.Source.Commit {
return fmt.Errorf("Step commit hash (%s) should be the latest commit hash (%s) on git tag", step.Source.Commit, latestCommit)
}
return nil
}
示例4: create
func create(c *cli.Context) error {
toolMode := c.Bool(ToolMode)
share, err := ReadShareSteplibFromFile()
if err != nil {
log.Error(err)
log.Fatalln("You have to start sharing with `stepman share start`, or you can read instructions with `stepman share`")
}
// Input validation
tag := c.String(TagKey)
if tag == "" {
log.Fatalln("No Step tag specified")
}
gitURI := c.String(GitKey)
if gitURI == "" {
log.Fatalln("No Step url specified")
}
stepID := c.String(StepIDKEy)
if stepID == "" {
stepID = getStepIDFromGit(gitURI)
}
if stepID == "" {
log.Fatalln("No Step id specified")
}
r := regexp.MustCompile(`[a-z0-9-]+`)
if find := r.FindString(stepID); find != stepID {
log.Fatalln("StepID doesn't conforms to: [a-z0-9-]")
}
route, found := stepman.ReadRoute(share.Collection)
if !found {
log.Fatalf("No route found for collectionURI (%s)", share.Collection)
}
stepDirInSteplib := stepman.GetStepCollectionDirPath(route, stepID, tag)
stepYMLPathInSteplib := path.Join(stepDirInSteplib, "step.yml")
if exist, err := pathutil.IsPathExists(stepYMLPathInSteplib); err != nil {
log.Fatalf("Failed to check step.yml path in steplib, err: %s", err)
} else if exist {
log.Warnf("Step already exist in path: %s.", stepDirInSteplib)
if val, err := goinp.AskForBool("Would you like to overwrite local version of Step?"); err != nil {
log.Fatalf("Failed to get bool, err: %s", err)
} else {
if !val {
log.Errorln("Unfortunately we can't continue with sharing without an overwrite exist step.yml.")
log.Fatalln("Please finish your changes, run this command again and allow it to overwrite the exist step.yml!")
}
}
}
// Clone Step to tmp dir
tmp, err := pathutil.NormalizedOSTempDirPath("")
if err != nil {
log.Fatalf("Failed to get temp directory, err: %s", err)
}
log.Infof("Cloning Step from (%s) with tag (%s) to temporary path (%s)", gitURI, tag, tmp)
if err := cmdex.GitCloneTag(gitURI, tmp, tag); err != nil {
log.Fatalf("Git clone failed, err: %s", err)
}
// Update step.yml
tmpStepYMLPath := path.Join(tmp, "step.yml")
bytes, err := fileutil.ReadBytesFromFile(tmpStepYMLPath)
if err != nil {
log.Fatalf("Failed to read Step from file, err: %s", err)
}
var stepModel models.StepModel
if err := yaml.Unmarshal(bytes, &stepModel); err != nil {
log.Fatalf("Failed to unmarchal Step, err: %s", err)
}
commit, err := cmdex.GitGetCommitHashOfHEAD(tmp)
if err != nil {
log.Fatalf("Failed to get commit hash, err: %s", err)
}
stepModel.Source = &models.StepSourceModel{
Git: gitURI,
Commit: commit,
}
stepModel.PublishedAt = pointers.NewTimePtr(time.Now())
// Validate step-yml
if err := stepModel.Audit(); err != nil {
log.Fatalf("Failed to validate Step, err: %s", err)
}
for _, input := range stepModel.Inputs {
key, value, err := input.GetKeyValuePair()
if err != nil {
log.Fatalf("Failed to get Step input key-value pair, err: %s", err)
}
options, err := input.GetOptions()
if err != nil {
log.Fatalf("Failed to get Step input (%s) options, err: %s", key, err)
}
if len(options.ValueOptions) > 0 && value == "" {
//.........这里部分代码省略.........