Skip to content
Closed
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
2 changes: 2 additions & 0 deletions .github/workflows/security.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ jobs:
run: |
go mod verify
go list -m -json all > dependency-inventory.json
- name: Run Go vulnerability scan
run: go tool -modfile=tools.mod govulncheck ./...
- uses: actions/upload-artifact@v7
with:
name: dependency-inventory
Expand Down
17 changes: 16 additions & 1 deletion .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,22 @@ jobs:
with:
go-version-file: go.mod
cache: true
- run: go run ./cmd/xtask validate
- name: Cache golangci-lint binary
id: cache-golangci
uses: actions/cache@v6
with:
path: ~/go/bin/golangci-lint
key: golangci-lint-${{ runner.os }}-${{ runner.arch }}-v2.15.0
- name: Install pinned golangci-lint
if: steps.cache-golangci.outputs.cache-hit != 'true'
run: |
mkdir -p "$HOME/go/bin"
curl -sSfL https://golangci-lint.run/install.sh | sh -s -- -b "$HOME/go/bin" v2.15.0
"$HOME/go/bin/golangci-lint" --version
- name: Run native Go validation suite
run: |
export PATH="$HOME/go/bin:$PATH"
go run ./cmd/xtask validate

release:
name: Tag & Release
Expand Down
105 changes: 105 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
version: "2"
run:
timeout: 5m
modules-download-mode: readonly
formatters:
enable: []
linters:
default: none
enable:
- bodyclose
- contextcheck
- errcheck
- errorlint
- exhaustive
- forbidigo
- gocritic
- gosec
- govet
- nilerr
- prealloc
- revive
- staticcheck
- unconvert
- wrapcheck
settings:
errcheck:
check-type-assertions: true
check-blank: true
errorlint:
errorf: true
asserts: true
comparison: true
exhaustive:
default-signifies-exhaustive: true
govet:
enable-all: true
disable:
- fieldalignment
staticcheck:
checks:
- "all"
forbidigo:
forbid:
- pattern: '^fmt\.Print.*$'
msg: "use structured logging instead of fmt.Print*"
- pattern: '^time\.Sleep$'
msg: "avoid unconditional time.Sleep; use context-aware timers"
- pattern: '^context\.(Background|TODO)$'
msg: "propagate caller context instead of creating root context in domain code"
revive:
rules:
- name: exported
- name: context-as-argument
- name: context-keys-type
- name: dot-imports
- name: error-return
- name: error-strings
- name: error-naming
- name: increment-decrement
- name: var-declaration
- name: range
- name: receiver-naming
- name: time-naming
- name: unexported-return
- name: indent-error-flow
- name: errorf
- name: empty-block
- name: superfluous-else
- name: unreachable-code
- name: redefines-builtin-id
gocritic:
enabled-tags:
- diagnostic
- performance
- style
disabled-checks:
- hugeParam
wrapcheck:
ignore-sigs:
- .Errorf(
- errors.New(
- errors.Unwrap(
- errors.Join(
exclusions:
generated: strict
rules:
# cmd/xtask is the native automation runner and may print gate output.
- path: ^cmd/xtask/
linters:
- forbidigo
- wrapcheck
# Local dev/CI CLI only: repo files, pinned subprocesses and generated artifacts are trusted.
- path: ^cmd/xtask/
text: "G(122|204|301|304|306|702|703):"
linters:
- gosec
# Standard Go tests may use context roots and unexported test helpers.
- path: _test\.go$
linters:
- forbidigo
- gosec
- wrapcheck
issues:
max-issues-per-linter: 0
max-same-issues: 0
6 changes: 4 additions & 2 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@ Technical operating rules for this Go repository template.

## 2. Toolchain & Validation

- Compiler & static safety: preserve every AST rule in `cmd/xtask/lint.go` and `-race` test execution in `cmd/xtask/main.go` (forbid `"unsafe"`, dot imports, `init()`, `panic`, `fmt.Print*`, `os.Exit`, `log.Fatal*`, `time.Sleep`, `context.Background`/`TODO`, `interface{}`, pointer-to-interface, embedded `sync.Mutex`, unchecked type assertions, mutable package globals, files over 500 lines, boolean parameters in exported functions, and bare `//nolint`).
- Semantic analysis: `golangci-lint v2.15.0` runs 15 type-checked linters from the immutable `.golangci.yml` with `formatters: enable: []`; it is installed at a pinned version in CI and must not be replaced with `@latest`. `govulncheck v1.10.0` runs from the isolated `tools.mod` in `security.yml` only.
- Enable hooks locally with `git config core.hooksPath .githooks` and run `go run ./cmd/xtask validate` (`TOTAL PASS=8 FAIL=0`) before opening or updating any pull request.
- Do not run `gofmt` or automated code formatters in hooks, CI, or pre-commit steps.
- Do not run `gofmt`, `goimports`, `gofumpt`, or any automated code formatter in hooks, CI, or pre-commit steps.

## 3. Code Layout & Architecture

- Organize domain logic under `internal/modules/<domain>/` as a six-file layered modular layout (`entity.go`, `dto.go`, `repository.go`, `service.go`, `controller.go`, `module.go`).
- Enforce unidirectional imports: `Controller` calls `Service` and `dto` (never `Repository`); `entity` and `dto` must not reference `service`, `repository`, or `controller`.
- Keep every source and documentation file at or below **500 lines**.
- Document all exported declarations in `internal/` with Go doc comments and keep every source and documentation file at or below **500 lines**.

## 4. Commit, Dependency & License Policy

Expand Down
5 changes: 5 additions & 0 deletions ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ The included `internal/modules/math/` module demonstrates this pattern with an a
3. Add unit, integration, and layer boundary tests in `internal/core/core_test.go`.
4. Run `go run ./cmd/xtask validate` to verify all eight gates pass.

## Strict AST Policy & Tripwires

- **AST Guardrails**: `cmd/xtask/lint.go` enforces `go vet ./...` plus native `go/ast` checks across `internal/` forbidding `"unsafe"`, dot imports, `init()`, `panic()`, `fmt.Print*`, `os.Exit`, `log.Fatal*`, `time.Sleep`, `context.Background`/`TODO`, `interface{}`, mutable package vars, boolean flag parameters, and unjustified `//nolint`, while requiring doc comments on exported symbols.
- **Race & Policy Lock**: `cmd/xtask/main.go` runs tests with `-race`, and `internal/core/core_test.go` fails if any AST rule, `-race` flag, or 3-day cooldown setting is removed.

## Monorepo Variant Architecture

When scaling into multiple Go services and shared libraries, adopt the `go.work` multi-module workspace layout:
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Production-ready pure-Go repository template featuring a native `cmd/xtask` vali
## Key Features

- **100% Native Go Tooling**: Powered by `go run ./cmd/xtask` and standard library checks with zero Node.js or external script dependencies.
- **Strict AST & Concurrency Safety Lock**: Runs `go vet ./...`, pure-Go `go/ast` guardrails (forbidding `"unsafe"`, `init()`, `panic()`, `fmt.Print*`, `os.Exit`, `log.Fatal*`, `interface{}`, mutable globals, and boolean flag parameters), and `-race` tests; `internal/core/core_test.go` locks all policy rules against weakening.
- **Layered Modular Architecture**: Reference domain module (`internal/modules/math/`) separating `entity`, `dto`, `repository`, `service`, `controller`, and `module` layers with automated boundary tests.
- **Eight Standardized Validation Gates**: `lint`, `typecheck`, `unit tests`, `integration and architecture tests`, `cooldown`, `hygiene`, `notices`, and `release`.
- **Supply-Chain Hardening**: 3-day dependency cooldown policy (`.github/dependabot.yml` `default-days: 3`, no `replace` or `@latest` directives), CodeQL static analysis, and automated SBOM/dependency inventory artifacts.
Expand Down Expand Up @@ -51,10 +52,10 @@ go run ./cmd/xtask release --check # Verify VERSION matches CHANGELOG.md

| Gate | Implementation | Purpose |
| :--- | :--- | :--- |
| `lint` | `go vet ./...` + AST checks | Static lints and forbidden calls |
| `lint` | `go vet ./...` + AST checks | Static `go/ast` safety rules, doc comments, `"unsafe"` ban |
| `typecheck` | `go build ./...` | Full package compilation check |
| `unit tests` | `go test -run TestUnit ./internal/...` | Fast unit test execution |
| `integration and architecture tests` | `go test -run 'TestIntegration\|TestArchitecture' ./internal/...` | HTTP endpoints and layer boundaries |
| `unit tests` | `go test -race -run TestUnit ./internal/...` | Race-checked unit test execution |
| `integration and architecture tests` | `go test -race -run 'TestIntegration\|TestArchitecture' ./internal/...` | Endpoints, layer boundaries, policy lock |
| `cooldown` | `cmd/xtask/main.go` + `.github/dependabot.yml` | 3-day dependency cooldown enforcement |
| `hygiene` | `cmd/xtask/hygiene.go` | Anti-leak, required docs, path checks |
| `notices` | `cmd/xtask/notices.go` | License inventory parity |
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.0
0.1.0
19 changes: 12 additions & 7 deletions cmd/xtask/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@ var (
)

func runCommitCheck(root string, args []string) error {
mode := ""
if len(args) >= 2 {
mode = args[0]
}
var msg string
if len(args) >= 2 && args[0] == "--file" {
switch mode {
case "--file":
if err := checkGitIdentity(root); err != nil {
return err
}
Expand All @@ -24,7 +29,7 @@ func runCommitCheck(root string, args []string) error {
return err
}
msg = string(raw)
} else if len(args) >= 2 && args[0] == "--range" {
case "--range":
cmd := exec.Command("git", "log", "--format=%B%x00", args[1])
cmd.Dir = root
out, err := cmd.Output()
Expand All @@ -41,10 +46,10 @@ func runCommitCheck(root string, args []string) error {
}
}
return nil
} else {
default:
raw, err := os.ReadFile(".git/COMMIT_EDITMSG")
if err != nil {
return fmt.Errorf("missing --file or --range: %v", err)
return fmt.Errorf("missing --file or --range: %w", err)
}
msg = string(raw)
}
Expand Down Expand Up @@ -91,7 +96,7 @@ func validateCommitText(raw string) error {
return fmt.Errorf("blank lines between bullets are forbidden")
}
if strings.Contains(strings.ToLower(line), "co-authored-by:") {
return fmt.Errorf("Co-authored-by trailers are forbidden")
return fmt.Errorf("co-authored-by trailers are forbidden")
}
bm := bulletRe.FindStringSubmatch(line)
if bm == nil {
Expand All @@ -117,7 +122,7 @@ func checkGitIdentity(root string) error {
nameCmd.Dir = root
nameOut, err := nameCmd.Output()
if err != nil {
return fmt.Errorf("git user.name not configured: %v", err)
return fmt.Errorf("git user.name not configured: %w", err)
}
if strings.TrimSpace(string(nameOut)) == "" {
return fmt.Errorf("git user.name must be configured")
Expand All @@ -126,7 +131,7 @@ func checkGitIdentity(root string) error {
emailCmd.Dir = root
emailOut, err := emailCmd.Output()
if err != nil {
return fmt.Errorf("git user.email not configured: %v", err)
return fmt.Errorf("git user.email not configured: %w", err)
}
if !strings.HasSuffix(strings.TrimSpace(string(emailOut)), noreplySuffix) {
return fmt.Errorf("git user.email must end with %q", noreplySuffix)
Expand Down
Loading
Loading