Skip to content

Commit

Permalink
Merge pull request #48 from kzys/upgrade-proto
Browse files Browse the repository at this point in the history
  • Loading branch information
estesp authored Oct 25, 2021
2 parents b7ebc4c + 3b9c4c7 commit 7e5ee24
Show file tree
Hide file tree
Showing 13 changed files with 578 additions and 43 deletions.
93 changes: 83 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,40 @@ on:
branches: [ main ]

jobs:
test:
name: Test
runs-on: ubuntu-20.04
timeout-minutes: 5
steps:
- name: Check out code
uses: actions/checkout@v2
with:
path: src/github.com/containerd/protobuild
fetch-depth: 25

- name: Project checks
uses: containerd/project-checks@v1
with:
working-directory: src/github.com/containerd/protobuild

- name: Setup environment
shell: bash
run: |
echo "GOPATH=${{ github.workspace }}" >> $GITHUB_ENV
echo "${{ github.workspace }}/bin" >> $GITHUB_PATH
- name: Check out code
uses: actions/checkout@v2
with:
path: src/github.com/containerd/protobuild

- name: Test
working-directory: src/github.com/containerd/protobuild
run: |
go test
build:
name: Protobuild CI
v1:
name: Run with protoc-gen-go v1.3.5
runs-on: ubuntu-20.04
timeout-minutes: 5
steps:
Expand All @@ -30,12 +61,6 @@ jobs:
uses: actions/checkout@v2
with:
path: src/github.com/containerd/protobuild
fetch-depth: 25

- name: Project checks
uses: containerd/project-checks@v1
with:
working-directory: src/github.com/containerd/protobuild

- name: Build
working-directory: src/github.com/containerd/protobuild
Expand All @@ -58,7 +83,55 @@ jobs:
- name: Run protobuild to see all committed auto-generated files can be generated as is
working-directory: src/github.com/containerd/protobuild
run: |
find examples/ -name '*.pb.*' | xargs rm
rm examples/foo/*.pb.* examples/bar/*.pb.* examples/nogrpc/*.pb.*
export PATH=$(go env GOBIN):$PATH
./protobuild github.com/containerd/protobuild/examples/bar github.com/containerd/protobuild/examples/foo github.com/containerd/protobuild/examples/nogrpc
git diff --exit-code
v2:
name: Run with protoc-gen-go v1.26
runs-on: ubuntu-20.04
timeout-minutes: 5
steps:

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.16.x
id: go

- name: Setup environment
shell: bash
run: |
echo "GOPATH=${{ github.workspace }}" >> $GITHUB_ENV
echo "${{ github.workspace }}/bin" >> $GITHUB_PATH
- name: Check out code
uses: actions/checkout@v2
with:
path: src/github.com/containerd/protobuild

- name: Build
working-directory: src/github.com/containerd/protobuild
run: |
go build .
- name: Install protoc
run: |
curl -LO https://github.com/protocolbuffers/protobuf/releases/download/v3.18.1/protoc-3.18.1-linux-x86_64.zip
sudo unzip -x protoc-3.18.1-linux-x86_64.zip -d /usr/local
sudo chmod -R go+rX /usr/local/include
sudo chmod go+x /usr/local/bin/protoc
- name: Install protoc-gen-go and protoc-gen-go-grpc
run: |
go install google.golang.org/protobuf/cmd/[email protected]
go install google.golang.org/grpc/cmd/[email protected]
- name: Run protobuild to see all committed auto-generated files can be generated as is
working-directory: src/github.com/containerd/protobuild
run: |
rm examples/v2/*.pb.*
export PATH=$(go env GOBIN):$PATH
go list ./... | grep -v vendor | xargs ./protobuild
./protobuild -f v2.toml github.com/containerd/protobuild/examples/v2
git diff --exit-code
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,18 @@ protobufs. To get started with a project, you must do the following:
go list ./... | grep -v vendor | xargs protobuild
```
TODO(stevvooe): Make this better.
## Version Compatibility
Originally protoc-gen-go was supporting gRPC through its plugins mechanism.
[However gRPC support is later extracted as protoc-gen-go-gprc binary](https://github.com/protocolbuffers/protobuf-go/releases/tag/v1.20.0#user-content-v1.20-grpc-support).
To use protoc-gen-go and protoc-gen-go-grpc. Please specify `version = "2"` and
both code generators instead of `plugins` like below.
```
version = "2"
generators = ["go", "go-grpc"]
```
## Project details
Expand Down
6 changes: 0 additions & 6 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ import (
"github.com/pelletier/go-toml"
)

const configVersion = "unstable"

type config struct {
Version string
Generators []string
Expand Down Expand Up @@ -97,10 +95,6 @@ func readConfigFrom(p []byte) (config, error) {
log.Fatalln(err)
}

if c.Version != configVersion {
return config{}, fmt.Errorf("unknown file version %v; please upgrade to %v", c.Version, configVersion)
}

if c.Generator != "" {
if len(c.Generators) > 0 {
return config{}, fmt.Errorf(
Expand Down
21 changes: 21 additions & 0 deletions examples/v2/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
Copyright The containerd Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

// Package foo demonstrates a protobuf package.
//
// We include a doc.go file in here to let protobuild know to place a
// Go/Protobuf package.
package v2
165 changes: 165 additions & 0 deletions examples/v2/foo.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions examples/v2/foo.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
syntax = "proto3";

package protobuild.example.v2;

import "google/protobuf/empty.proto";
import "google/protobuf/timestamp.proto";

option go_package = "github.com/containerd/protobuild/examples/v2/;v2";

service Foo {
rpc Do(DoRequest) returns (google.protobuf.Empty);
}

message DoRequest {
google.protobuf.Timestamp timestamp = 3;
}
Loading

0 comments on commit 7e5ee24

Please sign in to comment.