Skip to content

Commit 5ff59ee

Browse files
chore: Big refactoring
1 parent e6a09d9 commit 5ff59ee

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+5528
-161
lines changed

.github/workflows/ci.yml

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
name: ci
2+
3+
on:
4+
push:
5+
branches: [ main, master ]
6+
pull_request:
7+
branches: [ "**" ]
8+
9+
concurrency:
10+
group: ci-${{ github.ref }}
11+
cancel-in-progress: true
12+
13+
jobs:
14+
build-test:
15+
name: Lint, unit tests, vuln scan
16+
runs-on: ubuntu-latest
17+
timeout-minutes: 20
18+
env:
19+
# Ensure we build with the repo’s Go; helpful if using toolchain directives.
20+
GOTOOLCHAIN: local
21+
# Default: run vuln scan in CI (internet is available here).
22+
SKIP_VULN: "0"
23+
steps:
24+
- name: Checkout
25+
uses: actions/checkout@v4
26+
27+
- name: Setup Go
28+
uses: actions/setup-go@v5
29+
with:
30+
go-version: "1.24.x"
31+
cache: false # we’ll use explicit caches below
32+
33+
- name: Cache Go modules
34+
uses: actions/cache@v4
35+
with:
36+
path: |
37+
~/go/pkg/mod
38+
~/.cache/go-build
39+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
40+
restore-keys: |
41+
${{ runner.os }}-go-
42+
43+
- name: Print Go env
44+
run: |
45+
go version
46+
go env
47+
48+
- name: Install golangci-lint (built with local toolchain)
49+
run: |
50+
GOBIN=$HOME/.local/bin GOTOOLCHAIN=local go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.61.0
51+
echo "$HOME/.local/bin" >> $GITHUB_PATH
52+
golangci-lint version
53+
54+
- name: Make check (fmt, tidy, lint, unit tests, govulncheck)
55+
run: make check
56+
57+
- name: Upload coverage (if produced)
58+
if: always()
59+
uses: actions/upload-artifact@v4
60+
with:
61+
name: coverage.out
62+
path: coverage.out
63+
if-no-files-found: ignore
64+
65+
e2e:
66+
name: E2E (WebSocket + metrics)
67+
runs-on: ubuntu-latest
68+
timeout-minutes: 20
69+
needs: build-test
70+
env:
71+
GOTOOLCHAIN: local
72+
steps:
73+
- name: Checkout
74+
uses: actions/checkout@v4
75+
76+
- name: Setup Go
77+
uses: actions/setup-go@v5
78+
with:
79+
go-version: "1.24.x"
80+
cache: false
81+
82+
- name: Cache Go modules
83+
uses: actions/cache@v4
84+
with:
85+
path: |
86+
~/go/pkg/mod
87+
~/.cache/go-build
88+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
89+
restore-keys: |
90+
${{ runner.os }}-go-
91+
92+
- name: Install golangci-lint (for make lint, if used)
93+
run: |
94+
GOBIN=$HOME/.local/bin GOTOOLCHAIN=local go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.61.0
95+
echo "$HOME/.local/bin" >> $GITHUB_PATH
96+
97+
- name: Run E2E tests
98+
run: make test-e2e
99+
100+
- name: Upload test logs on failure
101+
if: failure()
102+
uses: actions/upload-artifact@v4
103+
with:
104+
name: e2e-logs
105+
path: |
106+
**/*.test
107+
**/*.log
108+
**/testdata/**
109+
if-no-files-found: ignore

.golangci.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
run:
2+
timeout: 5m
3+
tests: true
4+
5+
linters:
6+
enable:
7+
- govet
8+
- staticcheck
9+
- ineffassign
10+
- errcheck
11+
- gosimple
12+
- typecheck
13+
- unused
14+
- gocritic
15+
- bodyclose
16+
- unparam
17+
- prealloc
18+
- misspell
19+
- stylecheck
20+
- copyloopvar # replaces exportloopref for Go 1.22+
21+
- gosec
22+
- bidichk
23+
- forbidigo
24+
25+
issues:
26+
exclude-dirs:
27+
- vendor
28+
exclude-rules:
29+
- linters: [stylecheck]
30+
text: "ST1000"
31+
- linters: [gosec]
32+
text: "G115"

Dockerfile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# ---- build stage ----
2+
FROM golang:1.24 AS build
3+
WORKDIR /src
4+
COPY go.mod go.sum ./
5+
RUN --mount=type=cache,target=/go/pkg/mod go mod download
6+
COPY . .
7+
RUN --mount=type=cache,target=/root/.cache/go-build \
8+
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 \
9+
go build -ldflags="-s -w -X 'main.version=${VERSION:-dev}' -X 'main.commit=${COMMIT:-local}'" \
10+
-o /out/noisytransferd ./noisytransferd
11+
12+
# ---- runtime (distroless) ----
13+
FROM gcr.io/distroless/static:nonroot
14+
WORKDIR /app
15+
COPY --from=build /out/noisytransferd /app/noisytransferd
16+
USER nonroot:nonroot
17+
EXPOSE 1234
18+
ENTRYPOINT ["/app/noisytransferd"]

Makefile

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# -------- Variables --------
2+
GO ?= go
3+
GOTOOLCHAIN_ENV ?= GOTOOLCHAIN=local
4+
GOBIN ?= $(HOME)/.local/bin
5+
GOLANGCI_VER ?= v1.61.0
6+
GOLANGCI := $(GOBIN)/golangci-lint
7+
8+
PKGS := ./...
9+
E2E_PKGS := ./e2e_test/...
10+
11+
# Allow skipping vuln scan locally if network/DNS blocks vuln.go.dev
12+
SKIP_VULN ?= 0
13+
14+
# -------- Tools --------
15+
$(GOLANGCI):
16+
@echo "Installing golangci-lint $(GOLANGCI_VER) with local toolchain..."
17+
@mkdir -p $(GOBIN)
18+
$(GOTOOLCHAIN_ENV) GOBIN=$(GOBIN) $(GO) install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_VER)
19+
20+
# -------- Lint / Format / Tidy --------
21+
.PHONY: lint fmt tidy
22+
lint: $(GOLANGCI)
23+
$(GOLANGCI) version
24+
$(GOLANGCI) run
25+
26+
fmt:
27+
$(GOTOOLCHAIN_ENV) $(GO) run mvdan.cc/gofumpt@latest -l -w .
28+
29+
tidy:
30+
$(GO) mod tidy
31+
32+
# -------- Tests --------
33+
.PHONY: test test-e2e cover
34+
test:
35+
$(GO) test -race $(PKGS)
36+
37+
test-e2e:
38+
$(GO) test -race -tags=e2e $(E2E_PKGS)
39+
40+
cover:
41+
$(GO) test -race -coverprofile=coverage.out $(PKGS)
42+
$(GO) tool cover -func=coverage.out | tail -n 1
43+
44+
# -------- Vulnerability scan (skippable locally) --------
45+
.PHONY: vuln
46+
vuln:
47+
ifeq ($(SKIP_VULN),1)
48+
@echo "==> skipping govulncheck (SKIP_VULN=1)"
49+
else
50+
@echo "==> vulnerability scan (govulncheck)"
51+
@$(GOTOOLCHAIN_ENV) $(GO) run golang.org/x/vuln/cmd/govulncheck@latest $(PKGS) || \
52+
( echo "ERROR: govulncheck failed (likely network). Re-run with SKIP_VULN=1 to skip locally."; exit 1 )
53+
endif
54+
55+
# -------- Build --------
56+
.PHONY: build
57+
build:
58+
# Inject version/commit at link time; used by metrics.SetBuildInfo
59+
VERSION=$$(git describe --tags --abbrev=0 --dirty 2>/dev/null || echo dev); \
60+
COMMIT=$$(git rev-parse --short HEAD); \
61+
$(GO) build -ldflags="-X 'main.version=$$VERSION' -X 'main.commit=$$COMMIT'" -o noisytransferd ./noisytransferd
62+
63+
# -------- Composite checks --------
64+
.PHONY: check check-offline ci
65+
check: fmt tidy lint test vuln
66+
@echo "✓ all checks passed"
67+
68+
# Offline/local-friendly check (skips vuln)
69+
check-offline:
70+
@$(MAKE) check SKIP_VULN=1
71+
72+
# CI entry-point (explicit so CI configs can call one target)
73+
ci: check test-e2e
74+
@echo "✓ CI stages passed"
75+

0 commit comments

Comments
 (0)