Andrew Lamb | 3501307 | 2020-05-04 11:05:48 -0600 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | # |
| 3 | # Copyright 2020 The Chromium OS Authors. All rights reserved. |
| 4 | # Use of this source code is governed by a BSD-style license that can be |
| 5 | # found in the LICENSE file. |
| 6 | |
| 7 | # Move to this script's directory. |
| 8 | script_dir="$(realpath "$(dirname "$0")")" |
| 9 | cd "${script_dir}" || exit 1 |
| 10 | |
| 11 | set -e |
| 12 | |
| 13 | source "${script_dir}/setup_cipd.sh" |
| 14 | |
| 15 | shopt -s globstar nullglob |
| 16 | |
| 17 | echo "Checking Starlark files formatted..." |
| 18 | found_unformatted=0 |
| 19 | for f in util/**/*.star; do |
David Burger | 94ed6db | 2020-07-20 11:57:44 -0600 | [diff] [blame] | 20 | if ! lucicfg fmt "${f}" -dry-run; then |
Andrew Lamb | 3501307 | 2020-05-04 11:05:48 -0600 | [diff] [blame] | 21 | found_unformatted=1 |
| 22 | fi |
| 23 | done |
| 24 | |
David Burger | 94ed6db | 2020-07-20 11:57:44 -0600 | [diff] [blame] | 25 | if [[ ${found_unformatted} -ne 0 ]]; then |
| 26 | echo "Found unformatted Starlark files. Please format with lucicfg fmt (https://chromium.googlesource.com/infra/luci/luci-go/+/HEAD/lucicfg/doc/README.md#formatting_linting)." |
Andrew Lamb | 3501307 | 2020-05-04 11:05:48 -0600 | [diff] [blame] | 27 | exit 1 |
| 28 | fi |
| 29 | |
| 30 | echo "Linting Starlark files..." |
| 31 | found_lint_fail=0 |
| 32 | for f in util/**/*.star; do |
David Burger | 94ed6db | 2020-07-20 11:57:44 -0600 | [diff] [blame] | 33 | if ! lucicfg lint "${f}"; then |
Andrew Lamb | 3501307 | 2020-05-04 11:05:48 -0600 | [diff] [blame] | 34 | found_lint_fail=1 |
| 35 | fi |
| 36 | done |
| 37 | |
David Burger | 94ed6db | 2020-07-20 11:57:44 -0600 | [diff] [blame] | 38 | if [[ ${found_lint_fail} -ne 0 ]]; then |
| 39 | echo "Found linting errors in Starlark files. Please fix and re-lint with lucicfg lint (https://chromium.googlesource.com/infra/luci/luci-go/+/HEAD/lucicfg/doc/README.md#formatting_linting)." |
Andrew Lamb | 3501307 | 2020-05-04 11:05:48 -0600 | [diff] [blame] | 40 | exit 1 |
David Burger | 94ed6db | 2020-07-20 11:57:44 -0600 | [diff] [blame] | 41 | fi |