Add script and docs for linter (#1151)
This commit is contained in:
parent
f527d63c86
commit
84dca03311
@ -1,7 +1,5 @@
|
||||
run:
|
||||
timeout: 5m
|
||||
modules-download-mode: readonly
|
||||
|
||||
linters:
|
||||
disable:
|
||||
- errcheck
|
||||
|
@ -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.
|
||||
|
17
script/ensure-golangci-lint-installed
Executable file
17
script/ensure-golangci-lint-installed
Executable file
@ -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
|
15
script/lint
Executable file
15
script/lint
Executable file
@ -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
|
Loading…
Reference in New Issue
Block a user