Add workflows and fix linter errors

This commit is contained in:
Torjus Håkestad 2024-10-11 01:17:33 +02:00
parent 4f594f7412
commit 3edcb0ad1b
Signed by: torjus
SSH Key Fingerprint: SHA256:KjAds8wHfD2mBYK2H815s/+ABcSdcIHUndwHEdSxml4
9 changed files with 2085 additions and 7 deletions

19
.direnv/bin/nix-direnv-reload Executable file
View File

@ -0,0 +1,19 @@
#!/usr/bin/env bash
set -e
if [[ ! -d "/home/torjus/git/ghettoptt" ]]; then
echo "Cannot find source directory; Did you move it?"
echo "(Looking for "/home/torjus/git/ghettoptt")"
echo 'Cannot force reload with this script - use "direnv reload" manually and then try again'
exit 1
fi
# rebuild the cache forcefully
_nix_direnv_force_reload=1 direnv exec "/home/torjus/git/ghettoptt" true
# Update the mtime for .envrc.
# This will cause direnv to reload again - but without re-building.
touch "/home/torjus/git/ghettoptt/.envrc"
# Also update the timestamp of whatever profile_rc we have.
# This makes sure that we know we are up to date.
touch -r "/home/torjus/git/ghettoptt/.envrc" "/home/torjus/git/ghettoptt/.direnv"/*.rc

View File

@ -0,0 +1 @@
/nix/store/p2hby44a0qzrnd1vxcpcgfav6160rmcv-source

View File

@ -0,0 +1 @@
/nix/store/ri5q1bld0gwahdsrfs8ydcini09mx85i-source

View File

@ -0,0 +1 @@
/nix/store/4n7mpj43zcs1y74q231w94i3a3w56si2-nix-shell-env

File diff suppressed because it is too large Load Diff

20
.github/workflows/go-test-build.yaml vendored Normal file
View File

@ -0,0 +1,20 @@
name: go-test-build
on:
push:
pull_request:
jobs:
go-test-build:
runs-on: ubuntu-latest
container:
image: ghcr.io/catthehacker/ubuntu:runner-latest
strategy:
matrix:
go: [ "1.22", "1.21" ]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go }}
- run: go test -v ./...
- run: go build -o main main.go

19
.github/workflows/golangci-lint.yaml vendored Normal file
View File

@ -0,0 +1,19 @@
name: golangci-lint
on:
push:
pull_request:
jobs:
goglangci-lint:
runs-on: ubuntu-latest
container:
image: ghcr.io/catthehacker/ubuntu:runner-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v5
with:
go-version: "1.22"
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.61

15
.github/workflows/nix-check-build.yaml vendored Normal file
View File

@ -0,0 +1,15 @@
name: nix-check-build
on:
push:
pull_request:
jobs:
nix-check-build:
runs-on: ubuntu-latest
container:
image: ghcr.io/catthehacker/ubuntu:runner-latest
steps:
- uses: actions/checkout@v3
- uses: cachix/install-nix-action@v27
- run: nix flake check
- run: nix build

19
main.go
View File

@ -40,7 +40,10 @@ func main() {
panic(err)
}
defer input.Close()
input.NonBlock()
if err := input.NonBlock(); err != nil {
slog.Error("Failed to set non-blocking mode", "error", err)
os.Exit(1)
}
// Start metrics server
srvCtx, srvCancel := context.WithCancel(context.Background())
@ -54,12 +57,14 @@ func main() {
}
go func() {
<-ctx.Done()
srv.Shutdown(context.Background())
_ = srv.Shutdown(context.Background())
srvCancel()
}()
slog.Info("Starting metrics server", "addr", srv.Addr)
srv.ListenAndServe()
if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed {
slog.Warn("Failed to start metrics server", "error", err)
}
}()
// Listen for context cancellation
@ -84,7 +89,7 @@ func main() {
continue
}
slog.Error("Error reading from input device", "error", err)
mbus.StopTalking()
_ = mbus.StopTalking()
os.Exit(1)
}
if ev.Code == evdev.KEY_F24 && ev.Value == 1 {
@ -104,15 +109,15 @@ func main() {
for v := range debouncer.C {
if v {
mbus.StartTalking()
_ = mbus.StartTalking()
slog.Info("Started talking")
} else {
mbus.StopTalking()
_ = mbus.StopTalking()
slog.Info("Stopped talking")
}
}
mbus.StopTalking()
_ = mbus.StopTalking()
<-srvCtx.Done()
slog.Info("Exiting")
}