From ff9bac50446852a904585eeeda022e29b5828d50 Mon Sep 17 00:00:00 2001 From: ross-spencer Date: Fri, 15 Nov 2024 19:04:10 +0100 Subject: [PATCH] Linting workflows --- .codespellignore | 0 .github/workflows/linting.yml | 32 ++++++++++++++++++++++++++++++++ .github/workflows/tests.yml | 24 ++++++++++++++++++++++++ .pre-commit-config.yaml | 19 +++++++++++++++++++ justfile | 17 +++++++++++++++++ 5 files changed, 92 insertions(+) create mode 100644 .codespellignore create mode 100644 .github/workflows/linting.yml create mode 100644 .github/workflows/tests.yml create mode 100644 .pre-commit-config.yaml create mode 100644 justfile diff --git a/.codespellignore b/.codespellignore new file mode 100644 index 0000000..e69de29 diff --git a/.github/workflows/linting.yml b/.github/workflows/linting.yml new file mode 100644 index 0000000..b5c8960 --- /dev/null +++ b/.github/workflows/linting.yml @@ -0,0 +1,32 @@ +name: linting + +on: ["push", "pull_request"] + +jobs: + ci: + name: "run linting" + strategy: + fail-fast: true + matrix: + os: ["ubuntu-latest"] + go: ["1.23.x"] + runs-on: ${{ matrix.os }} + steps: + - name: "checkout" + uses: actions/checkout@v2 + - name: "fetch unshallow" + run: git fetch --prune --unshallow + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: ${{ matrix.go }} + - name: "fmt" + run: if [ "$(go fmt ./... | wc -l)" -gt 0 ]; then echo "go fmt failed, please run again locally"; exit 1; fi + if: matrix.os == 'ubuntu-latest' + - name: "imports" + run: if [ "$(goimports -l . | wc -l)" -gt 0 ]; then echo "goimports failed, please run again locally"; exit 1; fi + - name: "vet" + run: "go vet ./..." + - run: "go install honnef.co/go/tools/cmd/staticcheck@latest" + - name: staticcheck + run: "staticcheck ./..." diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..6ae8121 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,24 @@ +name: linting + +on: ["push", "pull_request"] + +jobs: + ci: + name: "run linting" + strategy: + fail-fast: true + matrix: + os: ["ubuntu-latest", "windows-latest", "macOS-latest"] + go: ["1.22.x", "1.23.x"] + runs-on: ${{ matrix.os }} + steps: + - name: "checkout" + uses: actions/checkout@v2 + - name: "fetch unshallow" + run: git fetch --prune --unshallow + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: ${{ matrix.go }} + - name: "test" + run: "go test ./..." diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..10d29c3 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,19 @@ +repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v5.0.0 + hooks: + - id: check-yaml + - id: check-json + - id: check-toml + - id: end-of-file-fixer + - id: trailing-whitespace + - id: check-case-conflict +- repo: https://github.com/igorshubovych/markdownlint-cli + rev: v0.42.0 + hooks: + - id: markdownlint +- repo: https://github.com/codespell-project/codespell + rev: v2.3.0 + hooks: + - id: codespell + args: [-I, .codespellignore] diff --git a/justfile b/justfile new file mode 100644 index 0000000..1aefeac --- /dev/null +++ b/justfile @@ -0,0 +1,17 @@ +# CLI helpers. + +# help +help: + @echo "Command line helpers for this project.\n" + @just -l + +# Run go linting +linting: + goimports -w . + go fmt . + - go vet . + - staticcheck . + +# Run pre-commit +all-checks: + pre-commit run --all-files \ No newline at end of file