Skip to content

Commit ed1368f

Browse files
authored
Add CI Workflow and Makefile target for Protocol Buffers (#173)
Reference: #172 Also includes the Makefile `lint` and `test` targets along with associated README updates while in the neighborhood.
1 parent 8070ef2 commit ed1368f

File tree

12 files changed

+112
-36
lines changed

12 files changed

+112
-36
lines changed

.github/workflows/ci-protobuf.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Continuous integration handling for Protocol Buffers
2+
name: ci-protobuf
3+
4+
on:
5+
pull_request:
6+
paths:
7+
- .github/workflows/ci-protobuf.yml
8+
- .go-version
9+
- go.mod
10+
- go.sum
11+
- 'tfprotov5/internal/tfplugin5/*'
12+
- 'tfprotov6/internal/tfplugin6/*'
13+
14+
permissions:
15+
contents: read
16+
17+
jobs:
18+
protoc:
19+
runs-on: ubuntu-latest
20+
steps:
21+
- uses: actions/checkout@v3
22+
- id: go-version
23+
# Reference: https://github.com/actions/setup-go/issues/23
24+
run: echo "::set-output name=version::$(cat ./.go-version)"
25+
- uses: actions/setup-go@v2
26+
with:
27+
go-version: ${{ steps.go-version.outputs.version }}
28+
- uses: arduino/setup-protoc@v1
29+
with:
30+
# The version string is embedded in protoc generated files, so it is
31+
# pinned here to prevent unexpected differences. Follow the
32+
# https://github.com/protocolbuffers/protobuf repository for protoc
33+
# release updates.
34+
version: '3.19.4'
35+
- run: go mod download
36+
- run: go install google.golang.org/protobuf/cmd/protoc-gen-go
37+
- run: go install google.golang.org/grpc/cmd/protoc-gen-go-grpc
38+
- run: make protoc
39+
- name: git diff
40+
run: |
41+
git diff --compact-summary --exit-code || \
42+
(echo; echo "Unexpected difference in directories after code generation. Run 'protoc' command and commit."; exit 1)

Makefile

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
default: test
2+
3+
lint:
4+
golangci-lint run ./...
5+
6+
# Protocol Buffers compilation is done outside of 'go generate' handling since
7+
# the 'protoc' tool is not installable via 'go install'.
8+
protoc:
9+
@cd tfprotov5/internal/tfplugin5 && \
10+
protoc \
11+
--proto_path=. \
12+
--go_out=. \
13+
--go_opt=paths=source_relative \
14+
--go-grpc_out=. \
15+
--go-grpc_opt=paths=source_relative \
16+
tfplugin5.proto
17+
@cd tfprotov6/internal/tfplugin6 && \
18+
protoc \
19+
--proto_path=. \
20+
--go_out=. \
21+
--go_opt=paths=source_relative \
22+
--go-grpc_out=. \
23+
--go-grpc_opt=paths=source_relative \
24+
tfplugin6.proto
25+
26+
test:
27+
go test ./...
28+
29+
.PHONY: default lint protoc test

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,30 @@ out of scope and should live in a separate module.
157157

158158
Please see [`.github/CONTRIBUTING.md`](https://github.com/hashicorp/terraform-plugin-go/blob/main/.github/CONTRIBUTING.md).
159159

160+
### Unit Testing
161+
162+
Run `go test ./...` or `make test` after any changes.
163+
164+
### Linting
165+
166+
Ensure the following tooling is installed:
167+
168+
- [`golangci-lint](https://golangci-lint.run/): Aggregate Go linting tool.
169+
170+
Run `golangci-lint run ./...` or `make lint` after any changes.
171+
172+
### Protocol Updates
173+
174+
Ensure the following tooling is installed:
175+
176+
- [`protoc`](https://github.com/protocolbuffers/protobuf): Protocol Buffers compiler.
177+
- [`protoc-gen-go`](https://pkg.go.dev/google.golang.org/protobuf/cmd/protoc-gen-go): Go plugin for Protocol Buffers compiler. e.g. `go install google.golang.org/protobuf/cmd/protoc-gen-go`
178+
- [`protoc-gen-go-grpc`](https://pkg.go.dev/google.golang.org/grpc/cmd/protoc-gen-go-grpc): Go gRPC plugin for Protocol Buffers compiler. e.g. `go install google.golang.org/grpc/cmd/protoc-gen-go-grpc`
179+
180+
The Protocol Buffers definitions can be found in `tfprotov5/internal/tfplugin5` and `tfprotov6/internal/tfplugin6`.
181+
182+
Run `make protoc` to recompile the Protocol Buffers files after any changes.
183+
160184
## License
161185

162186
This module is licensed under the [Mozilla Public License v2.0](https://github.com/hashicorp/terraform-plugin-go/blob/main/LICENSE).

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ require (
1313
github.com/nsf/jsondiff v0.0.0-20200515183724-f29ed568f4ce
1414
github.com/vmihailenco/msgpack/v4 v4.3.12
1515
google.golang.org/grpc v1.45.0
16+
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.2.0
1617
google.golang.org/protobuf v1.27.1
1718
)

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTp
176176
google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU=
177177
google.golang.org/grpc v1.45.0 h1:NEpgUqV3Z+ZjkqMsxMg11IaDrXY4RY6CQukSGK0uI1M=
178178
google.golang.org/grpc v1.45.0/go.mod h1:lN7owxKUQEqMfSyQikvvk5tf/6zMPsrK+ONuO11+0rQ=
179+
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.2.0 h1:TLkBREm4nIsEcexnCjgQd5GQWaHcqMzwQV0TX9pq8S0=
180+
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.2.0/go.mod h1:DNq5QpG7LJqD2AamLZ7zvKE0DEpVl2BSEVjFycAAjRY=
179181
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
180182
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
181183
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=

tfprotov5/internal/tfplugin5/generate.sh

Lines changed: 0 additions & 16 deletions
This file was deleted.

tfprotov5/internal/tfplugin5/tfplugin5.pb.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tfprotov6/internal/tfplugin6/generate.sh

Lines changed: 0 additions & 16 deletions
This file was deleted.

tfprotov6/internal/tfplugin6/tfplugin6.pb.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)