Skip to content

Commit

Permalink
refactor: migrate to protobuf-go-lite
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Stewart <[email protected]>
  • Loading branch information
paralin committed Apr 22, 2024
1 parent 01830e5 commit 9641434
Show file tree
Hide file tree
Showing 242 changed files with 31,948 additions and 50,180 deletions.
5 changes: 0 additions & 5 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ jobs:
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support

steps:
- name: Harden Runner
uses: step-security/harden-runner@63c24ba6bd7ba022e95695ff85de572c04a18142 # v2.7.0
with:
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs

- name: Checkout repository
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

Expand Down
5 changes: 0 additions & 5 deletions .github/workflows/dependency-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@ jobs:
dependency-review:
runs-on: ubuntu-latest
steps:
- name: Harden Runner
uses: step-security/harden-runner@63c24ba6bd7ba022e95695ff85de572c04a18142 # v2.7.0
with:
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs

- name: 'Checkout Repository'
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: 'Dependency Review'
Expand Down
6 changes: 0 additions & 6 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@ jobs:
matrix:
go: ['1.22']
steps:
- name: Harden Runner
uses: step-security/harden-runner@63c24ba6bd7ba022e95695ff85de572c04a18142 # v2.7.0
with:
disable-sudo: true
egress-policy: audit

- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
Expand Down
14 changes: 10 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,33 +20,39 @@ jobs:
node: [21.x]
timeout-minutes: 10
steps:
- uses: step-security/harden-runner@63c24ba6bd7ba022e95695ff85de572c04a18142 # v2.7.0
with:
disable-sudo: true
egress-policy: audit
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

- name: Setup Go ${{ matrix.go }}
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
with:
go-version: ${{ matrix.go }}

- name: Setup Node.JS ${{ matrix.node }}
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
with:
node-version: ${{ matrix.node }}
cache: 'yarn'

- name: Test Go
run: make test

- name: Yarn install
run: yarn install

- name: Build Javascript
run: yarn run build

- name: Test Js
run: yarn test:js

- name: Lint Javascript
run: yarn run lint:js

- name: Lint Go
run: yarn run lint:go

- name: Depcheck JS
run: yarn run deps

- name: Check goreleaser build
run: make hack/bin/goreleaser
150 changes: 43 additions & 107 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
# https://github.com/aperturerobotics/protobuf-project
# https://github.com/aperturerobotics/template

SHELL:=bash
PROTOWRAP=hack/bin/protowrap
PROTOC_GEN_GO=hack/bin/protoc-gen-go
PROTOC_GEN_GO=hack/bin/protoc-gen-go-lite
PROTOC_GEN_STARPC=hack/bin/protoc-gen-go-starpc
PROTOC_GEN_VTPROTO=hack/bin/protoc-gen-go-vtproto
PROTOC_GEN_GO_DRPC=hack/bin/protoc-gen-go-drpc
GOIMPORTS=hack/bin/goimports
GOFUMPT=hack/bin/gofumpt
GOLANGCI_LINT=hack/bin/golangci-lint
GO_MOD_OUTDATED=hack/bin/go-mod-outdated
WASMSERVE=hack/bin/wasmserve
GORELEASER=hack/bin/goreleaser
GOLIST=go list -f "{{ .Dir }}" -m

export GO111MODULE=on
undefine GOOS
undefine GOARCH
undefine GOOS

all:

Expand All @@ -26,26 +22,8 @@ vendor:
$(PROTOC_GEN_GO):
cd ./hack; \
go build -v \
-o ./bin/protoc-gen-go \
google.golang.org/protobuf/cmd/protoc-gen-go

$(PROTOC_GEN_VTPROTO):
cd ./hack; \
go build -v \
-o ./bin/protoc-gen-go-vtproto \
github.com/planetscale/vtprotobuf/cmd/protoc-gen-go-vtproto

$(PROTOC_GEN_GO_DRPC):
cd ./hack; \
go build -v \
-o ./bin/protoc-gen-go-drpc \
storj.io/drpc/cmd/protoc-gen-go-drpc

$(PROTOC_GEN_STARPC):
cd ./hack; \
go build -v \
-o ./bin/protoc-gen-go-starpc \
github.com/aperturerobotics/starpc/cmd/protoc-gen-go-starpc
-o ./bin/protoc-gen-go-lite \
github.com/aperturerobotics/protobuf-go-lite/cmd/protoc-gen-go-lite

$(GOIMPORTS):
cd ./hack; \
Expand Down Expand Up @@ -77,87 +55,53 @@ $(GO_MOD_OUTDATED):
-o ./bin/go-mod-outdated \
github.com/psampaz/go-mod-outdated

$(WASMSERVE):
cd ./hack; \
go build -v \
-o ./bin/wasmserve \
github.com/hajimehoshi/wasmserve

$(GORELEASER):
$(PROTOC_GEN_STARPC):
cd ./hack; \
go build -v \
-o ./bin/goreleaser \
github.com/goreleaser/goreleaser

.PHONY: gengo
gengo: $(GOIMPORTS) $(PROTOWRAP) $(PROTOC_GEN_GO) $(PROTOC_GEN_VTPROTO) $(PROTOC_GEN_GO_DRPC) $(PROTOC_GEN_STARPC)
shopt -s globstar; \
set -eo pipefail; \
export PROJECT=$$(go list -m); \
export PATH=$$(pwd)/hack/bin:$${PATH}; \
mkdir -p $$(pwd)/vendor/$$(dirname $${PROJECT}); \
rm $$(pwd)/vendor/$${PROJECT} || true; \
ln -s $$(pwd) $$(pwd)/vendor/$${PROJECT} ; \
$(PROTOWRAP) \
-I $$(pwd)/vendor \
--go_out=$$(pwd)/vendor \
--go-vtproto_out=$$(pwd)/vendor \
--go-vtproto_opt=features=marshal+unmarshal+size+equal+clone \
--go-drpc_out=$$(pwd)/vendor \
--go-drpc_opt=json=false \
--go-drpc_opt=protolib=github.com/golang/protobuf/proto \
--go-drpc_opt=protolib=github.com/planetscale/vtprotobuf/codec/drpc \
--go-starpc_out=$$(pwd)/vendor \
--proto_path $$(pwd)/vendor \
--print_structure \
--only_specified_files \
$$(\
git \
ls-files "*.proto" |\
xargs printf -- \
"$$(pwd)/vendor/$${PROJECT}/%s "); \
rm $$(pwd)/vendor/$${PROJECT} || true
$(GOIMPORTS) -w ./
-o ./bin/protoc-gen-go-starpc \
github.com/aperturerobotics/starpc/cmd/protoc-gen-go-starpc

node_modules:
yarn install

.PHONY: gents
gents: $(PROTOWRAP) node_modules
.PHONY: genproto
genproto: vendor node_modules $(GOIMPORTS) $(PROTOWRAP) $(PROTOC_GEN_GO) $(PROTOC_GEN_STARPC)
shopt -s globstar; \
set -eo pipefail; \
export PROJECT=$$(go list -m); \
export PATH=$$(pwd)/hack/bin:$${PATH}; \
mkdir -p $$(pwd)/vendor/$$(dirname $${PROJECT}); \
export OUT=$$(pwd)/vendor; \
mkdir -p $${OUT}/$$(dirname $${PROJECT}); \
rm $$(pwd)/vendor/$${PROJECT} || true; \
ln -s $$(pwd) $$(pwd)/vendor/$${PROJECT} ; \
$(PROTOWRAP) \
-I $$(pwd)/vendor \
--plugin=./node_modules/.bin/protoc-gen-ts_proto \
--ts_proto_out=$$(pwd)/vendor \
--ts_proto_opt=esModuleInterop=true \
--ts_proto_opt=fileSuffix=.pb \
--ts_proto_opt=importSuffix=.js \
--ts_proto_opt=forceLong=long \
--ts_proto_opt=oneof=unions \
--ts_proto_opt=outputServices=default,outputServices=generic-definitions \
--ts_proto_opt=useAbortSignal=true \
--ts_proto_opt=useAsyncIterable=true \
--ts_proto_opt=useDate=true \
--proto_path $$(pwd)/vendor \
--print_structure \
--only_specified_files \
$$(\
git \
ls-files "*.proto" |\
xargs printf -- \
"$$(pwd)/vendor/$${PROJECT}/%s "); \
protogen() { \
$(PROTOWRAP) \
-I $${OUT} \
--plugin=./node_modules/.bin/protoc-gen-es \
--plugin=./node_modules/.bin/protoc-gen-es-starpc \
--go-lite_out=$${OUT} \
--go-lite_opt=features=marshal+unmarshal+size+equal+json+clone \
--go-starpc_out=$${OUT} \
--es_out=$${OUT} \
--es_opt target=ts \
--es_opt ts_nocheck=false \
--es-starpc_out=$${OUT} \
--es-starpc_opt target=ts \
--es-starpc_opt ts_nocheck=false \
--proto_path $${OUT} \
--print_structure \
--only_specified_files \
$$(\
git \
ls-files "$$1" |\
xargs printf -- \
"$$(pwd)/vendor/$${PROJECT}/%s "); \
}; \
protogen "./*.proto"; \
rm $$(pwd)/vendor/$${PROJECT} || true
$(GOIMPORTS) -w ./
npm run format:js

.PHONY: genproto
genproto: gengo gents

.PHONY: gen
gen: genproto

Expand All @@ -171,25 +115,17 @@ list: $(GO_MOD_OUTDATED)

.PHONY: lint
lint: $(GOLANGCI_LINT)
$(GOLANGCI_LINT) run --timeout=10m
$(GOLANGCI_LINT) run

.PHONY: fix
fix: $(GOLANGCI_LINT)
$(GOLANGCI_LINT) run --fix --timeout=10m

.PHONY: format
format: $(GOFUMPT) $(GOIMPORTS)
$(GOIMPORTS) -w ./
$(GOFUMPT) -w ./
$(GOLANGCI_LINT) run --fix

.PHONY: test
test:
go test -v ./...

.PHONY: release
release: $(GORELEASER)
$(GORELEASER) release --clean

.PHONY: serve-example
serve-example: $(WASMSERVE)
$(WASMSERVE) -http ":8090" ./examples/websocket-browser-link/browser
.PHONY: format
format: $(GOFUMPT) $(GOIMPORTS)
$(GOIMPORTS) -w ./
$(GOFUMPT) -w ./
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,9 @@ Bifrost is designed around the following core concepts:
- **PubSub**: at-least-once delivery of messages to named topics.
- **Signaling**: exchanging messages between peers via a relay server.

Integrates with networking, pubsub, and RPC libraries like [libp2p], [drpc],
[starpc], [nats], and [pion webrtc].
Integrates with networking, pubsub, and RPC libraries like [libp2p], [starpc],
[nats], and [pion webrtc].

[drpc]: https://github.com/storj/drpc
[libp2p]: https://libp2p.io/
[nats]: https://nats.io
[starpc]: https://github.com/aperturerobotics/starpc
Expand Down
4 changes: 2 additions & 2 deletions cli/client_accept.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ func (a *ClientArgs) RunAccept(*cli.Context) error {
return err
}

drpc := stream_api.NewAcceptStreamClientRPC(client)
rpcClient := stream_api.NewAcceptStreamClientRPC(client)
return stream_api_rpc.AttachRPCToStream(
drpc,
rpcClient,
rwc.NewReadWriteCloser(os.Stdin, os.Stdout),
nil,
)
Expand Down
4 changes: 2 additions & 2 deletions cli/client_dial.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ func (a *ClientArgs) RunDial(*cli.Context) error {
return err
}

drpc := stream_api.NewDialStreamClientRPC(client)
rpcClient := stream_api.NewDialStreamClientRPC(client)
return stream_api_rpc.AttachRPCToStream(
drpc,
rpcClient,
rwc.NewReadWriteCloser(os.Stdin, os.Stdout),
nil,
)
Expand Down
8 changes: 4 additions & 4 deletions cli/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,26 @@ import (
"github.com/aperturerobotics/bifrost/peer"
peer_ssh "github.com/aperturerobotics/bifrost/peer/ssh"
"github.com/aperturerobotics/bifrost/util/confparse"
"github.com/aperturerobotics/timestamp"
"github.com/aperturerobotics/protobuf-go-lite/types/known/timestamppb"
"github.com/pkg/errors"
"github.com/urfave/cli/v2"
"golang.org/x/crypto/ssh"
)

// RunTimestamp runs the timestamp util command.
func (a *UtilArgs) RunTimestamp(_ *cli.Context) error {
var ts *timestamp.Timestamp
var ts *timestamppb.Timestamp
if a.Timestamp != "" {
var err error
ts, err = confparse.ParseTimestamp(a.Timestamp)
if err != nil {
return err
}
} else {
ts = timestamp.Now()
ts = timestamppb.Now()
}

formatted := ts.ToRFC3339() + "\n"
formatted := ts.AsRFC3339() + "\n"
return writeIfNotExists(a.OutPath, bytes.NewReader([]byte(formatted)))
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/bifrost/cmd_daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func init() {
},
&cli.StringFlag{
Name: "api-listen",
Usage: "if set, will listen on address for API drpc connections, ex :5110",
Usage: "if set, will listen on address for API srpc connections, ex :5110",
EnvVars: []string{"BIFROST_API_LISTEN"},
Destination: &daemonFlags.APIListen,
},
Expand Down
Loading

0 comments on commit 9641434

Please sign in to comment.