Skip to content
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
10 changes: 7 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,14 @@ jobs:
- name: Download tun2socks for embedding
run: make download-tun2socks

- name: Install lint tools
run: make install-lint-tools

- name: Check formatting
run: make fmt-check

- name: Lint
uses: golangci/golangci-lint-action@v9
with:
version: v2.10.1
run: make lint

test-linux:
name: Test (Linux)
Expand Down
24 changes: 21 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ BINARY_UNIX=$(BINARY_NAME)_unix
TUN2SOCKS_VERSION=v2.5.2
TUN2SOCKS_BIN_DIR=internal/sandbox/bin

.PHONY: all build build-ci build-linux test test-ci clean deps install-lint-tools setup setup-ci run fmt lint release release-minor release-beta download-tun2socks help
.PHONY: all build build-ci build-linux test test-ci clean deps install-lint-tools install-hooks setup setup-ci run fmt fmt-check lint release release-minor release-beta download-tun2socks help

all: build

Expand Down Expand Up @@ -77,7 +77,13 @@ install-lint-tools:
go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@latest
@echo "Linting tools installed"

setup: deps install-lint-tools
install-hooks:
@echo "Installing git hooks..."
cp scripts/pre-commit .git/hooks/pre-commit
chmod +x .git/hooks/pre-commit
@echo "Git hooks installed"

setup: deps install-lint-tools install-hooks
@echo "Development environment ready"

setup-ci: deps install-lint-tools
Expand All @@ -90,6 +96,16 @@ fmt:
@echo "Formatting code..."
gofumpt -w .

fmt-check:
@echo "Checking formatting..."
@UNFORMATTED=$$(gofumpt -l .); \
if [ -n "$$UNFORMATTED" ]; then \
echo "The following files need formatting (run 'make fmt'):"; \
echo "$$UNFORMATTED"; \
exit 1; \
fi
@echo "All files are formatted."

lint:
@echo "Linting code..."
golangci-lint run --allow-parallel-runners
Expand Down Expand Up @@ -119,10 +135,12 @@ help:
@echo " clean - Clean build artifacts"
@echo " deps - Download dependencies"
@echo " install-lint-tools - Install linting tools"
@echo " setup - Setup development environment"
@echo " install-hooks - Install git pre-commit hook"
@echo " setup - Setup development environment (includes hooks)"
@echo " setup-ci - Setup CI environment"
@echo " run - Build and run"
@echo " fmt - Format code"
@echo " fmt-check - Check formatting (non-destructive, for CI)"
@echo " lint - Lint code"
@echo " release - Create patch release (v0.0.X)"
@echo " release-minor - Create minor release (v0.X.0)"
Expand Down
2 changes: 1 addition & 1 deletion cmd/greywall/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -1096,7 +1096,7 @@ profiles, first save a copy with --learning or copy the output of "profiles show
}
switch strings.ToLower(strings.TrimSpace(choice)) {
case "d", "discard":
if writeErr := os.WriteFile(profilePath, originalData, 0o600); writeErr != nil {
if writeErr := os.WriteFile(profilePath, originalData, 0o600); writeErr != nil { //nolint:gosec // user-specified profile path - intentional
return fmt.Errorf("failed to restore original profile: %w", writeErr)
}
fmt.Println("Changes discarded.")
Expand Down
32 changes: 32 additions & 0 deletions scripts/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env bash
# Pre-commit hook: run gofumpt and golangci-lint before every commit.
# Install with: make install-hooks

set -euo pipefail

export PATH="$PATH:$(go env GOPATH)/bin"

echo "[greywall] Running pre-commit checks..."

if ! command -v gofumpt &>/dev/null; then
echo "[greywall] gofumpt not found — run 'make setup' to install linting tools"
exit 1
fi

if ! command -v golangci-lint &>/dev/null; then
echo "[greywall] golangci-lint not found — run 'make setup' to install linting tools"
exit 1
fi

echo "[greywall] Checking formatting..."
UNFORMATTED=$(gofumpt -l .)
if [ -n "$UNFORMATTED" ]; then
echo "[greywall] The following files need formatting (run 'make fmt'):"
echo "$UNFORMATTED"
exit 1
fi

echo "[greywall] Running linter..."
golangci-lint run --allow-parallel-runners

echo "[greywall] All checks passed."
Loading