Skip to content

Commit

Permalink
feat: add node binding for y-octo (#4)
Browse files Browse the repository at this point in the history
* feat: add y-octo-node

* feat: add deps

* feat: init build

* chore: ignore auto generate files lint in prettier

* test: add test for node binding

* ci: extract rust toolchain action

* feat: extract more  actions

* feat: add test workflow for node

* ci: fix coverage

* fix: binding build

* ci: fix artifact name

* chore: ci name

* feat: add rust test for node binding

* chore: cleanup
  • Loading branch information
darkskygit authored Aug 21, 2023
1 parent 57286a3 commit 3152dc0
Show file tree
Hide file tree
Showing 21 changed files with 1,494 additions and 31 deletions.
44 changes: 44 additions & 0 deletions .github/actions/setup-node/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: "Y-Octo Node.js Setup"
description: "Node.js setup for CI, including cache configuration"
inputs:
extra-flags:
description: "Extra flags to pass to the yarn install."
required: false
default: "--immutable --inline-builds"
package-install:
description: "Run the install step."
required: false
default: "true"
hard-link-nm:
description: "set nmMode to hardlinks-local in .yarnrc.yml"
required: false
default: "true"

runs:
using: "composite"
steps:
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version-file: ".nvmrc"
cache: "yarn"

- name: Set nmMode
if: ${{ inputs.hard-link-nm == 'true' }}
shell: bash
run: yarn config set nmMode hardlinks-local

- name: yarn install
if: ${{ inputs.package-install == 'true' }}
continue-on-error: true
shell: bash
run: yarn install ${{ inputs.extra-flags }}
env:
HUSKY: "0"

- name: yarn install (try again)
if: ${{ steps.install.outcome == 'failure' }}
shell: bash
run: yarn install ${{ inputs.extra-flags }}
env:
HUSKY: "0"
24 changes: 24 additions & 0 deletions .github/actions/setup-rust/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: "Y-Octo Rust setup"
description: "Rust setup, including cache configuration"
inputs:
components:
description: "Cargo components"
required: false
target:
description: "Cargo target"
required: true
toolchain:
description: "Rustup toolchain"
required: false
default: "stable"

runs:
using: "composite"
steps:
- name: Setup Rust
uses: dtolnay/rust-toolchain@stable
with:
toolchain: ${{ inputs.toolchain }}
targets: ${{ inputs.target }}
components: ${{ inputs.components }}
- uses: Swatinem/rust-cache@v2
89 changes: 89 additions & 0 deletions .github/workflows/y-octo-node.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
name: Y-Octo Node Binding Build & Test

on:
workflow_dispatch:
push:
branches: [main]
pull_request:
branches: [main]

env:
DEBUG: napi:*
COVERAGE: true

jobs:
build-node:
name: Build Node Binding
runs-on: ubuntu-latest
env:
RUSTFLAGS: "-C debuginfo=1"
environment: development

steps:
- uses: actions/checkout@v3
- name: Setup Node.js
uses: ./.github/actions/setup-node
- name: Setup Rust
uses: ./.github/actions/setup-rust
with:
target: "x86_64-unknown-linux-gnu"
- name: Build node binding
run: yarn build:node
- name: Upload y-octo.node
uses: actions/upload-artifact@v3
with:
name: y-octo.node
path: ./y-octo-node/y-octo.linux-x64-gnu.node
if-no-files-found: error

test-node:
name: Test & Collect Coverage
runs-on: ubuntu-latest
continue-on-error: true
env:
RUSTFLAGS: -D warnings
CARGO_TERM_COLOR: always
steps:
- uses: actions/checkout@v3

- name: Setup Rust
uses: ./.github/actions/setup-rust
with:
components: llvm-tools-preview
- name: Install latest nextest release
uses: taiki-e/install-action@nextest
- name: Install cargo-llvm-cov
uses: taiki-e/install-action@cargo-llvm-cov

- name: Collect coverage data
run: cargo llvm-cov nextest --lcov --output-path lcov.info
- name: Upload coverage data to codecov
uses: codecov/codecov-action@v3
with:
name: tests
files: lcov.info

node-binding-test:
name: Node Binding Test
runs-on: ubuntu-latest
needs: build-node
steps:
- uses: actions/checkout@v3
- name: Setup Node.js
uses: ./.github/actions/setup-node
- name: Download y-octo.node
uses: actions/download-artifact@v3
with:
name: y-octo.node
path: ./y-octo-node
- name: Run node binding tests
run: yarn test:node:coverage
working-directory: y-octo-node
- name: Upload server test coverage results
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./y-octo-node/.coverage/lcov.info
flags: node-binding-test
name: y-octo
fail_ci_if_error: false
32 changes: 16 additions & 16 deletions .github/workflows/yocto.yml → .github/workflows/y-octo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,12 @@ jobs:
with:
fetch-depth: 0

- name: Install Rust
uses: dtolnay/rust-toolchain@master
- name: Setup Rust
uses: ./.github/actions/setup-rust
with:
toolchain: nightly-2023-08-19
components: clippy, rustfmt

- uses: Swatinem/rust-cache@v2

- name: Install Node.js
uses: actions/setup-node@v3
with:
Expand Down Expand Up @@ -79,11 +77,11 @@ jobs:
CARGO_TERM_COLOR: always
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@stable

- name: Setup Rust
uses: ./.github/actions/setup-rust
with:
components: llvm-tools-preview
- uses: Swatinem/rust-cache@v2

- name: Install latest nextest release
uses: taiki-e/install-action@nextest
- name: Install cargo-llvm-cov
Expand All @@ -107,10 +105,11 @@ jobs:
CARGO_TERM_COLOR: always
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@stable

- name: Setup Rust
uses: ./.github/actions/setup-rust
with:
toolchain: nightly-2023-08-19
- uses: Swatinem/rust-cache@v2

- name: Memory Check
run: |
Expand All @@ -127,9 +126,9 @@ jobs:
CARGO_TERM_COLOR: always
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2

- name: Setup Rust
uses: ./.github/actions/setup-rust
- name: Install latest nextest release
uses: taiki-e/install-action@nextest

Expand All @@ -147,12 +146,12 @@ jobs:
MIRIFLAGS: -Zmiri-backtrace=full -Zmiri-tree-borrows
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@stable

- name: Setup Rust
uses: ./.github/actions/setup-rust
with:
toolchain: nightly-2023-08-19
components: miri
- uses: Swatinem/rust-cache@v2

- name: Install latest nextest release
uses: taiki-e/install-action@nextest

Expand All @@ -169,10 +168,11 @@ jobs:
CARGO_TERM_COLOR: always
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@master

- name: Setup Rust
uses: ./.github/actions/setup-rust
with:
toolchain: nightly-2023-08-19
- uses: Swatinem/rust-cache@v2

- name: fuzzing
working-directory: ./y-octo
Expand Down
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
18
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ target
y-octo/README.md
.cargo
vendor
index.d.ts
index.js
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[workspace]

members = ["./y-octo", "./y-octo-utils"]
members = ["./y-octo", "./y-octo-node", "./y-octo-utils"]
resolver = "2"

[workspace.dependencies]
Expand Down
12 changes: 11 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
{
"name": "y-octo",
"name": "@y-octo/cli",
"version": "0.0.0",
"packageManager": "[email protected]",
"license": "MIT",
"workspaces": [
".",
"y-octo-node"
],
"engines": {
"node": ">=18.16.1 <19.0.0"
},
"scripts": {
"build:node": "yarn workspace @y-octo/node build",
"test:node": "yarn workspace @y-octo/node test",
"test:node:coverage": "yarn workspace @y-octo/node test:coverage",
"format": "run-p format:toml format:prettier format:rs",
"format:toml": "taplo format",
"format:prettier": "prettier --write .",
Expand Down
73 changes: 73 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{
"compilerOptions": {
"verbatimModuleSyntax": true,
// Classification follows https://www.typescriptlang.org/tsconfig

// Type Checking
"strict": true,
// exactOptionalPropertyTypes: false,
"noFallthroughCasesInSwitch": true,
"noImplicitAny": true,
"noImplicitOverride": true,
"noImplicitReturns": true,
"noImplicitThis": true,
// "noUnusedLocals": true,
// "noUnusedParameters": true,
// noPropertyAccessFromIndexSignature: false,
// noUncheckedIndexedAccess: false,
"useUnknownInCatchVariables": true,

// Modules
"module": "ESNext",
"moduleResolution": "bundler",
"resolveJsonModule": true,
// Emit
"declaration": true,
"declarationMap": true,
"sourceMap": true,
// skip type emit for @internal types
// "stripInternal": true,

// JavaScript Support
"allowJs": false,
"checkJs": false,

// Interop Constraints
"forceConsistentCasingInFileNames": true,
"allowSyntheticDefaultImports": true,
"isolatedModules": true,

// Language and Environment
"jsx": "preserve",
"jsxImportSource": "@emotion/react",
"lib": ["ESNext", "DOM"],
"target": "ES2022",
"useDefineForClassFields": false,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,

// Projects
"composite": true,
"incremental": true,

// Completeness
"skipLibCheck": true, // skip all type checks for .d.ts files
"paths": {
"@y-octo/node/*": ["./y-octo-node/src/*"]
}
},
"include": [],
"references": [
{
"path": "./y-octo-node"
}
],
"files": [],
"exclude": ["node_modules", "target", "lib", "test-results"],
"ts-node": {
"compilerOptions": {
"module": "ESNext",
"moduleResolution": "Node"
}
}
}
2 changes: 2 additions & 0 deletions y-octo-node/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.node
.coverage
22 changes: 22 additions & 0 deletions y-octo-node/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[package]
authors = ["DarkSky <[email protected]>"]
edition = "2021"
license = "MIT"
name = "y-octo-node"
repository = "https://github.com/toeverything/y-octo"
version = "0.0.1"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
crate-type = ["cdylib"]

[dependencies]
napi = "2"
napi-derive = "2"
y-octo = { path = "../y-octo" }

[build-dependencies]
napi-build = "2"

[profile.release]
lto = true
3 changes: 3 additions & 0 deletions y-octo-node/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
napi_build::setup();
}
Loading

0 comments on commit 3152dc0

Please sign in to comment.