From f1bc82d3b179a8c5a3211cd5649eb87897a1142f Mon Sep 17 00:00:00 2001 From: Vojtech Vitek Date: Mon, 17 Oct 2022 00:14:03 +0200 Subject: [PATCH] Regenerate examples in CI, error out on git diff (#115) --- .github/workflows/ci.yml | 19 +++++++++++--- Makefile | 6 +++++ _examples/golang-basics/main.go | 2 +- _examples/golang-imports/main.go | 2 +- _examples/golang-nodejs/Makefile | 4 +-- _examples/golang-nodejs/client/client.gen.mjs | 4 +-- _examples/golang-nodejs/server/server.gen.go | 25 ++++++++++++++----- _examples/hello-webrpc-ts/Makefile | 4 +-- .../hello-webrpc-ts/server/hello_api.gen.go | 25 ++++++++++++++----- .../hello-webrpc-ts/webapp/src/client.gen.ts | 12 ++++----- _examples/hello-webrpc/Makefile | 4 +-- .../hello-webrpc/server/hello_api.gen.go | 25 ++++++++++++++----- _examples/hello-webrpc/webapp/client.gen.js | 4 +-- _examples/node-ts/Makefile | 4 +-- _examples/node-ts/server/server.gen.ts | 6 ++--- _examples/node-ts/webapp/client.gen.ts | 12 ++++----- 16 files changed, 108 insertions(+), 50 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4b772810..8d65cd3b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,15 +9,28 @@ on: - "**" jobs: - build: + test: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - name: Set up Go uses: actions/setup-go@v3 with: go-version: 1.19 - - name: Test run: go test -v ./... + + examples: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Set up Go + uses: actions/setup-go@v3 + with: + go-version: 1.19 + - name: Build + run: go install ./cmd/webrpc-gen + - name: Regenerate examples + run: make generate + - name: Git diff of regenerated examples + run: git diff --color --exit-code diff --git a/Makefile b/Makefile index e024635f..8a49b853 100644 --- a/Makefile +++ b/Makefile @@ -34,6 +34,12 @@ test: generate generate: go generate ./... + @for i in _examples/*/Makefile; do \ + echo; echo $$ cd $$i \&\& make generate; \ + cd $$(dirname $$i); \ + make generate; \ + cd ../../; \ + done dep: @export GO111MODULE=on && go mod tidy diff --git a/_examples/golang-basics/main.go b/_examples/golang-basics/main.go index fa2ec9b2..df9ae81d 100644 --- a/_examples/golang-basics/main.go +++ b/_examples/golang-basics/main.go @@ -1,4 +1,4 @@ -//go:generate ../../bin/webrpc-gen -schema=example.ridl -target=go -pkg=main -server -client -out=./example.gen.go +//go:generate webrpc-gen -schema=example.ridl -target=go -pkg=main -server -client -out=./example.gen.go package main import ( diff --git a/_examples/golang-imports/main.go b/_examples/golang-imports/main.go index af794724..f096e35a 100644 --- a/_examples/golang-imports/main.go +++ b/_examples/golang-imports/main.go @@ -1,4 +1,4 @@ -//go:generate ../../bin/webrpc-gen -schema=./proto/api.ridl -target=go -pkg=main -server -client -out=./api.gen.go +//go:generate webrpc-gen -schema=./proto/api.ridl -target=go -pkg=main -server -client -out=./api.gen.go package main import ( diff --git a/_examples/golang-nodejs/Makefile b/_examples/golang-nodejs/Makefile index 06366123..db2e05f8 100644 --- a/_examples/golang-nodejs/Makefile +++ b/_examples/golang-nodejs/Makefile @@ -2,8 +2,8 @@ all: @echo "please read Makefile source or README to see available commands" generate: - ../../bin/webrpc-gen -schema=example.webrpc.json -target=go -pkg=main -server -out=./server/server.gen.go - ../../bin/webrpc-gen -schema=example.webrpc.json -target=js -client -out=./client/client.gen.mjs + webrpc-gen -schema=example.webrpc.json -target=go -pkg=main -server -out=./server/server.gen.go + webrpc-gen -schema=example.webrpc.json -target=js -client -out=./client/client.gen.mjs run-server: go run ./server diff --git a/_examples/golang-nodejs/client/client.gen.mjs b/_examples/golang-nodejs/client/client.gen.mjs index b5dd4e90..657ad8be 100644 --- a/_examples/golang-nodejs/client/client.gen.mjs +++ b/_examples/golang-nodejs/client/client.gen.mjs @@ -1,4 +1,4 @@ -// example v0.0.1 07d79ad7e0e7bc2320ac29fdd065307ce932cf47 +// example v0.0.1 33aa93c6d912046df938c7f94cef36d3a30679fa // -- // This file has been generated by https://github.com/webrpc/webrpc using gen/javascript // Do not edit by hand. Update your webrpc schema and re-generate. @@ -10,7 +10,7 @@ export const WebRPCVersion = "v1" export const WebRPCSchemaVersion = " v0.0.1" // Schema hash generated from your RIDL schema -export const WebRPCSchemaHash = "07d79ad7e0e7bc2320ac29fdd065307ce932cf47" +export const WebRPCSchemaHash = "33aa93c6d912046df938c7f94cef36d3a30679fa" // diff --git a/_examples/golang-nodejs/server/server.gen.go b/_examples/golang-nodejs/server/server.gen.go index e814679f..78886400 100644 --- a/_examples/golang-nodejs/server/server.gen.go +++ b/_examples/golang-nodejs/server/server.gen.go @@ -1,4 +1,4 @@ -// example v0.0.1 07d79ad7e0e7bc2320ac29fdd065307ce932cf47 +// example v0.0.1 33aa93c6d912046df938c7f94cef36d3a30679fa // -- // This file has been generated by https://github.com/webrpc/webrpc using gen/golang // Do not edit by hand. Update your webrpc schema and re-generate. @@ -27,7 +27,7 @@ func WebRPCSchemaVersion() string { // Schema hash generated from your RIDL schema func WebRPCSchemaHash() string { - return "07d79ad7e0e7bc2320ac29fdd065307ce932cf47" + return "33aa93c6d912046df938c7f94cef36d3a30679fa" } // @@ -335,6 +335,14 @@ func WrapError(code ErrorCode, cause error, format string, args ...interface{}) return &rpcErr{code: ErrInternal, msg: "invalid error type " + string(code), cause: cause} } +func Failf(format string, args ...interface{}) Error { + return Errorf(ErrFail, format, args...) +} + +func WrapFailf(cause error, format string, args ...interface{}) Error { + return WrapError(ErrFail, cause, format, args...) +} + func ErrorNotFound(format string, args ...interface{}) Error { return Errorf(ErrNotFound, format, args...) } @@ -354,13 +362,16 @@ func ErrorInternal(format string, args ...interface{}) Error { type ErrorCode string const ( - // Canceled indicates the operation was cancelled (typically by the caller). - ErrCanceled ErrorCode = "canceled" - // Unknown error. For example when handling errors raised by APIs that do not // return enough error information. ErrUnknown ErrorCode = "unknown" + // Fail error. General failure error type. + ErrFail ErrorCode = "fail" + + // Canceled indicates the operation was cancelled (typically by the caller). + ErrCanceled ErrorCode = "canceled" + // InvalidArgument indicates client specified an invalid argument. It // indicates arguments that are problematic regardless of the state of the // system (i.e. a malformed file name, required argument, number out of range, @@ -449,7 +460,9 @@ func HTTPStatusFromErrorCode(code ErrorCode) int { case ErrCanceled: return 408 // RequestTimeout case ErrUnknown: - return 500 // Internal Server Error + return 400 // Bad Request + case ErrFail: + return 422 // Unprocessable Entity case ErrInvalidArgument: return 400 // BadRequest case ErrDeadlineExceeded: diff --git a/_examples/hello-webrpc-ts/Makefile b/_examples/hello-webrpc-ts/Makefile index 0e64c26f..c92a7b1a 100644 --- a/_examples/hello-webrpc-ts/Makefile +++ b/_examples/hello-webrpc-ts/Makefile @@ -7,10 +7,10 @@ tools: generate: generate-server generate-client generate-server: - ../../bin/webrpc-gen -schema=hello-api.ridl -target=go -pkg=main -server -out=./server/hello_api.gen.go + webrpc-gen -schema=hello-api.ridl -target=go -pkg=main -server -out=./server/hello_api.gen.go generate-client: - ../../bin/webrpc-gen -schema=hello-api.ridl -target=ts -client -out=./webapp/src/client.gen.ts + webrpc-gen -schema=hello-api.ridl -target=ts -client -out=./webapp/src/client.gen.ts bootstrap: rm -rf webapp/node_modules diff --git a/_examples/hello-webrpc-ts/server/hello_api.gen.go b/_examples/hello-webrpc-ts/server/hello_api.gen.go index a01bdb19..0d33c1c8 100644 --- a/_examples/hello-webrpc-ts/server/hello_api.gen.go +++ b/_examples/hello-webrpc-ts/server/hello_api.gen.go @@ -1,4 +1,4 @@ -// hello-webrpc v1.0.0 87ce8159bce3ad056518dfb1f1877b1a1012b34d +// hello-webrpc v1.0.0 5ace0c3aa305e464d6a2c180f43e8876be34e155 // -- // This file has been generated by https://github.com/webrpc/webrpc using gen/golang // Do not edit by hand. Update your webrpc schema and re-generate. @@ -27,7 +27,7 @@ func WebRPCSchemaVersion() string { // Schema hash generated from your RIDL schema func WebRPCSchemaHash() string { - return "87ce8159bce3ad056518dfb1f1877b1a1012b34d" + return "5ace0c3aa305e464d6a2c180f43e8876be34e155" } // @@ -400,6 +400,14 @@ func WrapError(code ErrorCode, cause error, format string, args ...interface{}) return &rpcErr{code: ErrInternal, msg: "invalid error type " + string(code), cause: cause} } +func Failf(format string, args ...interface{}) Error { + return Errorf(ErrFail, format, args...) +} + +func WrapFailf(cause error, format string, args ...interface{}) Error { + return WrapError(ErrFail, cause, format, args...) +} + func ErrorNotFound(format string, args ...interface{}) Error { return Errorf(ErrNotFound, format, args...) } @@ -419,13 +427,16 @@ func ErrorInternal(format string, args ...interface{}) Error { type ErrorCode string const ( - // Canceled indicates the operation was cancelled (typically by the caller). - ErrCanceled ErrorCode = "canceled" - // Unknown error. For example when handling errors raised by APIs that do not // return enough error information. ErrUnknown ErrorCode = "unknown" + // Fail error. General failure error type. + ErrFail ErrorCode = "fail" + + // Canceled indicates the operation was cancelled (typically by the caller). + ErrCanceled ErrorCode = "canceled" + // InvalidArgument indicates client specified an invalid argument. It // indicates arguments that are problematic regardless of the state of the // system (i.e. a malformed file name, required argument, number out of range, @@ -514,7 +525,9 @@ func HTTPStatusFromErrorCode(code ErrorCode) int { case ErrCanceled: return 408 // RequestTimeout case ErrUnknown: - return 500 // Internal Server Error + return 400 // Bad Request + case ErrFail: + return 422 // Unprocessable Entity case ErrInvalidArgument: return 400 // BadRequest case ErrDeadlineExceeded: diff --git a/_examples/hello-webrpc-ts/webapp/src/client.gen.ts b/_examples/hello-webrpc-ts/webapp/src/client.gen.ts index d623d5d7..9e7cddd2 100644 --- a/_examples/hello-webrpc-ts/webapp/src/client.gen.ts +++ b/_examples/hello-webrpc-ts/webapp/src/client.gen.ts @@ -1,5 +1,5 @@ -/* tslint:disable */ -// hello-webrpc v1.0.0 87ce8159bce3ad056518dfb1f1877b1a1012b34d +/* eslint-disable */ +// hello-webrpc v1.0.0 5ace0c3aa305e464d6a2c180f43e8876be34e155 // -- // This file has been generated by https://github.com/webrpc/webrpc using gen/typescript // Do not edit by hand. Update your webrpc schema and re-generate. @@ -11,7 +11,7 @@ export const WebRPCVersion = "v1" export const WebRPCSchemaVersion = "v1.0.0" // Schema hash generated from your RIDL schema -export const WebRPCSchemaHash = "87ce8159bce3ad056518dfb1f1877b1a1012b34d" +export const WebRPCSchemaHash = "5ace0c3aa305e464d6a2c180f43e8876be34e155" // @@ -69,9 +69,9 @@ export interface FindUsersReturn { // Client // export class ExampleService implements ExampleService { - private hostname: string - private fetch: Fetch - private path = '/rpc/ExampleService/' + protected hostname: string + protected fetch: Fetch + protected path = '/rpc/ExampleService/' constructor(hostname: string, fetch: Fetch) { this.hostname = hostname diff --git a/_examples/hello-webrpc/Makefile b/_examples/hello-webrpc/Makefile index 26a63fda..8100aa19 100644 --- a/_examples/hello-webrpc/Makefile +++ b/_examples/hello-webrpc/Makefile @@ -7,10 +7,10 @@ tools: generate: generate-server generate-client generate-server: - ../../bin/webrpc-gen -schema=hello-api.ridl -target=go -pkg=main -server -out=./server/hello_api.gen.go + webrpc-gen -schema=hello-api.ridl -target=go -pkg=main -server -out=./server/hello_api.gen.go generate-client: - ../../bin/webrpc-gen -schema=hello-api.ridl -target=js -extra=noexports -client -out=./webapp/client.gen.js + webrpc-gen -schema=hello-api.ridl -target=js -extra=noexports -client -out=./webapp/client.gen.js run-server: go run ./server diff --git a/_examples/hello-webrpc/server/hello_api.gen.go b/_examples/hello-webrpc/server/hello_api.gen.go index bff576f7..93c9552f 100644 --- a/_examples/hello-webrpc/server/hello_api.gen.go +++ b/_examples/hello-webrpc/server/hello_api.gen.go @@ -1,4 +1,4 @@ -// hello-webrpc v1.0.0 c929128d878e94653f3a856f80c4671008e22a45 +// hello-webrpc v1.0.0 d12378d7d88e036c2e5f779db475e7144b638b26 // -- // This file has been generated by https://github.com/webrpc/webrpc using gen/golang // Do not edit by hand. Update your webrpc schema and re-generate. @@ -27,7 +27,7 @@ func WebRPCSchemaVersion() string { // Schema hash generated from your RIDL schema func WebRPCSchemaHash() string { - return "c929128d878e94653f3a856f80c4671008e22a45" + return "d12378d7d88e036c2e5f779db475e7144b638b26" } // @@ -319,6 +319,14 @@ func WrapError(code ErrorCode, cause error, format string, args ...interface{}) return &rpcErr{code: ErrInternal, msg: "invalid error type " + string(code), cause: cause} } +func Failf(format string, args ...interface{}) Error { + return Errorf(ErrFail, format, args...) +} + +func WrapFailf(cause error, format string, args ...interface{}) Error { + return WrapError(ErrFail, cause, format, args...) +} + func ErrorNotFound(format string, args ...interface{}) Error { return Errorf(ErrNotFound, format, args...) } @@ -338,13 +346,16 @@ func ErrorInternal(format string, args ...interface{}) Error { type ErrorCode string const ( - // Canceled indicates the operation was cancelled (typically by the caller). - ErrCanceled ErrorCode = "canceled" - // Unknown error. For example when handling errors raised by APIs that do not // return enough error information. ErrUnknown ErrorCode = "unknown" + // Fail error. General failure error type. + ErrFail ErrorCode = "fail" + + // Canceled indicates the operation was cancelled (typically by the caller). + ErrCanceled ErrorCode = "canceled" + // InvalidArgument indicates client specified an invalid argument. It // indicates arguments that are problematic regardless of the state of the // system (i.e. a malformed file name, required argument, number out of range, @@ -433,7 +444,9 @@ func HTTPStatusFromErrorCode(code ErrorCode) int { case ErrCanceled: return 408 // RequestTimeout case ErrUnknown: - return 500 // Internal Server Error + return 400 // Bad Request + case ErrFail: + return 422 // Unprocessable Entity case ErrInvalidArgument: return 400 // BadRequest case ErrDeadlineExceeded: diff --git a/_examples/hello-webrpc/webapp/client.gen.js b/_examples/hello-webrpc/webapp/client.gen.js index 96401190..afac6fb8 100644 --- a/_examples/hello-webrpc/webapp/client.gen.js +++ b/_examples/hello-webrpc/webapp/client.gen.js @@ -1,4 +1,4 @@ -// hello-webrpc v1.0.0 c929128d878e94653f3a856f80c4671008e22a45 +// hello-webrpc v1.0.0 d12378d7d88e036c2e5f779db475e7144b638b26 // -- // This file has been generated by https://github.com/webrpc/webrpc using gen/javascript // Do not edit by hand. Update your webrpc schema and re-generate. @@ -10,7 +10,7 @@ export const WebRPCVersion = "v1" export const WebRPCSchemaVersion = "v1.0.0" // Schema hash generated from your RIDL schema -export const WebRPCSchemaHash = "c929128d878e94653f3a856f80c4671008e22a45" +export const WebRPCSchemaHash = "d12378d7d88e036c2e5f779db475e7144b638b26" // diff --git a/_examples/node-ts/Makefile b/_examples/node-ts/Makefile index 05de5c73..c4dbfb75 100644 --- a/_examples/node-ts/Makefile +++ b/_examples/node-ts/Makefile @@ -7,8 +7,8 @@ bootstrap: cd webapp && yarn generate: - ../../bin/webrpc-gen -schema=service.ridl -target=ts -server -out=./server/server.gen.ts - ../../bin/webrpc-gen -schema=service.ridl -target=ts -client -out=./webapp/client.gen.ts + webrpc-gen -schema=service.ridl -target=ts -server -out=./server/server.gen.ts + webrpc-gen -schema=service.ridl -target=ts -client -out=./webapp/client.gen.ts run-server: yarn --cwd ./server start diff --git a/_examples/node-ts/server/server.gen.ts b/_examples/node-ts/server/server.gen.ts index 6c5075d9..a692cc36 100644 --- a/_examples/node-ts/server/server.gen.ts +++ b/_examples/node-ts/server/server.gen.ts @@ -1,5 +1,5 @@ -/* tslint:disable */ -// node-ts v1.0.0 4d2858fa129683e5775e9b863ceceb740e7e09b1 +/* eslint-disable */ +// node-ts v1.0.0 ecee5cfb3e360bc0bc632e78556b19a2c58d4e25 // -- // This file has been generated by https://github.com/webrpc/webrpc using gen/typescript // Do not edit by hand. Update your webrpc schema and re-generate. @@ -11,7 +11,7 @@ export const WebRPCVersion = "v1" export const WebRPCSchemaVersion = "v1.0.0" // Schema hash generated from your RIDL schema -export const WebRPCSchemaHash = "4d2858fa129683e5775e9b863ceceb740e7e09b1" +export const WebRPCSchemaHash = "ecee5cfb3e360bc0bc632e78556b19a2c58d4e25" // diff --git a/_examples/node-ts/webapp/client.gen.ts b/_examples/node-ts/webapp/client.gen.ts index f13bd10d..32cd01a9 100644 --- a/_examples/node-ts/webapp/client.gen.ts +++ b/_examples/node-ts/webapp/client.gen.ts @@ -1,5 +1,5 @@ -/* tslint:disable */ -// node-ts v1.0.0 4d2858fa129683e5775e9b863ceceb740e7e09b1 +/* eslint-disable */ +// node-ts v1.0.0 ecee5cfb3e360bc0bc632e78556b19a2c58d4e25 // -- // This file has been generated by https://github.com/webrpc/webrpc using gen/typescript // Do not edit by hand. Update your webrpc schema and re-generate. @@ -11,7 +11,7 @@ export const WebRPCVersion = "v1" export const WebRPCSchemaVersion = "v1.0.0" // Schema hash generated from your RIDL schema -export const WebRPCSchemaHash = "4d2858fa129683e5775e9b863ceceb740e7e09b1" +export const WebRPCSchemaHash = "ecee5cfb3e360bc0bc632e78556b19a2c58d4e25" // @@ -61,9 +61,9 @@ export interface GetUserReturn { // Client // export class ExampleService implements ExampleService { - private hostname: string - private fetch: Fetch - private path = '/rpc/ExampleService/' + protected hostname: string + protected fetch: Fetch + protected path = '/rpc/ExampleService/' constructor(hostname: string, fetch: Fetch) { this.hostname = hostname