Skip to content
This repository has been archived by the owner on Aug 2, 2023. It is now read-only.

Publish Node SDK #97

Merged
merged 20 commits into from
Apr 19, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
139 changes: 138 additions & 1 deletion .github/workflows/pr-sdk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,55 @@ env:
CARGO_PROFILE_TEST_DEBUG: 0

jobs:
node-sdk:
name: Build Node SDK
runs-on: ubuntu-latest

steps:
- name: Set up Protoc
uses: arduino/setup-protoc@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}

- name: Print version of protoc
run: protoc --version

- name: Checkout code
uses: actions/checkout@v3

- name: Set up Node
uses: actions/setup-node@v3
with:
node-version: 16
cache: npm
cache-dependency-path: sdk/node/package-lock.json

- name: Install Buf dependencies
run: npm install -g grpc_tools_node_protoc_ts grpc-tools

- name: Set up Buf
uses: bufbuild/buf-setup-action@v1.3.1

- name: Run Buf
working-directory: api
run: buf generate

- name: Install dependencies
working-directory: ./sdk/node
run: npm install

- name: Build Node client
working-directory: ./sdk/node
run: npm run build

- name: Upload Node SDK
uses: actions/upload-artifact@v3
with:
name: node-sdk
path: sdk/node/**

test-server:
name: Build test-server
name: Build test server
runs-on: ubuntu-latest

steps:
Expand Down Expand Up @@ -44,6 +91,51 @@ jobs:
name: test-server
path: target/debug/test-server

javascript:
name: Test JavaScript bot
runs-on: ubuntu-latest

needs:
- node-sdk
- test-server

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Node
uses: actions/setup-node@v3
with:
node-version: 16
cache: npm
cache-dependency-path: examples/javascript/package-lock.json

- name: Download Node SDK
uses: actions/download-artifact@v3
with:
name: node-sdk
path: sdk/node

- name: Install dependencies
working-directory: ./examples/javascript
run: npm install

- name: Download test-server
uses: actions/download-artifact@v3
with:
name: test-server
path: bin

- name: Set permissions for test-server
run: chmod +x bin/test-server

- name: Start test-server
run: bin/test-server &

- name: Run JavaScript example
working-directory: ./examples/javascript
run: npm start

rust:
name: Test Rust bot
runs-on: ubuntu-latest
Expand Down Expand Up @@ -86,3 +178,48 @@ jobs:
with:
command: run
args: -p auto-traffic-control-example

typescript:
name: Test TypeScript bot
runs-on: ubuntu-latest

needs:
- node-sdk
- test-server

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Node
uses: actions/setup-node@v3
with:
node-version: 16
cache: npm
cache-dependency-path: examples/typescript/package-lock.json

- name: Download Node SDK
uses: actions/download-artifact@v3
with:
name: node-sdk
path: sdk/node

- name: Install dependencies
working-directory: ./examples/typescript
run: npm install

- name: Download test-server
uses: actions/download-artifact@v3
with:
name: test-server
path: bin

- name: Set permissions for test-server
run: chmod +x bin/test-server

- name: Start test-server
run: bin/test-server &

- name: Run JavaScript example
working-directory: ./examples/typescript
run: npm start
52 changes: 52 additions & 0 deletions .github/workflows/release-sdk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,58 @@ name: SDK
- released

jobs:
node:
name: Node
runs-on: ubuntu-latest

env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

steps:
- name: Set up Protoc
uses: arduino/setup-protoc@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}

- name: Print version of protoc
run: protoc --version

- name: Checkout code
uses: actions/checkout@v3

- name: Set up Node
uses: actions/setup-node@v3
with:
node-version: 16
cache: npm
cache-dependency-path: sdk/node/package-lock.json

- name: Install Buf dependencies
run: npm install -g grpc_tools_node_protoc_plugin_ts grpc-tools

- name: Set up Buf
uses: bufbuild/buf-setup-action@v1.3.1

- name: Run Buf
working-directory: api
run: buf generate

- name: Install dependencies
working-directory: ./sdk/node
run: npm install

- name: Authenticate using a token
working-directory: ./sdk/node
run: echo '//registry.npmjs.org/:_authToken=${NPM_TOKEN}' > .npmrc

- name: Build Node client
working-directory: ./sdk/node
run: npm run build

- name: Publish to npm
working-directory: ./sdk/node
run: npm publish

rust:
name: Publish Rust SDK
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# 🛬 Auto Traffic Control

[![GitHub branch checks state](https://img.shields.io/github/checks-status/jdno/atc/main)](https://github.com/jdno/atc/actions)
[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/jdno/auto-traffic-control/main)](https://github.com/jdno/auto-traffic-control/actions)

[Homepage](https://auto-traffic-control.com) |
[Documentation](https://auto-traffic-control.com/docs) |
Expand Down
19 changes: 19 additions & 0 deletions api/buf.gen.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
version: v1

managed:
enabled: true

plugins:
- name: js
out: ../sdk/node/src
opt: import_style=commonjs,binary

- name: grpc
out: ../sdk/node/src
opt: grpc_js
path: grpc_tools_node_protoc_plugin

- name: ts
out: ../sdk/node/src
opt: grpc_js
51 changes: 51 additions & 0 deletions examples/javascript/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
### Node.gitignore
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Coverage directory used by tools like istanbul
coverage
*.lcov

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local
29 changes: 29 additions & 0 deletions examples/javascript/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import atc from "auto-traffic-control";

const { getCredentials, AtcServiceClient, GetVersionRequest } = atc;

const atcService = new AtcServiceClient("localhost:4747", getCredentials());

atcService.getVersion(new GetVersionRequest(), (err, response) => {
if (err != null) {
throw err;
}

const version = response.getVersion();

if (version != null) {
let versionString = [
version.getMajor(),
version.getMinor(),
version.getPatch(),
].join(".");

if (version.getPre() !== "") {
versionString = versionString.concat(version.getPre());
}

console.log(`Auto Traffic Control is running version '${versionString}'`);
} else {
throw new Error("Requesting the version returned an empty response.");
}
});
43 changes: 43 additions & 0 deletions examples/javascript/package-lock.json

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

Loading