blob: 0d5c8c4238458c6ffec79403a517d5ed385ef7f3 [file] [log] [blame]
Andrew Lamb35013072020-05-04 11:05:48 -06001#!/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.
8script_dir="$(realpath "$(dirname "$0")")"
9cd "${script_dir}" || exit 1
10
11set -e
12
13source "${script_dir}/setup_cipd.sh"
14
15shopt -s globstar nullglob
16
17echo "Checking Starlark files formatted..."
18found_unformatted=0
19for f in util/**/*.star; do
David Burger94ed6db2020-07-20 11:57:44 -060020 if ! lucicfg fmt "${f}" -dry-run; then
Andrew Lamb35013072020-05-04 11:05:48 -060021 found_unformatted=1
22 fi
23done
24
David Burger94ed6db2020-07-20 11:57:44 -060025if [[ ${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 Lamb35013072020-05-04 11:05:48 -060027 exit 1
28fi
29
30echo "Linting Starlark files..."
31found_lint_fail=0
32for f in util/**/*.star; do
David Burger94ed6db2020-07-20 11:57:44 -060033 if ! lucicfg lint "${f}"; then
Andrew Lamb35013072020-05-04 11:05:48 -060034 found_lint_fail=1
35 fi
36done
37
David Burger94ed6db2020-07-20 11:57:44 -060038if [[ ${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 Lamb35013072020-05-04 11:05:48 -060040 exit 1
David Burger94ed6db2020-07-20 11:57:44 -060041fi