1
0
mirror of https://github.com/drone/drone-cli.git synced 2026-01-24 11:48:01 +01:00

add key build fields to starlark context

This commit is contained in:
Brad Rydzewski 2019-06-11 11:33:02 -07:00
parent 34c43c728a
commit 482252adeb
2 changed files with 53 additions and 3 deletions

@ -14,11 +14,17 @@ def build(version):
}
def main(ctx):
if ctx['repo']['name'] == 'hello-world':
print('hello-world')
if ctx['build']['message'].find('[skip build]'):
return {
'kind': 'pipeline',
'name': 'publish_only',
'steps': [
docker('octocat/hello-world'),
],
}
return {
'kind': 'pipeline',
'name': 'default',
'name': 'build_and_publish',
'steps': [
build('1.11'),
build('1.12'),

@ -60,6 +60,40 @@ var Command = cli.Command{
Name: "repo.slug",
Usage: "repository slug",
},
cli.StringFlag{
Name: "build.event",
Usage: "build event",
Value: "push",
},
cli.StringFlag{
Name: "build.branch",
Usage: "build branch",
Value: "master",
},
cli.StringFlag{
Name: "build.source",
Usage: "build source branch",
Value: "master",
},
cli.StringFlag{
Name: "build.target",
Usage: "build target branch",
Value: "master",
},
cli.StringFlag{
Name: "build.ref",
Usage: "build ref",
Value: "refs/heads/master",
},
cli.StringFlag{
Name: "build.commit",
Usage: "build commit sha",
},
cli.StringFlag{
Name: "build.message",
Usage: "build commit message",
},
},
}
@ -99,6 +133,16 @@ func generate(c *cli.Context) error {
repo.SetKey(starlark.String("slug"), starlark.String(c.String("repo.slug")))
dict.SetKey(starlark.String("repo"), &repo)
build := starlark.Dict{}
build.SetKey(starlark.String("event"), starlark.String(c.String("build.event")))
build.SetKey(starlark.String("branch"), starlark.String(c.String("build.branch")))
build.SetKey(starlark.String("source"), starlark.String(c.String("build.source_branch")))
build.SetKey(starlark.String("target"), starlark.String(c.String("build.target_branch")))
build.SetKey(starlark.String("ref"), starlark.String(c.String("build.ref")))
build.SetKey(starlark.String("commit"), starlark.String(c.String("build.commit")))
build.SetKey(starlark.String("message"), starlark.String(c.String("build.message")))
dict.SetKey(starlark.String("build"), &build)
args := starlark.Tuple([]starlark.Value{&dict})
mainVal, err = starlark.Call(thread, main, args, nil)
if err != nil {