Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linting workflows #3

Merged
merged 5 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 ./..."
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
linkstat.exe
release/*
linkstat
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]
80 changes: 80 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
7 changes: 4 additions & 3 deletions bolthandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
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 All @@ -16,10 +17,10 @@
var namelen = 8

// bucket constants
const linkIndex = "link index"

Check failure on line 20 in bolthandler.go

View workflow job for this annotation

GitHub Actions / run linting (ubuntu-latest, 1.23.x)

const linkIndex is unused (U1000)

Check failure on line 20 in bolthandler.go

View workflow job for this annotation

GitHub Actions / run linting (ubuntu-latest, 1.23.x)

const linkIndex is unused (U1000)

// const fnameIndex = "filename index"
const hashIndex = "hash index"

Check failure on line 23 in bolthandler.go

View workflow job for this annotation

GitHub Actions / run linting (ubuntu-latest, 1.23.x)

const hashIndex is unused (U1000)

Check failure on line 23 in bolthandler.go

View workflow job for this annotation

GitHub Actions / run linting (ubuntu-latest, 1.23.x)

const hashIndex is unused (U1000)

// location for bolt databases. Names are random at present because
// I'm unsure how they're going to be used in future so may write naming
Expand Down Expand Up @@ -81,7 +82,7 @@
// boltGetResultContainers returns the names of all top level buckets
// n.b. these functions are heavily linked to the database schema and
// could be made more generic with more effort.
func boltGetResultContainers(kb kval.Kvalboltdb) []string {

Check failure on line 85 in bolthandler.go

View workflow job for this annotation

GitHub Actions / run linting (ubuntu-latest, 1.23.x)

func boltGetResultContainers is unused (U1000)

Check failure on line 85 in bolthandler.go

View workflow job for this annotation

GitHub Actions / run linting (ubuntu-latest, 1.23.x)

func boltGetResultContainers is unused (U1000)
var buckets []string
q := "GET " + hashIndex
res, _ := kval.Query(kb, q)
Expand All @@ -94,7 +95,7 @@
// boltGetSingleRecord will return a single record for a given md5 key
// n.b. these functions are heavily linked to the database schema and
// could be made more generic with more effort.
func boltGetSingleRecord(kb kval.Kvalboltdb, md5Key string) map[string]string {

Check failure on line 98 in bolthandler.go

View workflow job for this annotation

GitHub Actions / run linting (ubuntu-latest, 1.23.x)

func boltGetSingleRecord is unused (U1000)

Check failure on line 98 in bolthandler.go

View workflow job for this annotation

GitHub Actions / run linting (ubuntu-latest, 1.23.x)

func boltGetSingleRecord is unused (U1000)
records := make(map[string]string)
q := "GET " + hashIndex + " >> " + md5Key
res, _ := kval.Query(kb, q)
Expand All @@ -108,7 +109,7 @@
// database.
// n.b. these functions are heavily linked to the database schema and
// could be made more generic with more effort.
func boltGetAllRecords(kb kval.Kvalboltdb) []map[string]string {

Check failure on line 112 in bolthandler.go

View workflow job for this annotation

GitHub Actions / run linting (ubuntu-latest, 1.23.x)

func boltGetAllRecords is unused (U1000)

Check failure on line 112 in bolthandler.go

View workflow job for this annotation

GitHub Actions / run linting (ubuntu-latest, 1.23.x)

func boltGetAllRecords is unused (U1000)
var records []map[string]string
keys := boltGetResultContainers(kb)
for _, v := range keys {
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 @@
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 All @@ -17,7 +18,7 @@
"analysis version number", "analysis version text", "stats creation time"}

func outputCSVHeader() string {
var header string

Check failure on line 21 in csvhandler.go

View workflow job for this annotation

GitHub Actions / run linting (ubuntu-latest, 1.23.x)

should merge variable declaration with assignment on next line (S1021)

Check failure on line 21 in csvhandler.go

View workflow job for this annotation

GitHub Actions / run linting (ubuntu-latest, 1.23.x)

should merge variable declaration with assignment on next line (S1021)
header = "\"" + strings.Join(csvHeader, "\",\"") + "\"" + "\n"
return header
}
Expand Down
6 changes: 3 additions & 3 deletions distil.sh
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -27,4 +27,4 @@ export GOARCH=amd64
go build
mv "$MOONSHINE" "${DIR}/${VERSION}"-darwinAmd64
export GOOS=
export GOARCH=
export GOARCH=
21 changes: 21 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -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
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
17 changes: 0 additions & 17 deletions statbuild.sh

This file was deleted.

Loading