Add script and docs for linter (#1151)

This commit is contained in:
Tim Vaillancourt 2022-07-18 18:21:32 +02:00 committed by GitHub
parent f527d63c86
commit 84dca03311
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 39 additions and 3 deletions

View File

@ -1,7 +1,5 @@
run: run:
timeout: 5m timeout: 5m
modules-download-mode: readonly
linters: linters:
disable: disable:
- errcheck - errcheck

View File

@ -5,7 +5,7 @@
Getting started with gh-ost development is simple! Getting started with gh-ost development is simple!
- First obtain the repository with `git clone` or `go get`. - 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. - This will bootstrap the environment if needed, format the code, build the code, and then run the unit test.
## CI build workflow ## 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. 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: ## Notes:
Currently, `script/ensure-go-installed` will install `go` for Mac OS X and Linux. We welcome PR's to add other platforms. Currently, `script/ensure-go-installed` will install `go` for Mac OS X and Linux. We welcome PR's to add other platforms.

View 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
View 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