diff --git a/.golangci.yml b/.golangci.yml index 4e0bc4f..cb5f21f 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,7 +1,5 @@ run: timeout: 5m - modules-download-mode: readonly - linters: disable: - errcheck diff --git a/doc/coding-ghost.md b/doc/coding-ghost.md index ee26f0c..24425e3 100644 --- a/doc/coding-ghost.md +++ b/doc/coding-ghost.md @@ -5,7 +5,7 @@ Getting started with gh-ost development is simple! - First obtain the repository with `git clone` or `go get`. -- From inside of the repository run `script/cibuild` +- From inside of the repository run `script/cibuild`. - This will bootstrap the environment if needed, format the code, build the code, and then run the unit test. ## CI build workflow @@ -14,6 +14,12 @@ Getting started with gh-ost development is simple! If additional steps are needed, please add them into this workflow so that the workflow remains simple. +## `golang-ci` linter + +To enfore best-practices, Pull Requests are automatically linted by [`golang-ci`](https://golangci-lint.run/). The linter config is located at [`.golangci.yml`](https://github.com/github/gh-ost/blob/master/.golangci.yml) and the `golangci-lint` GitHub Action is located at [`.github/workflows/golangci-lint.yml`](https://github.com/github/gh-ost/blob/master/.github/workflows/golangci-lint.yml). + +To run the `golang-ci` linters locally _(recommended before push)_, use `script/lint`. + ## Notes: Currently, `script/ensure-go-installed` will install `go` for Mac OS X and Linux. We welcome PR's to add other platforms. diff --git a/script/ensure-golangci-lint-installed b/script/ensure-golangci-lint-installed new file mode 100755 index 0000000..e4f49f5 --- /dev/null +++ b/script/ensure-golangci-lint-installed @@ -0,0 +1,17 @@ +#!/bin/bash + +# See https://github.com/golangci/golangci-lint/releases +GOLANGCI_RELEASE=v1.46.2 +GOLANGCI_INSTALL_SCRIPT=https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh + +if [ -z "$GOPATH" ]; then + echo "GOPATH must be set" + exit 1 +fi + +if [ ! -x "$GOPATH/bin/golangci-lint" ]; then + echo "Installing golangci-lint $GOLANGCI_RELEASE using script: $GOLANGCI_INSTALL_SCRIPT" + curl -sSfL $GOLANGCI_INSTALL_SCRIPT | sh -s -- -b $(go env GOPATH)/bin $GOLANGCI_RELEASE +fi + +$GOPATH/bin/golangci-lint --version diff --git a/script/lint b/script/lint new file mode 100755 index 0000000..e29aa8b --- /dev/null +++ b/script/lint @@ -0,0 +1,15 @@ +#!/bin/bash + +set -e + +. script/ensure-go-installed +. script/ensure-golangci-lint-installed + +if [ -x "$GOPATH/bin/golangci-lint" ]; then + echo "Running golangci-lint run" + $GOPATH/bin/golangci-lint run --config=.golangci.yml + echo "Done, exit code: $?" +else + echo "ERROR: cannot find golangci-lint at $GOPATH/bin" + exit 1 +fi