Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'model' plugin. #161

Merged
merged 2 commits into from
Jun 15, 2024
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
23 changes: 2 additions & 21 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,10 @@ jobs:
runs-on: ubuntu-latest
steps:

- name: Collect Workflow Telemetry
uses: runforesight/foresight-workflow-kit-action@v1
if: success() || failure()

- name: Set up Go 1.21
- name: Set up Go 1.22
uses: actions/[email protected]
with:
go-version: '1.21'
go-version: '1.22'
check-latest: true
id: go

Expand All @@ -31,18 +27,3 @@ jobs:

- name: Build
run: make ci
env:
GOA_BRANCH: ${{ steps.extract_branch.outputs.branch }}

- name: Compute code coverage
run: go test -v -json -coverprofile=coverage.out ./...> ./test-report.json || true

- name: Analyze Test and/or Coverage Results
uses: runforesight/foresight-test-kit-action@v1
if: success() || failure()
with:
test_format: JSON
test_framework: GOLANG
test_path: "./test-report.json"
coverage_format: GOLANG
coverage_path: ./coverage.out
32 changes: 0 additions & 32 deletions .github/workflows/stale.yml

This file was deleted.

31 changes: 17 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ PLUGINS=\
docs \
goakit \
i18n \
model \
otel \
types \
zaplogger \
zerologger

PROTOC_VERSION=22.2
UNZIP=unzip
PROTOC_VERSION=27.1
ifeq ($(GOOS),linux)
PROTOC=protoc-$(PROTOC_VERSION)-linux-x86_64
PROTOC_EXEC=$(PROTOC)/bin/protoc
endif
ifeq ($(GOOS),darwin)
PROTOC=protoc-$(PROTOC_VERSION)-osx-x86_64
PROTOC=protoc-$(PROTOC_VERSION)-osx-universal_binary
PROTOC_EXEC=$(PROTOC)/bin/protoc
endif
ifeq ($(GOOS),windows)
Expand All @@ -47,17 +47,20 @@ ci: depend all

depend:
@echo INSTALLING DEPENDENCIES...
@go mod download
@for package in $(DEPEND); do go install $$package; done
@go mod tidy -compat=1.19
@echo INSTALLING PROTOC...
@mkdir $(PROTOC)
@cd $(PROTOC); \
curl -O -L https://github.com/protocolbuffers/protobuf/releases/download/v$(PROTOC_VERSION)/$(PROTOC).zip; \
$(UNZIP) $(PROTOC).zip
@cp $(PROTOC_EXEC) $(GOPATH)/bin && \
rm -rf $(PROTOC) && \
echo "`protoc --version`"
@for package in $(DEPEND); do \
go install $$package; \
done
@go mod tidy
@if [ "`protoc --version`" != "libprotoc ${PROTOC_VERSION}" ]; then \
echo INSTALLING PROTOC...; \
mkdir -p $(PROTOC); \
cd $(PROTOC) && \
curl -O -L https://github.com/protocolbuffers/protobuf/releases/download/v$(PROTOC_VERSION)/$(PROTOC).zip && \
sudo unzip -o ${PROTOC}.zip -d /usr/local bin/protoc && \
sudo unzip -o ${PROTOC}.zip -d /usr/local 'include/*' && \
cd .. && rm -rf $(PROTOC); \
echo "`protoc --version`"; \
fi

check-goa:
ifdef GOA
Expand Down
18 changes: 10 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,30 +1,32 @@
module goa.design/plugins/v3

go 1.21
go 1.22.0

toolchain go1.22.2

require (
github.com/go-kit/kit v0.13.0
github.com/go-kit/log v0.2.1
github.com/gorilla/websocket v1.5.2
github.com/gorilla/websocket v1.5.3
github.com/stretchr/testify v1.9.0
go.uber.org/zap v1.27.0
goa.design/goa/v3 v3.16.2
goa.design/model v1.9.8
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dimfeld/httppath v0.0.0-20170720192232-ee938bf73598 // indirect
github.com/go-chi/chi/v5 v5.0.12 // indirect
github.com/go-logfmt/logfmt v0.5.1 // indirect
github.com/go-logfmt/logfmt v0.6.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/manveru/faker v0.0.0-20171103152722-9fbc68a78c4d // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/sergi/go-diff v1.3.1 // indirect
go.uber.org/multierr v1.10.0 // indirect
golang.org/x/mod v0.17.0 // indirect
golang.org/x/net v0.25.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/mod v0.18.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/text v0.15.0 // indirect
golang.org/x/tools v0.21.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/tools v0.22.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
28 changes: 14 additions & 14 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ github.com/go-kit/kit v0.13.0 h1:OoneCcHKHQ03LfBpoQCUfCluwd2Vt3ohz+kvbJneZAU=
github.com/go-kit/kit v0.13.0/go.mod h1:phqEHMMUbyrCFCTgH48JueqrM3md2HcAZ8N3XE4FKDg=
github.com/go-kit/log v0.2.1 h1:MRVx0/zhvdseW+Gza6N9rVzU/IVzaeE1SFI4raAhmBU=
github.com/go-kit/log v0.2.1/go.mod h1:NwTd00d/i8cPZ3xOwwiv2PO5MOcx78fFErGNcVmBjv0=
github.com/go-logfmt/logfmt v0.5.1 h1:otpy5pqBCBZ1ng9RQ0dPu4PN7ba75Y/aA+UpowDyNVA=
github.com/go-logfmt/logfmt v0.5.1/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs=
github.com/go-logfmt/logfmt v0.6.0 h1:wGYYu3uicYdqXVgoYbvnkrPVXkuLM1p1ifugDMEdRi4=
github.com/go-logfmt/logfmt v0.6.0/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs=
github.com/go-openapi/jsonpointer v0.20.2 h1:mQc3nmndL8ZBzStEo3JYF8wzmeWffDH4VbXz58sAx6Q=
github.com/go-openapi/jsonpointer v0.20.2/go.mod h1:bHen+N0u1KEO3YlmqOjTT9Adn1RfD91Ar825/PuiRVs=
github.com/go-openapi/swag v0.22.8 h1:/9RjDSQ0vbFR+NyjGMkFTsA1IA0fmhKSThmfGZjicbw=
github.com/go-openapi/swag v0.22.8/go.mod h1:6QT22icPLEqAM/z/TChgb4WAveCHF92+2gF0CNjHpPI=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gorilla/websocket v1.5.2 h1:qoW6V1GT3aZxybsbC6oLnailWnB+qTMVwMreOso9XUw=
github.com/gorilla/websocket v1.5.2/go.mod h1:0n9H61RBAcf5/38py2MCYbxzPIY9rOkpvvMT24Rqs30=
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/invopop/yaml v0.2.0 h1:7zky/qH+O0DwAyoobXUqvVBwgBFRxKoQ/3FjcVpjTMY=
github.com/invopop/yaml v0.2.0/go.mod h1:2XuRLgs/ouIrW3XNzuNj7J3Nvu/Dig5MXvbCEdiBN3Q=
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
Expand Down Expand Up @@ -51,22 +51,22 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
go.uber.org/multierr v1.10.0 h1:S0h4aNzvfcFsC3dRF1jLoaov7oRaKqRGC/pUEJ2yvPQ=
go.uber.org/multierr v1.10.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
goa.design/goa/v3 v3.16.2 h1:EwsYmtyhx4bmKjQ/+150nF26DIB5NjgYZyJq6Cg2jxA=
goa.design/goa/v3 v3.16.2/go.mod h1:YAY4TIUGlQH0Rj9AWtAyPktH3WLGWRaGxi3P19RvGXU=
golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA=
golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac=
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
goa.design/model v1.9.8 h1:SGf+q+hYO1rh/Jvq7T0ZbfBcANzi3Lc3RHKWBDZCWCE=
goa.design/model v1.9.8/go.mod h1:RqPSTbZV49gD3+IBsT9/zf+EPxt4zuDPuT/6r857H3w=
golang.org/x/mod v0.18.0 h1:5+9lSbEzPSdWkH32vYPBwEpX8KwDbM52Ud9xBUvNlb0=
golang.org/x/mod v0.18.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk=
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/tools v0.21.0 h1:qc0xYgIbsSDt9EyWz05J5wfa7LOVW0YTLOXrqdLAWIw=
golang.org/x/tools v0.21.0/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=
golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=
golang.org/x/tools v0.22.0 h1:gqSGLZqv+AI9lIQzniJ0nZDRG5GBPsSi+DRNHWNz6yA=
golang.org/x/tools v0.22.0/go.mod h1:aCwcsjqvq7Yqt6TNyX7QMU2enbQ/Gt0bo6krSeEri+c=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
9 changes: 9 additions & 0 deletions model/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#! /usr/bin/make
#
# Makefile for the Goa Model plugin

# include common Makefile content for plugins
GOPATH=$(shell go env GOPATH)
include ../plugins.mk

gen:
78 changes: 78 additions & 0 deletions model/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Model Plugin

The `model` plugin is a [Goa](https://github.com/goadesign/goa/tree/v3) plugin
that validates a [Model](https://github.com/goadesign/model) diagram DSL against
a Goa design. The plugin generates errors if there are services present in the
Goa design with no corresponding container in the Model diagram. The plugin can
also validate that all the containers in the Model diagram have a corresponding
service in the Goa design.

## Enabling the Plugin

To enable the plugin simply import the model plugin `dsl` package in the Goa
design:

```go
import (
. "goa.design/goa/v3/dsl"
. "goa.design/plugins/v3/model/dsl"
)
```

Running `goa gen` will now execute the plugin and validate that all services
have a corresponding container in the model (unless configured otherwise, see
below).

## Usage

The plugin extends the Goa DSL as follows:

* The `Model` function sets the `model` Go package and the name of the software
system to validate against, this is the only required DSL.
* The `ModelContainerNameFormat` function sets the format used by the plugin to
map service to container names.
* The `ModelExcludedTags` function sets a list of case-insensitive tags that
exclude containers equipped with them from the validation process.
* The `ModelComplete` function enables the validation that all the containers in
the Model diagram have a corresponding service in the Goa design.

All these functions must appear inside the `API` function:

```go
var _ = API("calc", func() {
// Set the model package and the name of the software system
Model("goa.design/model/examples/basic/model", "calc")

// Set the container name format, default is "%s Service"
ModelContainerFormat("%s Service")

// Exclude containers with the "database", "external" and "thirdparty" tags (default)
ModelExcludedTags("database", "external", "thirdparty")

// Enable the validation that all the containers in the Model diagram have a
// corresponding service. Not enabled by default.
ModelComplete()
})
```

The plugin also defines the following DSL functions that must appear under a
`Service` definition:

* The `ModelContainer` function sets the name of the corresponding diagram
container. This overrides the name computed from the `ContainerNameFormat`
format.
* The `ModelNone` function disables the validation for the service.

```go
var _ = Service("add", func() {
// Set the container name
ModelContainer("Add Service")
// ...
})

var _ = Service("no diagram", func() {
// Disable the validation for this service
ModelNone()
// ...
})
```
Loading
Loading