Skip to content

Commit

Permalink
chore: add go-arch-lint (#2421)
Browse files Browse the repository at this point in the history
This lints our internal software architecture.

It currently does not pass, but I'm adding this to guide the refactoring
changes. Current output:

```
module: github.com/TBD54566975/ftl
linters:
   On | Base: component imports # always on
  Off | Advanced: vendor imports # switch 'allow.depOnAnyVendor = false' (or delete) to on
   On | Advanced: method calls and dependency injections # switch 'allow.deepScan = true' (or delete) to on

Component controller shouldn't depend on github.com/TBD54566975/ftl/go-runtime/encoding in /Users/alec/dev/ftl/backend/controller/admin/admin.go:13
Component controller shouldn't depend on github.com/TBD54566975/ftl/go-runtime/encoding in /Users/alec/dev/ftl/backend/controller/ingress/handler_test.go:20
Component controller shouldn't depend on github.com/TBD54566975/ftl/go-runtime/encoding in /Users/alec/dev/ftl/backend/controller/ingress/request_test.go:15
Component controller shouldn't depend on github.com/TBD54566975/ftl/go-runtime/ftl in /Users/alec/dev/ftl/backend/controller/ingress/request_test.go:16
Component controller shouldn't depend on github.com/TBD54566975/ftl/backend/runner in /Users/alec/dev/ftl/backend/controller/scaling/localscaling/local_scaling.go:16
Component encoding shouldn't depend on github.com/TBD54566975/ftl/go-runtime/ftl/reflection in /Users/alec/dev/ftl/go-runtime/encoding/encoding.go:16
Component encoding shouldn't depend on github.com/TBD54566975/ftl/go-runtime/encoding in /Users/alec/dev/ftl/go-runtime/encoding/encoding_test.go:10
Component encoding shouldn't depend on github.com/TBD54566975/ftl/go-runtime/ftl in /Users/alec/dev/ftl/go-runtime/encoding/encoding_test.go:11
Component encoding shouldn't depend on github.com/TBD54566975/ftl/go-runtime/ftl/reflection in /Users/alec/dev/ftl/go-runtime/encoding/encoding_test.go:12
Component internal shouldn't depend on github.com/TBD54566975/ftl/go-runtime/compile in /Users/alec/dev/ftl/internal/buildengine/build_go.go:8
Component internal shouldn't depend on github.com/TBD54566975/ftl/go-runtime/compile in /Users/alec/dev/ftl/internal/buildengine/stubs.go:10
Component internal shouldn't depend on github.com/TBD54566975/ftl/go-runtime/compile in /Users/alec/dev/ftl/internal/buildengine/watch.go:11
Component internal shouldn't depend on github.com/TBD54566975/ftl/backend/controller/leader in /Users/alec/dev/ftl/internal/configuration/asm.go:13
Component internal shouldn't depend on github.com/TBD54566975/ftl/backend/controller/leases in /Users/alec/dev/ftl/internal/configuration/asm.go:14
Component internal shouldn't depend on github.com/TBD54566975/ftl/backend/controller/leader in /Users/alec/dev/ftl/internal/configuration/asm_follower.go:13
Component internal shouldn't depend on github.com/TBD54566975/ftl/backend/controller/leases in /Users/alec/dev/ftl/internal/configuration/asm_test.go:16
Component internal shouldn't depend on github.com/TBD54566975/ftl/backend/controller/sql/sqltest in /Users/alec/dev/ftl/internal/configuration/dal/dal_test.go:9
Component internal shouldn't depend on github.com/TBD54566975/ftl/backend/controller/sql/sqltypes in /Users/alec/dev/ftl/internal/configuration/sql/models.go:14
Component internal shouldn't depend on github.com/TBD54566975/ftl/backend/controller/leases in /Users/alec/dev/ftl/internal/configuration/sql/models.go:13
Component internal shouldn't depend on github.com/TBD54566975/ftl/backend/controller/sql in /Users/alec/dev/ftl/internal/configuration/sql/types.go:3
Component internal shouldn't depend on github.com/TBD54566975/ftl/go-runtime/encoding in /Users/alec/dev/ftl/internal/modulecontext/from_secrets.go:8
```
  • Loading branch information
alecthomas authored and safeer committed Aug 19, 2024
1 parent 7cb9636 commit de4f729
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,13 @@ jobs:
submodules: true
- uses: cashapp/activate-hermit@v1
- run: cd docs && zola build
arch-lint:
name: Lint Architecture
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: cashapp/activate-hermit@v1
- run: go-arch-lint check || true
integration-shard:
name: Shard Integration Tests
if: github.event_name != 'pull_request' || github.event.action == 'enqueued' || contains( github.event.pull_request.labels.*.name, 'run-all')
Expand Down
1 change: 1 addition & 0 deletions .go-arch-lint-schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"$schema":"http://json-schema.org/draft-07/schema#","additionalProperties":false,"definitions":{"commonComponents":{"description":"All project packages can import this components, useful for utils packages like 'models'","items":{"title":"component name","type":"string"},"title":"List of components names","type":"array"},"commonVendors":{"description":"All project packages can import this vendor libs","items":{"title":"vendor name","type":"string"},"title":"List of vendor names","type":"array"},"component":{"additionalProperties":false,"properties":{"in":{"anyOf":[{"$ref":"#/definitions/componentIn"},{"items":{"$ref":"#/definitions/componentIn"},"type":"array"}]}},"required":["in"],"type":"object"},"componentIn":{"description":"relative directory name, support glob masking (src/\\*/engine/\\*\\*)","examples":["src/services","src/services/*/repo","src/*/services/**"],"title":"relative path to project package","type":"string"},"components":{"additionalProperties":{"$ref":"#/definitions/component"},"title":"List of components","type":"object"},"dependencies":{"additionalProperties":{"$ref":"#/definitions/dependencyRule"},"title":"Dependency rules between spec and package imports","type":"object"},"dependencyRule":{"additionalProperties":false,"properties":{"anyProjectDeps":{"description":"all component code can import any other project code, useful for DI/main component","title":"Allow import any project package?","type":"boolean"},"anyVendorDeps":{"description":"all component code can import any vendor code","title":"Allow import any vendor package?","type":"boolean"},"canUse":{"items":{"title":"vendor name","type":"string"},"title":"List of allowed vendors to import","type":"array"},"deepScan":{"description":"you can turn on/off deepScan only for this component","title":"Override deepscan global flag for this component","type":"boolean"},"mayDependOn":{"items":{"title":"component name","type":"string"},"title":"List of allowed components to import","type":"array"}},"type":"object"},"exclude":{"items":{"title":"list of directories (relative path) for exclude from analyse","type":"string"},"title":"Excluded folders from analyse","type":"array"},"excludeFiles":{"description":"package will by excluded in all package files is matched by provided regexp's","items":{"title":"regular expression rules for file names, will exclude this files and it's packages from analyse","type":"string","x-intellij-language-injection":"regexp"},"title":"Excluded files from analyse matched by regexp","type":"array"},"settings":{"additionalProperties":false,"properties":{"deepScan":{"title":"will use new advanced AST linter (this default=true from v3+)","type":"boolean"},"depOnAnyVendor":{"title":"allow import any vendor code to any project file","type":"boolean"}},"title":"Global Scheme options","type":"object"},"vendor":{"additionalProperties":false,"properties":{"in":{"anyOf":[{"$ref":"#/definitions/vendorIn"},{"items":{"$ref":"#/definitions/vendorIn"},"type":"array"}]}},"required":["in"],"type":"object"},"vendorIn":{"description":"one or more import path of vendor libs, support glob masking (src/\\*/engine/\\*\\*)","examples":["golang.org/x/mod/modfile","example.com/*/libs/**",["gopkg.in/yaml.v2","github.com/mailru/easyjson"]],"title":"full import path to vendor","type":"string"},"vendors":{"additionalProperties":{"$ref":"#/definitions/vendor"},"title":"List of vendor libs","type":"object"},"version":{"description":"Defines arch file syntax and file validation rules","maximum":3,"minimum":3,"title":"Scheme Version","type":"integer"},"workdir":{"description":"Linter will prepend all path's in project with this relative path prefix (relative directory for analyse)","title":"Working directory","type":"string"}},"description":"Arch file scheme version 3","id":"https://github.com/fe3dback/go-arch-lint/v3","properties":{"allow":{"$ref":"#/definitions/settings"},"commonComponents":{"$ref":"#/definitions/commonComponents"},"commonVendors":{"$ref":"#/definitions/commonVendors"},"components":{"$ref":"#/definitions/components"},"deps":{"$ref":"#/definitions/dependencies"},"exclude":{"$ref":"#/definitions/exclude"},"excludeFiles":{"$ref":"#/definitions/excludeFiles"},"vendors":{"$ref":"#/definitions/vendors"},"version":{"$ref":"#/definitions/version"},"workdir":{"$ref":"#/definitions/workdir"}},"required":["version","components","deps"],"title":"Go Arch Lint V3","type":"object"}
103 changes: 103 additions & 0 deletions .go-arch-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# yaml-language-server: $schema=./.go-arch-lint-schema.json
version: 3
workdir: .
components:
controller: { in: backend/controller/** }
ftl-controller-cmd: { in: cmd/ftl-controller/** }
common: { in: common/** }
internal: { in: internal/** }
dal: { in: backend/dal/** }
protos: { in: backend/protos/** }
schema: { in: backend/schema/** }
ftl: { in: . }
ftl-cmd: { in: cmd/ftl/** }
go-runtime: { in: go-runtime/** }
jvm-runtime: { in: jvm-runtime/** }
rust-runtime: { in: rust-runtime/** }
runner: { in: backend/runner/** }
ftl-runner-cmd: { in: cmd/ftl-runner/** }
frontend: { in: frontend/** }
ftl-gen-lsp-cmd: { in: cmd/ftl-gen-lsp/** }
ftl-initdb-cmd: { in: cmd/ftl-initdb/** }
ftl-schema-cmd: { in: cmd/ftl-schema/** }
lint-commit-or-rollback-cmd: { in: cmd/lint-commit-or-rollback/** }
databasetesting: { in: backend/controller/sql/databasetesting/** }
sql: { in: backend/controller/sql/** }
# TODO: Nothing outside of the go-runtime package should depend on reflection.
reflection: { in: go-runtime/ftl/reflection/** }
# TODO: Nothing outside of the go-runtime package should depend on reflection.
encoding: { in: go-runtime/encoding/** }
leases: { in: backend/controller/leases/** }

excludeFiles:
- ".*/testdata/.*"
- ".*/\\.ftl/.*"
- "/examples/.*"
- "/jvm-runtime/.*"

allow:
depOnAnyVendor: true

commonComponents:
- common
- internal
- dal
- protos
- schema
- ftl

deps:
controller:
mayDependOn:
- controller
- frontend
runner:
mayDependOn:
- common
- internal
- runner
go-runtime:
mayDependOn:
- common
- internal
- go-runtime
ftl-cmd:
mayDependOn:
- controller
- common
- internal
- dal
- protos
- schema
- ftl
- jvm-runtime # TODO: When we decouple runtimes, this should be removed.
- go-runtime # TODO: When we decouple runtimes, this should be removed.
ftl-controller-cmd:
mayDependOn:
- controller
- common
- internal
- dal
- protos
- schema
- ftl
ftl-runner-cmd:
mayDependOn:
- common
- internal
- runner
ftl-initdb-cmd:
mayDependOn:
- databasetesting
databasetesting:
mayDependOn:
- common
- internal
- dal
- sql
sql:
mayDependOn:
- common
- internal
- sql
- leases
1 change: 1 addition & 0 deletions bin/.go-arch-lint-1.11.4.pkg
1 change: 1 addition & 0 deletions bin/go-arch-lint

0 comments on commit de4f729

Please sign in to comment.