Merge pull request #821 from Icinga/golangci-lint-init-and-fix #3373
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Go | |
on: | |
push: | |
branches: | |
- main | |
- 'support/*' | |
pull_request: {} | |
jobs: | |
build-test: | |
strategy: | |
matrix: | |
os: [ macos-latest, ubuntu-latest ] | |
runs-on: ${{ matrix.os }} | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-go@v5 | |
with: | |
go-version: 1.x | |
- run: go build ./... | |
- run: go test -v -race ./... | |
lint: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-go@v5 | |
with: | |
go-version: 1.x | |
- uses: dominikh/staticcheck-action@fe1dd0c3658873b46f8c9bb3291096a617310ca6 # v1.3.1 | |
with: | |
install-go: false | |
- uses: golangci/golangci-lint-action@v6 | |
with: | |
version: latest | |
only-new-issues: true | |
# Enable the gosec linter w/o having to create a .golangci.yml config | |
args: -E gosec | |
vet: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-go@v5 | |
with: | |
go-version: 1.x | |
- run: go vet ./... | |
fmt: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-go@v5 | |
with: | |
go-version: 1.x | |
- name: Run gofmt -d . | |
run: | | |
fmtvar="$(gofmt -d .)" | |
echo "$fmtvar" | |
test -z "$fmtvar" | |
modtidy: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-go@v5 | |
with: | |
go-version: 1.x | |
- name: Run go mod tidy | |
run: | | |
go mod tidy | |
gitdiff="$(git diff -U0)" | |
echo "$gitdiff" | |
test -z "$gitdiff" | |
vendor-diff: | |
if: github.event_name == 'pull_request' | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/setup-go@v5 | |
with: | |
go-version: 1.x | |
- name: Checkout base commit | |
uses: actions/checkout@v4 | |
with: | |
path: a | |
ref: ${{ github.base_ref }} | |
- name: Download dependencies of base commit | |
run: go mod vendor | |
working-directory: a | |
- name: Checkout PR | |
uses: actions/checkout@v4 | |
with: | |
path: b | |
- name: Download dependencies of PR | |
run: go mod vendor | |
working-directory: b | |
- name: Diff of dependencies | |
run: diff -ur --color=always a/vendor b/vendor || true |