Skip to content

GitHooks

Andy Williams edited this page Feb 6, 2020 · 14 revisions

As there are many checks on our continuous integration server it's easy to accidentally forget something on a minor commit that could fail the build. No-one likes to be the one to cause a build to fail so instead why not install these git hooks to help avoid the extra work 😃?

Make sure that your $GOPATH/bin is in your environment path or this may fail! You also need to have goimports installed, you can do this using go get golang.org/x/tools/cmd/goimports.

.git/hooks/pre-commit

#!/bin/sh
fail_if_err () {
        eval $2
        if [[ "$?" -ne 0 ]]; then
                echo "FAILED " $1
                exit 1
        fi
}

NO_VENDOR=$(find . -iname '*.go' -type f | grep -v /vendor/ | grep -v /cmd/fyne/internal/mobile)
GO_FILES=$(for file in $NO_VENDOR; do if [[ `head -n1 $file` != "// auto-generated" ]]; then echo $file; fi; done)

fail_if_err "FORMAT" "goimports -w $GO_FILES"
fail_if_err "TEST"   "go test ./... > /dev/null"
fail_if_err "VET"    "go vet ./..."
fail_if_err "LINT"   "golint -set_exit_status \$(go list ./... | grep -v /cmd/fyne/internal/mobile)"

Welcome to the Fyne wiki.

Project documentation

Getting involved

Platform details

Clone this wiki locally