do: verify the action exists before running

Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
This commit is contained in:
Andrea Luzzardi 2022-03-08 18:34:47 -08:00
parent 116e25ce20
commit 9f2d56f3c4
3 changed files with 30 additions and 19 deletions

View File

@ -175,17 +175,19 @@ func (p *Plan) fillAction() {
noOpRunner, noOpRunner,
) )
actions := p.source.LookupPath(cue.MakePath(ActionSelector))
actionsComment := ""
for _, cg := range actions.Doc() {
actionsComment += cg.Text()
}
p.action = &Action{ p.action = &Action{
ActionSelector.String(), Name: ActionSelector.String(),
false, Hidden: false,
actions.Path(), Path: cue.MakePath(ActionSelector),
actionsComment, Children: []*Action{},
[]*Action{}, }
actions := p.source.LookupPath(cue.MakePath(ActionSelector))
if actions.Exists() {
return
}
for _, cg := range actions.Doc() {
p.action.Comment += cg.Text()
} }
tasks := flow.Tasks() tasks := flow.Tasks()
@ -205,11 +207,11 @@ func (p *Plan) fillAction() {
} }
a = &Action{ a = &Action{
s.String(), Name: s.String(),
s.PkgPath() != "", Hidden: s.PkgPath() != "",
path, Path: path,
childComment, Comment: childComment,
[]*Action{}, Children: []*Action{},
} }
prevAction.AddChild(a) prevAction.AddChild(a)
} }

View File

@ -38,6 +38,10 @@ func NewRunner(pctx *plancontext.Context, target cue.Path, s solver.Solver) *Run
} }
func (r *Runner) Run(ctx context.Context, src *compiler.Value) error { func (r *Runner) Run(ctx context.Context, src *compiler.Value) error {
if !src.LookupPath(r.target).Exists() {
return fmt.Errorf("%s not found", r.target.String())
}
if err := r.update(cue.MakePath(), src); err != nil { if err := r.update(cue.MakePath(), src); err != nil {
return err return err
} }

View File

@ -4,7 +4,13 @@ setup() {
common_setup common_setup
} }
@test "plan/do dynamic tasks - fails to find tasks" { @test "plan/do: action sanity checks" {
run "$DAGGER" "do" -p ./plan/do/actions.cue not exist
assert_failure
assert_output --partial "not found"
}
@test "plan/do: dynamic tasks - fails to find tasks" {
# Europa loader handles the cwd differently, therefore we need to CD into the tree at or below the parent of cue.mod # Europa loader handles the cwd differently, therefore we need to CD into the tree at or below the parent of cue.mod
cd "$TESTDIR" cd "$TESTDIR"
run "$DAGGER" "do" -p ./plan/do/dynamic_tasks.cue test b run "$DAGGER" "do" -p ./plan/do/dynamic_tasks.cue test b
@ -12,12 +18,12 @@ setup() {
refute_output --partial "actions.test.b" refute_output --partial "actions.test.b"
} }
@test "plan/do dynamic tasks - fails to run tasks" { @test "plan/do: dynamic tasks - fails to run tasks" {
run "$DAGGER" "do" -p ./plan/do/dynamic_tasks.cue "test" run "$DAGGER" "do" -p ./plan/do/dynamic_tasks.cue "test"
refute_output --partial 'actions.test.b.y' refute_output --partial 'actions.test.b.y'
} }
@test "plan/do don't run unspecified tasks" { @test "plan/do: don't run unspecified tasks" {
run "$DAGGER" "do" -p ./plan/do/do_not_run_unspecified_tasks.cue test run "$DAGGER" "do" -p ./plan/do/do_not_run_unspecified_tasks.cue test
assert_output --partial "actions.test.one.script" assert_output --partial "actions.test.one.script"
assert_output --partial "actions.test.three.script" assert_output --partial "actions.test.three.script"
@ -32,7 +38,6 @@ setup() {
refute_output --partial 'client.filesystem."./dependent_do".write' refute_output --partial 'client.filesystem."./dependent_do".write'
} }
@test "plan/hello" { @test "plan/hello" {
# Europa loader handles the cwd differently, therefore we need to CD into the tree at or below the parent of cue.mod # Europa loader handles the cwd differently, therefore we need to CD into the tree at or below the parent of cue.mod
cd "$TESTDIR" cd "$TESTDIR"