Skip to content

Commit

Permalink
Linters: Add github action, update README
Browse files Browse the repository at this point in the history
Github action will:

1. Lint
2. Format (err if any diff)
3. Run 'go mod tidy' (err if any diff)
  • Loading branch information
r-vasquez committed Dec 14, 2023
1 parent 9c10bbc commit 70cf43c
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/lint-golang.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Lint golang

on: [push, pull_request]

jobs:
go:
name: Lint go files
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Setup go
uses: actions/setup-go@v3
with:
go-version: stable

- name: Run golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: latest
args: --timeout 5m

- name: Install gofumpt
env:
GOFUMPT_VER: 0.5.0
run: |
mkdir -v -p "$HOME/.local/bin"
wget -O "$HOME/.local/bin/gofumpt" "https://github.com/mvdan/gofumpt/releases/download/v${GOFUMPT_VER}/gofumpt_v${GOFUMPT_VER}_linux_amd64"
chmod 0700 "$HOME/.local/bin/gofumpt"
- name: Run gofumpt
run: |
find . -type f -name '*.go' ! -name '*.pb.go' | xargs -n1 "$HOME/.local/bin/gofumpt" -w -lang=1.21
git diff --exit-code
- name: go mod tidy
run: |
go mod tidy
git diff --exit-code -- go.mod go.sum
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,22 @@ Schema: ThingSchema(),
}
```

### Running Linters and Formatter

#### Prerequisites
- [golangci-lint](https://github.com/golangci/golangci-lint)
- [gofumpt](https://github.com/mvdan/gofumpt)

#### Run the commands

**Linter:**
```
$ golangci-lint run --config .golangci.yml
```

**Formatter:**
```
$ gofumpt -w ./
# -w writes the result to source file.
```

0 comments on commit 70cf43c

Please sign in to comment.