diff --git a/cli/app/deploy.go b/cli/app/deploy.go index aa8b4062..72e45a58 100644 --- a/cli/app/deploy.go +++ b/cli/app/deploy.go @@ -108,7 +108,11 @@ checkout as-is. Recipe commit hashes are also supported as values for } if err := lint.LintForErrors(app.Recipe); err != nil { - log.Fatal(err) + if internal.Chaos { + log.Warn(err) + } else { + log.Fatal(err) + } } if err := validateSecrets(cl, app); err != nil { diff --git a/pkg/lint/recipe.go b/pkg/lint/recipe.go index 4f7f5e24..1855b6e2 100644 --- a/pkg/lint/recipe.go +++ b/pkg/lint/recipe.go @@ -184,6 +184,8 @@ var LintRules = map[string][]LintRule{ func LintForErrors(recipe recipe.Recipe) error { log.Debugf("linting for critical errors in %s configs", recipe.Name) + var errors string + for level := range LintRules { if level != "error" { continue @@ -196,14 +198,18 @@ func LintForErrors(recipe recipe.Recipe) error { ok, err := rule.Function(recipe) if err != nil { - return fmt.Errorf("lint %s: %s", rule.Ref, err) + errors += fmt.Sprintf("\nlint %s: %s", rule.Ref, err) } if !ok { - return fmt.Errorf("lint error in %s configs: \"%s\" failed lint checks (%s)", recipe.Name, rule.Description, rule.Ref) + errors += fmt.Sprintf("\n * %s (%s)", rule.Description, rule.Ref) } } } + if len(errors) > 0 { + return fmt.Errorf("recipe '%s' failed lint checks:\n"+errors[1:], recipe.Name) + } + log.Debugf("linting successful, %s is well configured", recipe.Name) return nil diff --git a/tests/integration/app_deploy.bats b/tests/integration/app_deploy.bats index 5828a6b5..87c3e79c 100644 --- a/tests/integration/app_deploy.bats +++ b/tests/integration/app_deploy.bats @@ -75,6 +75,45 @@ teardown(){ assert_success } +# bats test_tags=slow +@test "bail if recipe lint errors and no --chaos" { + # Break the recipe + run sed -i '/traefik.enable=.*/d' "$ABRA_DIR/recipes/$TEST_RECIPE/compose.yml" + assert_success + + # Commit the breakage (so we can test without --chaos) + _set_git_author + + run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" commit -a -m 'Break recipe' + assert_success + + # Make a broken release + run $ABRA recipe sync --patch "$TEST_RECIPE" + run $ABRA recipe release --patch -n "$TEST_RECIPE" + + # Make sure we deploy latest + _wipe_env_version + + run $ABRA app deploy "$TEST_APP_DOMAIN" --no-input + assert_failure + assert_output --partial 'failed lint checks' + + run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" reset --hard HEAD~1 + latestRelease=$(_latest_release) + run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" tag -d "$latestRelease" +} + +# bats test_tags=slow +@test "warn on recipe lint errors with --chaos" { + # Break the recipe + run sed -i '/traefik.enable=.*/d' "$ABRA_DIR/recipes/$TEST_RECIPE/compose.yml" + assert_success + + run $ABRA app deploy "$TEST_APP_DOMAIN" --no-input --no-converge-checks --chaos + assert_success + assert_output --partial 'failed lint checks' +} + # bats test_tags=slow @test "ensure recipe up to date if no --offline" { wantHash=$(_get_n_hash 3) @@ -147,16 +186,6 @@ teardown(){ assert_exists "$ABRA_DIR/recipes/$TEST_RECIPE" } -@test "no deploy if lint error" { - run sed -i '/traefik.enable=.*/d' "$ABRA_DIR/recipes/$TEST_RECIPE/compose.yml" - assert_success - - run $ABRA app deploy "$TEST_APP_DOMAIN" \ - --no-input --no-converge-checks --chaos - assert_failure - assert_output --partial 'failed lint checks' -} - # bats test_tags=slow @test "error if already deployed and no --force/--chaos" { _deploy_app