Skip to content

Commit

Permalink
Basic linting workflow
Browse files Browse the repository at this point in the history
An attempt to determine a baseline CI workflow for Golang if we
include no further linters.
  • Loading branch information
ross-spencer committed Nov 21, 2024
1 parent 6d25dc1 commit 0141543
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 5 deletions.
Empty file added .codespellignore
Empty file.
38 changes: 38 additions & 0 deletions .github/workflows/linting.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
name: linting

on:
pull_request:
push:
branches: [main]

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@v4
- name: "fetch unshallow"
run: git fetch --prune --unshallow
- name: Set up Go
uses: actions/setup-go@v5
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
- name: "vet"
run: "go vet ./..."
- name: "setup imports"
run: "go install golang.org/x/tools/cmd/goimports@latest"
- name: "test imports"
run: if [ "$(goimports -l . | wc -l)" -gt 0 ]; then echo "goimports failed, please run again locally"; exit 1; fi
- name: "setup staticcheck"
run: "go install honnef.co/go/tools/cmd/staticcheck@latest"
- name: staticcheck
run: "staticcheck ./..."
28 changes: 28 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
name: unit-tests

on:
pull_request:
push:
branches: [main]

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 ./..."
19 changes: 19 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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]
7 changes: 4 additions & 3 deletions bolthandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ package main
import (
"encoding/json"
"fmt"
"github.com/httpreserve/httpreserve"
kval "github.com/kval-access-language/kval-bbolt"
"github.com/speps/go-hashids"
"log"
"os"
"time"

"github.com/httpreserve/httpreserve"
kval "github.com/kval-access-language/kval-bbolt"
"github.com/speps/go-hashids"
)

// values to use to create hashid
Expand Down
3 changes: 2 additions & 1 deletion csvhandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package main
import (
"encoding/json"
"fmt"
"github.com/httpreserve/httpreserve"
"os"
"strings"

"github.com/httpreserve/httpreserve"
)

var csvHeader = []string{"id", "filename", "link", "response code", "response text", "title",
Expand Down
17 changes: 17 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion linkstat.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package main
import (
"flag"
"fmt"
"github.com/httpreserve/httpreserve"
"log"
"os"
"time"

"github.com/httpreserve/httpreserve"
)

var (
Expand Down
1 change: 1 addition & 0 deletions linkstathandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"crypto/md5"
"fmt"

"github.com/httpreserve/httpreserve"
"github.com/httpreserve/wayback"
)
Expand Down

0 comments on commit 0141543

Please sign in to comment.