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

WIP - publish grpc-bridge package #3985

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 20 additions & 10 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ jobs:
echo "::set-output name=new-release-published::${{steps.semantic.outputs.new-release-published}}"
echo "::set-output name=release-version::${{steps.semantic.outputs.release-version}}"


post-semantic-release:
needs: semantic-release
#if: needs.semantic-release.outputs.new-release-published == 'true'
Expand All @@ -64,6 +63,7 @@ jobs:
- name: Unshallow
run: git fetch --prune --unshallow

# Next step also sets up a .npmrc file for automatic publishing to npm
- uses: actions/setup-node@v2
if: needs.semantic-release.outputs.new-release-published == 'true'
with:
Expand All @@ -81,11 +81,21 @@ jobs:
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
continue-on-error: true
# Next step also sets up a .npmrc file for automatic publishing to npm

- name: "Publish npm package: @berty/api (DryRun)"
if: needs.semantic-release.outputs.new-release-published != 'true'
run: cd tool && go run ./publish-npm-package -path=../js/packages/api -version=0.0.0 -dry-run
run: cd tool && go run ./publish-npm-package -path=../js/packages/api -version=0.42.0 -dry-run

- name: "Publish npm package: @berty/grpc-bridge (Real)"
if: needs.semantic-release.outputs.new-release-published == 'true'
run: cd tool && go run ./publish-npm-package -path=../js/packages/grpc-bridge -version=${{ needs.semantic-release.outputs.release-version }}
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
continue-on-error: true

- name: "Publish npm package: @berty/grpc-bridge (DryRun)"
if: needs.semantic-release.outputs.new-release-published != 'true'
run: cd tool && go run ./publish-npm-package -path=../js/packages/grpc-bridge -version=0.42.0 -dry-run

- name: Register version on pkg.go.dev
if: needs.semantic-release.outputs.new-release-published == 'true'
Expand All @@ -96,19 +106,19 @@ jobs:
set -x +e
curl -i $url


build-asset:
needs: semantic-release
name: build asset
runs-on: ${{ matrix.config.runs-on }}
strategy:
matrix:
config: [
{runs-on: 'ubuntu-latest', goos: 'linux', golang: '1.17.x'},
{runs-on: 'macos-latest', goos: 'darwin', golang: '1.17.x'},
{runs-on: 'windows-latest', goos: 'windows', golang: '1.17.x'},
# TODO: bertyguy
]
config:
[
{ runs-on: "ubuntu-latest", goos: "linux", golang: "1.17.x" },
{ runs-on: "macos-latest", goos: "darwin", golang: "1.17.x" },
{ runs-on: "windows-latest", goos: "windows", golang: "1.17.x" },
]
# TODO: bertyguy
env:
OSXCROSS_DIR: /home/runner/work/osxcross
steps:
Expand Down
75 changes: 70 additions & 5 deletions js/packages/grpc-bridge/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,76 @@
# `@berty/berty-store`
# `@berty/grpc-bridge`

> TODO: description
Berty GRPC plumbing

## Usage
# Usage

## React

Tested with a raw `create-react-app`

```sh
yarn add '@berty/grpc-bridge@2.361.5' '@berty/api@2.361.1' '@improbable-eng/grpc-web@^0.15.0' 'google-protobuf@^3.14.0'
```

```js
import './App.css';
import beapi from "@berty/api"
import { Service, rpcWeb, logger } from "@berty/grpc-bridge"
import { grpc } from "@improbable-eng/grpc-web"

function App() {
return (
<div className="App">
<button onClick={async () => {
const opts = {
transport: grpc.CrossBrowserHttpTransport({ withCredentials: false }),
host: "http://127.0.0.1:9091",
}
const rpc = rpcWeb(opts)
const client = Service(beapi.messenger.MessengerService, rpc, logger.create('MESSENGER'))

const accountReply = await client.accountGet({})
console.log("account", accountReply)

const stream = await client.eventStream({})
stream.onMessage(msg => console.log("got msg:", msg))
stream.start()

await client.accountUpdate({ displayName: "niceeee" })
}}>
Test
</button>
</div>
);
}

export default App;
```
const bertyStore = require('@berty/berty-store');

// TODO: DEMONSTRATE API
## Node

```sh
yarn add '@berty/grpc-bridge@2.361.5' '@berty/api@2.361.1' '@improbable-eng/grpc-web@^0.15.0' '@improbable-eng/grpc-web-node-http-transport@^0.15.0' 'google-protobuf@^3.14.0'
```

```js
const beapi = require("@berty/api")
const { Service, rpcWeb, logger } = require("@berty/grpc-bridge")
const { NodeHttpTransport } = require('@improbable-eng/grpc-web-node-http-transport')

const opts = {
transport: NodeHttpTransport(),
host: "http://127.0.0.1:9091",
}
const rpc = rpcWeb(opts)

const client = Service(beapi.messenger.MessengerService, rpc, logger.create('MESSENGER'))

client.eventStream({}).then(stream => {
stream.onMessage(msg => console.log("msg:", msg))
stream.start().then((r) => {
console.log("eventStream started:", r)
client.accountUpdate({ displayName: "toto" })
})
})
```
5 changes: 5 additions & 0 deletions js/packages/grpc-bridge/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import grpcBridge from './bridge'

import rpcWeb from './rpc/rpc.grpcweb'
import { logger } from './middleware'

export type { GRPCBridge } from './bridge'
export { ReactNativeTransport } from './grpc-web-react-native-transport'
export { WebsocketTransport } from './grpc-web-websocket-transport'
export { createService as Service } from './service'
export { GRPCError, EOF } from './error'

export { rpcWeb, logger }

export default grpcBridge
26 changes: 26 additions & 0 deletions js/packages/grpc-bridge/package.template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "@berty/grpc-bridge",
"version": "{{ .Version }}",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"repository": "https://github.com/berty/berty",
"homepage": "https://github.com/berty/berty/tree/master/js/packages/grpc-bridge#readme",
"files": [
"dist"
],
"scripts": {
"prepublish": "tsc"
},
"license": "MIT",
"dependencies": {
"@berty/api": "2.361.1",
"@improbable-eng/grpc-web": "^0.15.0",
"base64-js": "^1.3.0",
"lodash": "^4.14.178",
"protobufjs": "^6.11.2"
},
"devDependencies": {
"@types/lodash": "^4.14.178",
"typescript": "^4.6.2"
}
}
10 changes: 0 additions & 10 deletions js/packages/grpc-bridge/rpc/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Platform } from 'react-native'
import base64 from 'base64-js'
import * as pb from 'protobufjs'

Expand All @@ -14,15 +13,6 @@ export const getServiceName = <T extends pb.Method>(method: T) => {
return fullName
}

// CONST
export const isWeb = Platform.OS === 'web'
export const isElectron = !!(
isWeb &&
window.navigator &&
window.navigator.userAgent &&
window.navigator.userAgent.toLowerCase().indexOf('electron') !== -1
)

// Error
export const ErrorStreamNotImplemented = new Error('stream service not implemented')
export const ErrorUnaryNotImplemented = new Error('unary service not implemented')
18 changes: 18 additions & 0 deletions js/packages/grpc-bridge/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"compilerOptions": {
"outDir": "dist",
"target": "es2016",
"module": "commonjs",
"declaration": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true,
"allowJs": true,
"isolatedModules": true,
"moduleResolution": "node",
},
"files": [
"index.ts"
]
}
7 changes: 7 additions & 0 deletions tool/publish-npm-package/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ func errMain() error {
pathFlag := flag.String("path", "", "path to the package to be published")
versionFlag := flag.String("version", "", "version to publish")
dryrunFlag := flag.Bool("dry-run", false, "do not publish at the end")
var manual bool
flag.BoolVar(&manual, "manual", false, "don't install deps and don't publish if set")
flag.Parse()

path := *pathFlag
Expand Down Expand Up @@ -102,6 +104,11 @@ func errMain() error {
}
logger.Info("Wrote package.json")

if manual {
logger.Info("Manual mode!")
return nil
}

cmd := exec.Command("npm", "i")
cmd.Dir = buildDir
cmd.Stderr = os.Stderr
Expand Down