|
1 |
| -#!/bin/bash -e |
| 1 | +#!/bin/bash |
2 | 2 | #
|
3 | 3 | # Copyright 2017 the Heptio Ark contributors.
|
4 | 4 | #
|
|
14 | 14 | # See the License for the specific language governing permissions and
|
15 | 15 | # limitations under the License.
|
16 | 16 |
|
17 |
| -HACK_DIR=$(dirname "${BASH_SOURCE}") |
| 17 | +set -o errexit |
| 18 | +set -o nounset |
| 19 | +set -o pipefail |
18 | 20 |
|
19 |
| -echo "Updating formatting" |
| 21 | +if [[ ${1:-} == '--verify' ]]; then |
| 22 | + # List file diffs that need formatting updates |
| 23 | + MODE='-d' |
| 24 | + ACTION='Verifying' |
| 25 | +else |
| 26 | + # Write formatting updates to files |
| 27 | + MODE='-w' |
| 28 | + ACTION='Updating' |
| 29 | +fi |
20 | 30 |
|
21 |
| -gofmt -w -s $(find . -type f -name "*.go" -not -path "./vendor/*" -not -path "./pkg/generated/*" -not -name "zz_generated*") |
| 31 | +if ! command -v goimports > /dev/null; then |
| 32 | + echo 'goimports is missing - please run "go get golang.org/x/tools/cmd/goimports"' |
| 33 | + exit 1 |
| 34 | +fi |
22 | 35 |
|
23 |
| -command -v goimports > /dev/null || go get golang.org/x/tools/cmd/goimports |
24 |
| -goimports -w -d $(find . -type f -name "*.go" -not -path "./vendor/*" -not -path "./pkg/generated/*" -not -name "zz_generated*") |
| 36 | +files="$(find . -type f -name '*.go' -not -path './vendor/*' -not -path './pkg/generated/*' -not -name 'zz_generated*')" |
| 37 | +echo "${ACTION} gofmt" |
| 38 | +for file in ${files}; do |
| 39 | + output=$(gofmt "${MODE}" -s "${file}") |
| 40 | + if [[ -n "${output}" ]]; then |
| 41 | + VERIFY_FMT_FAILED=1 |
| 42 | + echo "${output}" |
| 43 | + fi |
| 44 | +done |
| 45 | +if [[ -n "${VERIFY_FMT_FAILED:-}" ]]; then |
| 46 | + echo "${ACTION} gofmt - failed! Please run 'make update'." |
| 47 | +else |
| 48 | + echo "${ACTION} gofmt - done!" |
| 49 | +fi |
25 | 50 |
|
26 |
| -echo "Success!" |
| 51 | +echo "${ACTION} goimports" |
| 52 | +for file in ${files}; do |
| 53 | + output=$(goimports "${MODE}" -local github.com/heptio/ark "${file}") |
| 54 | + if [[ -n "${output}" ]]; then |
| 55 | + VERIFY_IMPORTS_FAILED=1 |
| 56 | + echo "${output}" |
| 57 | + fi |
| 58 | +done |
| 59 | +if [[ -n "${VERIFY_IMPORTS_FAILED:-}" ]]; then |
| 60 | + echo "${ACTION} goimports - failed! Please run 'make update'." |
| 61 | +else |
| 62 | + echo "${ACTION} goimports - done!" |
| 63 | +fi |
| 64 | + |
| 65 | +if [[ -n "${VERIFY_FMT_FAILED:-}" || -n "${VERIFY_IMPORTS_FAILED:-}" ]]; then |
| 66 | + exit 1 |
| 67 | +fi |
0 commit comments