From 58aabe4a25cfac2f2ada7959953115712fa7cc7b Mon Sep 17 00:00:00 2001 From: ross-spencer Date: Fri, 15 Nov 2024 19:04:10 +0100 Subject: [PATCH 1/5] Basic linting workflow An attempt to determine a baseline CI workflow for Golang if we include no further linters. --- .codespellignore | 0 .github/workflows/linting.yml | 38 +++++++++++++++++++++++++++++++++++ .github/workflows/tests.yml | 28 ++++++++++++++++++++++++++ .pre-commit-config.yaml | 19 ++++++++++++++++++ bolthandler.go | 7 ++++--- csvhandler.go | 3 ++- justfile | 17 ++++++++++++++++ linkstat.go | 3 ++- linkstathandler.go | 1 + 9 files changed, 111 insertions(+), 5 deletions(-) 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..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/.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/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/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 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" ) From 297fa6365a4257df26d9c7ca7483a9a9d30f9c7d Mon Sep 17 00:00:00 2001 From: ross-spencer Date: Thu, 21 Nov 2024 10:24:47 +0100 Subject: [PATCH 2/5] Add .vscode --- .vscode/settings.json | 80 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 .vscode/settings.json 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" + ] +} From 6417975613b1d68351806c21c62ea476f233ace5 Mon Sep 17 00:00:00 2001 From: ross-spencer Date: Thu, 21 Nov 2024 10:24:59 +0100 Subject: [PATCH 3/5] Update .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 4db1ece..c36adfd 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ linkstat.exe +release/* From 56d4f897e8f69c287fdff958f245ecf8d7c9acd6 Mon Sep 17 00:00:00 2001 From: ross-spencer Date: Thu, 21 Nov 2024 10:25:52 +0100 Subject: [PATCH 4/5] Update build options distil.sh has meaning across all uses without needing to be renamed. --- distil.sh | 6 +++--- justfile | 6 +++++- statbuild.sh | 17 ----------------- 3 files changed, 8 insertions(+), 21 deletions(-) delete mode 100755 statbuild.sh 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 index 1aefeac..1be0d23 100644 --- a/justfile +++ b/justfile @@ -14,4 +14,8 @@ linting: # Run pre-commit all-checks: - pre-commit run --all-files \ No newline at end of file + pre-commit run --all-files + +# Compile for all platforms +compile-all: + ./distil.sh 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 From 26b41a0b29d41dd975bd84237b13ea10267b7bba Mon Sep 17 00:00:00 2001 From: ross-spencer Date: Thu, 21 Nov 2024 10:27:09 +0100 Subject: [PATCH 5/5] Update .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index c36adfd..2b02af2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ linkstat.exe release/* +linkstat