From 4a076753225b3929f1e7f6a68806287d68998059 Mon Sep 17 00:00:00 2001 From: Seth Hoenig Date: Mon, 16 Dec 2024 17:01:27 -0600 Subject: [PATCH] ci: enable ci steps for testing, linting, copywrite --- .github/workflows/ci.yaml | 38 ++++++++++++++++++++++ .github/workflows/scripts/copywrite.hcl | 14 ++++++++ .github/workflows/scripts/golangci.yaml | 43 +++++++++++++++++++++++++ Justfile | 37 +++++++++++++++++++++ 4 files changed, 132 insertions(+) create mode 100644 .github/workflows/ci.yaml create mode 100644 .github/workflows/scripts/copywrite.hcl create mode 100644 .github/workflows/scripts/golangci.yaml create mode 100644 Justfile diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..56d9f96 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,38 @@ +name: Run CI Tests +on: + pull_request: + paths-ignore: + - 'README.md' + - 'LICENSE' + push: + branches: + - 'main' +jobs: + run-copywrite: + timeout-minutes: 5 + runs-on: ubuntu-24.04 + steps: + - uses: actions/checkout@v4 + - uses: hashicorp/setup-copywrite@v1.1.3 + - name: verify copyright + run: | + copywrite --config .github/workflows/scripts/copywrite.hcl \ + headers --spdx "BSD-3-Clause" --plan + run-tests: + runs-on: ubuntu-24.04 + steps: + - uses: actions/checkout@v4 + - uses: extractions/setup-just@v2 + - uses: actions/setup-go@v5 + with: + go-version-file: go.mod + cache-dependency-path: '**/go.sum' + - uses: golangci/golangci-lint-action@v6 + with: + version: v1.62.2 + skip-cache: true + args: --config .github/workflows/scripts/golangci.yaml + - name: Run Go Test + run: | + just test + diff --git a/.github/workflows/scripts/copywrite.hcl b/.github/workflows/scripts/copywrite.hcl new file mode 100644 index 0000000..f94866f --- /dev/null +++ b/.github/workflows/scripts/copywrite.hcl @@ -0,0 +1,14 @@ +schema_version = 1 + +project { + license = "BSD-3-Clause" + copyright_holder = "CattleCloud LLC" + copyright_year = 2024 + header_ignore = [ + "**/*.sh", + ".src/**", + ".bin/**", + ".github/**", + ".golangci.yaml", + ] +} diff --git a/.github/workflows/scripts/golangci.yaml b/.github/workflows/scripts/golangci.yaml new file mode 100644 index 0000000..5be68bc --- /dev/null +++ b/.github/workflows/scripts/golangci.yaml @@ -0,0 +1,43 @@ +run: + timeout: 5m +linters: + enable: + - asasalint + - asciicheck + - bidichk + - bodyclose + - copyloopvar + - dogsled + - dupword + - durationcheck + - errcheck + - errname + - errorlint + - exhaustive + - gochecknoinits + - gocritic + - gofmt + - gosimple + - govet + - ineffassign + - makezero + - misspell + - musttag + - nilnil + - noctx + - perfsprint + - prealloc + - predeclared + - reassign + - revive + - rowserrcheck + - staticcheck + - sqlclosecheck + - tagalign + - tenv + - unused + - whitespace + +linters-settings: + exhaustive: + default-signifies-exhaustive: true diff --git a/Justfile b/Justfile new file mode 100644 index 0000000..3135ff7 --- /dev/null +++ b/Justfile @@ -0,0 +1,37 @@ +set shell := ["bash", "-u", "-c"] + +export scripts := ".github/workflows/scripts" +export GOBIN := `echo $PWD/.bin` + +# show available commands +[private] +default: + @just --list + +# tidy up Go modules +[group('build')] +tidy: + go mod tidy + +# run tests across source tree +[group('build')] +test: + go test -v -race -count=1 ./... + +# ensure copywrite headers present on source files +[group('lint')] +copywrite: + copywrite \ + --config {{scripts}}/copywrite.hcl headers \ + --spdx "BSD-3-Clause" + +# apply go vet command on source tree +[group('lint')] +vet: + go vet ./... + +# apply golangci-lint linters on source tree +[group('lint')] +lint: vet + golangci-lint run --config .github/workflows/scripts/golangci.yaml +