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..22d4c10 --- /dev/null +++ b/.github/workflows/linting.yml @@ -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 ./..." diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..d58124a --- /dev/null +++ b/.github/workflows/tests.yml @@ -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 ./..." diff --git a/.gitignore b/.gitignore index 4db1ece..2b02af2 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ linkstat.exe +release/* +linkstat 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/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..41c2987 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,80 @@ +{ + "editor.insertSpaces": true, + "editor.tabSize": 4, + "editor.rulers": [ + 79 + ], + "editor.detectIndentation": false, + "files.trimTrailingWhitespace": true, + "files.insertFinalNewline": true, + "python.linting.mypyEnabled": false, + "python.linting.flake8Enabled": true, + "python.linting.pylintEnabled": true, + "python.linting.lintOnSave": true, + "git.inputValidationSubjectLength": 50, + "git.inputValidationLength": 72, + "[git-commit]": { + "editor.rulers": [ + 50, + 72 + ] + }, + "[python]": { + "editor.rulers": [ + 72, + 79, + 120 + ], + "editor.formatOnSave": true, + "editor.defaultFormatter": "ms-python.black-formatter" + }, + "[go]": { + "editor.rulers": [ + 72, + 79 + ] + }, + "[markdown]": { + "editor.rulers": [80] + }, + "[makefile]": { + "editor.insertSpaces": false, + "editor.tabSize": 4 + }, + "files.eol": "\n", + "cSpell.words": [ + "ADAAGIX", + "ADADJED", + "ADAEUR", + "ADAFACT", + "ADAUSD", + "ADAWMT", + "AGIX", + "ALGORAND", + "apsw", + "autouse", + "cafile", + "Cardano", + "certifi", + "conlist", + "DJED", + "dotenv", + "fastapi", + "freezegun", + "kucoin", + "lastrowid", + "LENFI", + "LQADA", + "Orcfax", + "pickleable", + "pydantic", + "rowid", + "upgrader", + "utxo", + "websockets", + "WMTADA", + "WMTAGIX", + "WMTDJED", + "WMTLENFI" + ] +} diff --git a/bolthandler.go b/bolthandler.go index e8f80a4..e6c5300 100644 --- a/bolthandler.go +++ b/bolthandler.go @@ -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 diff --git a/csvhandler.go b/csvhandler.go index 8c2a2ad..1779d21 100644 --- a/csvhandler.go +++ b/csvhandler.go @@ -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", diff --git a/distil.sh b/distil.sh index 95ed1fd..0d84b54 100755 --- a/distil.sh +++ b/distil.sh @@ -1,10 +1,10 @@ - GNU nano 5.4 distil.sh #!/usr/bin/env bash set -eux MOONSHINE="linkstat" -VERSION="${MOONSHINE}-v0.0.3" DIR="release" +VERSION="${MOONSHINE}" +rm -rf "$DIR" mkdir -p "$DIR" export GOOS=windows export GOARCH=386 @@ -27,4 +27,4 @@ export GOARCH=amd64 go build mv "$MOONSHINE" "${DIR}/${VERSION}"-darwinAmd64 export GOOS= -export GOARCH= \ No newline at end of file +export GOARCH= diff --git a/justfile b/justfile new file mode 100644 index 0000000..1be0d23 --- /dev/null +++ b/justfile @@ -0,0 +1,21 @@ +# 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 + +# Compile for all platforms +compile-all: + ./distil.sh diff --git a/linkstat.go b/linkstat.go index 7de2651..a4e3b4b 100644 --- a/linkstat.go +++ b/linkstat.go @@ -3,10 +3,11 @@ package main import ( "flag" "fmt" - "github.com/httpreserve/httpreserve" "log" "os" "time" + + "github.com/httpreserve/httpreserve" ) var ( diff --git a/linkstathandler.go b/linkstathandler.go index a744039..54ae969 100644 --- a/linkstathandler.go +++ b/linkstathandler.go @@ -3,6 +3,7 @@ package main import ( "crypto/md5" "fmt" + "github.com/httpreserve/httpreserve" "github.com/httpreserve/wayback" ) diff --git a/statbuild.sh b/statbuild.sh deleted file mode 100755 index 1bee41e..0000000 --- a/statbuild.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env bash -set -eux - -STAT="linkstat" -DIR="release" -rm -rf "$DIR" -mkdir "$DIR" -env GOOS=windows GOARCH=386 go build -mv "$STAT".exe "${DIR}/${STAT}"-win386.exe -env GOOS=windows GOARCH=amd64 go build -mv "$STAT".exe "${DIR}/${STAT}"-win64.exe -env GOOS=linux GOARCH=amd64 go build -mv "$STAT" "${DIR}/${STAT}"-linux64 -env GOOS=darwin GOARCH=386 go build -mv "$STAT" "${DIR}/${STAT}"-darwin386 -env GOOS=darwin GOARCH=amd64 go build -mv "$STAT" "${DIR}/${STAT}"-darwinAmd64