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 protobuf generated code for Go #12

Merged
merged 9 commits into from
Nov 14, 2022
Merged
Show file tree
Hide file tree
Changes from 4 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
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.pb.go linguist-generated
40 changes: 40 additions & 0 deletions .github/workflows/generate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#
# Copyright 2022 The Sigstore 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.

name: Generate code

permissions:
contents: read

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
Copy link
Member

@codysoyland codysoyland Nov 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assuming we want this running on all pull requests, prior to merge, I think this needs to not have a branches key.

Suggested change
pull_request:
branches: [ main ]
pull_request:
types:
- opened
paths:
- '**.proto'

Edit: updated with types and paths

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not an Actions expert, so you might need to play with these settings a bit until it starts building this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohhh i think i can leave it blank maybe, with the paths

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the branches is for targetted against, so understood if it's meant to capture all branches.

Either new workflows aren't triggered in the pull request itself or I've done something wrong still

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, maybe it needs to be merged before it starts working. We can fix in a follow-up if not!


jobs:
generate_go:
name: Generate go code
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3

- name: Compile protobuf
run: |
make proto

- name: Ensure no files were modified as a result of the codegen
run: git update-index --refresh && git diff-index --quiet HEAD -- || git diff --exit-code
24 changes: 24 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#
# Copyright 2022 The Sigstore 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.

PROTOC_IMAGE := namely/protoc-all:1.50_0
asraa marked this conversation as resolved.
Show resolved Hide resolved

# generate Go protobuf code
proto:
@echo "Generating Protobuf files"
docker run -v ${PWD}:/defs ${PROTOC_IMAGE} -i protos -f envelope.proto -l go --go-module-prefix github.com/secure-systems-lab
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool that this works! I think the correct package path is this though:

Suggested change
docker run -v ${PWD}:/defs ${PROTOC_IMAGE} -i protos -f envelope.proto -l go --go-module-prefix github.com/secure-systems-lab
docker run -v ${PWD}:/defs ${PROTOC_IMAGE} -i protos -f envelope.proto -l go --go-module-prefix github.com/secure-systems-lab/go-securesystemslib

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This I was actually unsure about: the generated DSSE code lives here in protobuf-specs for now, and without that the imports for the other files that depend on it might get messed up. I actually think I might be able ot preserve the secure-systems-lab part, let me see.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah :| I'm not sure I can preserve the module path outside of protobuf-specs... if I do, I end up with this error:

--go_out: github.com/sigstore/protobuf-specs/gen/pb-go/dsse/envelope.pb.go: generated file does not match prefix "github.com/secure-systems-lab/go-securesystemslib/gen/pb-go"

docker run -v ${PWD}:/defs ${PROTOC_IMAGE} -i protos -f sigstore_common.proto -l go --go-module-prefix github.com/sigstore
docker run -v ${PWD}:/defs ${PROTOC_IMAGE} -i protos -f sigstore_rekor.proto -l go --go-module-prefix github.com/sigstore
docker run -v ${PWD}:/defs ${PROTOC_IMAGE} -i protos -f sigstore_bundle.proto -l go --go-module-prefix github.com/sigstore
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,15 @@
# protobuf-specs

This repository holds protobuf specifications for Sigstore messages.

## Protobuf

If you change protobuf definitions, you will need to regenerate the code by running the protocol buffer compiler on the changed `.proto` files.

You will need [Docker](https://docs.docker.com/get-docker/) installed to generate the protobuf stubs. Then run,

```
$ make proto
```

to generate the `*.pb.go` files under `gen/`.
269 changes: 269 additions & 0 deletions gen/pb-go/dsse/envelope.pb.go

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

Loading