tenseleyflow/shithub / bbb237b

Browse files

Add build infra: Makefile, golangci-lint, air, GitHub Actions CI

Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
bbb237bc72ed3fd20231b0c1e89025262cdd9e8e
Parents
a641ad1
Tree
706ebf7

4 changed files

StatusFile+-
A .air.toml 18 0
A .github/workflows/ci.yml 31 0
A .golangci.yml 37 0
A Makefile 76 0
.air.tomladded
@@ -0,0 +1,18 @@
1
+root = "."
2
+tmp_dir = "tmp"
3
+
4
+[build]
5
+  cmd = "go build -o ./tmp/shithubd ./cmd/shithubd"
6
+  bin = "./tmp/shithubd"
7
+  full_bin = "./tmp/shithubd web"
8
+  include_ext = ["go", "html", "tmpl", "css", "js"]
9
+  exclude_dir = ["bin", "tmp", "vendor", ".git", ".docs", ".refs", "node_modules", "internal/web/static/primer"]
10
+  delay = 200
11
+  send_interrupt = true
12
+  kill_delay = "1s"
13
+
14
+[log]
15
+  time = true
16
+
17
+[misc]
18
+  clean_on_exit = true
.github/workflows/ci.ymladded
@@ -0,0 +1,31 @@
1
+name: ci
2
+on:
3
+  push:
4
+    branches: [trunk, main]
5
+  pull_request:
6
+
7
+permissions:
8
+  contents: read
9
+
10
+jobs:
11
+  ci:
12
+    runs-on: ubuntu-latest
13
+    steps:
14
+      - uses: actions/checkout@v4
15
+
16
+      - uses: actions/setup-go@v5
17
+        with:
18
+          go-version: "1.22"
19
+          cache: true
20
+
21
+      - name: Install golangci-lint
22
+        uses: golangci/golangci-lint-action@v6
23
+        with:
24
+          version: latest
25
+          args: --timeout=5m
26
+
27
+      - name: Test
28
+        run: go test -trimpath ./...
29
+
30
+      - name: Build
31
+        run: go build -trimpath ./cmd/shithubd
.golangci.ymladded
@@ -0,0 +1,37 @@
1
+version: "2"
2
+run:
3
+  timeout: 5m
4
+  tests: true
5
+linters:
6
+  default: none
7
+  enable:
8
+    - errcheck
9
+    - govet
10
+    - ineffassign
11
+    - staticcheck
12
+    - unused
13
+    - gocritic
14
+    - gosec
15
+    - revive
16
+  settings:
17
+    gosec:
18
+      excludes:
19
+        - G304 # file inclusion via variable; we audit these manually
20
+    revive:
21
+      rules:
22
+        - name: var-naming
23
+        - name: package-comments
24
+          disabled: true
25
+        - name: exported
26
+          disabled: true
27
+formatters:
28
+  enable:
29
+    - gofumpt
30
+    - goimports
31
+  settings:
32
+    goimports:
33
+      local-prefixes:
34
+        - github.com/tenseleyFlow/shithub
35
+issues:
36
+  max-issues-per-linter: 0
37
+  max-same-issues: 0
Makefileadded
@@ -0,0 +1,76 @@
1
+# shithub Makefile
2
+# Targets mirror what CI runs. The Makefile is the source of truth.
3
+
4
+.DEFAULT_GOAL := help
5
+.PHONY: help dev build test test-race lint fmt tidy clean ci assets install-tools version
6
+
7
+# Build metadata embedded into the binary via -ldflags.
8
+VERSION := $(shell git describe --tags --always --dirty 2>/dev/null || echo dev)
9
+COMMIT  := $(shell git rev-parse --short HEAD 2>/dev/null || echo unknown)
10
+BUILT   := $(shell date -u +%Y-%m-%dT%H:%M:%SZ)
11
+LDFLAGS := -X github.com/tenseleyFlow/shithub/internal/version.Version=$(VERSION) \
12
+           -X github.com/tenseleyFlow/shithub/internal/version.Commit=$(COMMIT) \
13
+           -X github.com/tenseleyFlow/shithub/internal/version.BuiltAt=$(BUILT)
14
+
15
+GOFLAGS := -trimpath
16
+BIN     := bin/shithubd
17
+
18
+# Tools installed via 'go install' live in GOBIN (or GOPATH/bin). Reference
19
+# them by absolute path so make recipes don't depend on PATH ordering.
20
+GOBIN := $(shell go env GOBIN)
21
+ifeq ($(GOBIN),)
22
+GOBIN := $(shell go env GOPATH)/bin
23
+endif
24
+GOFUMPT   := $(GOBIN)/gofumpt
25
+GOIMPORTS := $(GOBIN)/goimports
26
+AIR       := $(GOBIN)/air
27
+
28
+help: ## Show this help.
29
+	@awk 'BEGIN {FS = ":.*##"} /^[a-zA-Z_-]+:.*##/ {printf "  %-20s %s\n", $$1, $$2}' $(MAKEFILE_LIST)
30
+
31
+dev: ## Run the web server with hot reload via air.
32
+	@$(AIR)
33
+
34
+build: ## Build the shithubd binary into bin/.
35
+	@mkdir -p bin
36
+	go build $(GOFLAGS) -ldflags "$(LDFLAGS)" -o $(BIN) ./cmd/shithubd
37
+
38
+test: ## Run unit tests.
39
+	go test $(GOFLAGS) ./...
40
+
41
+test-race: ## Run unit tests with the race detector.
42
+	go test $(GOFLAGS) -race ./...
43
+
44
+lint: ## Run golangci-lint.
45
+	golangci-lint run
46
+
47
+fmt: ## Format the codebase with gofumpt and goimports.
48
+	$(GOFUMPT) -l -w cmd internal pkg
49
+	$(GOIMPORTS) -local github.com/tenseleyFlow/shithub -w cmd internal pkg
50
+
51
+tidy: ## Tidy go.mod / go.sum.
52
+	go mod tidy
53
+
54
+clean: ## Remove build artifacts.
55
+	rm -rf bin tmp coverage.out
56
+
57
+assets: ## Copy Primer CSS into internal/web/static/ for embedding.
58
+	@mkdir -p internal/web/static/primer
59
+	@if [ -d .refs/primer-css/dist ]; then \
60
+		cp -R .refs/primer-css/dist/* internal/web/static/primer/; \
61
+	else \
62
+		echo "warn: .refs/primer-css/dist not found; run 'git clone https://github.com/primer/css .refs/primer-css' first"; \
63
+	fi
64
+
65
+ci: lint test build ## Full CI pipeline (matches .github/workflows/ci.yml).
66
+	@echo "ci: ok"
67
+
68
+install-tools: ## Install development tools via 'go install'.
69
+	go install mvdan.cc/gofumpt@latest
70
+	go install golang.org/x/tools/cmd/goimports@latest
71
+	go install github.com/air-verse/air@latest
72
+
73
+version: ## Print version info that would be embedded into the binary.
74
+	@echo "Version: $(VERSION)"
75
+	@echo "Commit:  $(COMMIT)"
76
+	@echo "Built:   $(BUILT)"