Skip to content

Commit

Permalink
feat: update Node.JS binding (#28)
Browse files Browse the repository at this point in the history
Co-authored-by: Ivan Shumkov <[email protected]>
  • Loading branch information
fominok and shumkov authored Jan 27, 2022
1 parent 24e6050 commit 39efe87
Show file tree
Hide file tree
Showing 24 changed files with 5,399 additions and 834 deletions.
6 changes: 6 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[target.aarch64-unknown-linux-musl]
linker = "aarch64-linux-gnu-gcc"
rustflags = [ "-C", "target-feature=+crt-static", "-C", "link-arg=-lgcc" ]

[target.x86_64-unknown-linux-musl]
rustflags = [ "-C", "target-feature=-crt-static" ]
30 changes: 0 additions & 30 deletions .github/workflows/ci.yml

This file was deleted.

80 changes: 80 additions & 0 deletions .github/workflows/grovedb.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
on:
workflow_dispatch:
pull_request:
branches:
- master

name: GroveDB

jobs:
test:
name: Tests
runs-on: ubuntu-latest
steps:
- name: Cancel previous runs
uses: styfle/[email protected]
with:
access_token: ${{ github.token }}

- uses: actions/checkout@v2

- uses: actions-rs/toolchain@v1
with:
toolchain: nightly

- run: cargo test

linting:
name: Liniting
runs-on: ubuntu-latest
steps:
- name: Cancel previous runs
uses: styfle/[email protected]
with:
access_token: ${{ github.token }}

- uses: actions/checkout@v2

- uses: actions-rs/toolchain@v1
with:
toolchain: nightly
default: true
components: clippy

- uses: actions-rs/clippy-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
args: --all-features

errors:
name: Compilation errors
runs-on: ubuntu-latest
steps:
- name: Cancel previous runs
uses: styfle/[email protected]
with:
access_token: ${{ github.token }}

- uses: actions/checkout@v2

- uses: actions-rs/toolchain@v1
with:
toolchain: nightly
default: true

- run: cargo check

security:
name: Dependencies security audit
runs-on: ubuntu-latest
steps:
- name: Cancel previous runs
uses: styfle/[email protected]
with:
access_token: ${{ github.token }}

- uses: actions/checkout@v2

- uses: actions-rs/audit-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
64 changes: 64 additions & 0 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
on:
workflow_dispatch:
pull_request:
branches:
- master

name: Node.JS binding

jobs:
test:
name: Tests
runs-on: ubuntu-latest
steps:
- name: Cancel previous runs
uses: styfle/[email protected]
with:
access_token: ${{ github.token }}

- uses: actions/checkout@v2

- name: Setup Node.JS
uses: actions/setup-node@v2
with:
node-version: '16'

- name: Setup Rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
default: true

- name: Install NPM deps
run: npm ci

- name: Run tests
run: npm test

linting:
name: Linting
runs-on: ubuntu-latest
steps:
- name: Cancel previous runs
uses: styfle/[email protected]
with:
access_token: ${{ github.token }}

- uses: actions/checkout@v2

- name: Setup Node.JS
uses: actions/setup-node@v2
with:
node-version: '16'

- name: Setup Rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
default: true

- name: Install NPM deps
run: npm ci

- name: Run ES linter
run: npm run lint
186 changes: 186 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
name: Release

on:
workflow_dispatch:
release:
types:
- published

jobs:
build:
name: Build Node.JS binding

strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
arch: x86_64
compiler: gnu
platform: unknown-linux
# TODO: Enable build for arm64 linux gnu
# - os: ubuntu-latest
# arch: aarch64
# node_arch: arm64
# compiler: gnu
# platform: unknown-linux
# build_dependencies:
# - gcc-aarch64-linux-gnu
# - binutils-aarch64-linux-gnu
# - clang
- os: ubuntu-latest
arch: x86_64
compiler: musl
platform: unknown-linux
build_dependencies:
- musl-tools
# TODO: Enable build for arm64 linux musl
# - os: ubuntu-latest
# arch: aarch64
# node_arch: arm64
# compiler: musl
# platform: unknown-linux
# build_dependencies:
# - gcc-aarch64-linux-gnu
# - binutils-aarch64-linux-gnu
# - clang
# - musl-tools
# - musl
# - musl:arm64
- os: macos-11
arch: x86_64
platform: apple-darwin
- os: macos-11
arch: aarch64
node_arch: arm64
platform: apple-darwin

runs-on: ${{ matrix.os }}
steps:
- name: Check out repo
uses: actions/checkout@v2

- name: Setup Node.JS
uses: actions/setup-node@v2
with:
node-version: 16

- name: Install NPM deps
run: npm ci

- name: Set target name
uses: actions/github-script@v5
id: set-target
with:
script: |
let target = '${{ matrix.arch }}-${{ matrix.platform }}';
if ('${{ matrix.compiler }}') {
target += '-${{ matrix.compiler }}';
}
core.info(`Set target ${target}`);
return target;
result-encoding: string

# - name: Add arm64 architecture for apt
# if: ${{ matrix.os == 'ubuntu-latest' && matrix.arch == 'aarch64' }}
# run: sudo dpkg --add-architecture arm64

- name: Install build deps
if: ${{ matrix.os == 'ubuntu-latest' && matrix.build_dependencies && matrix.build_dependencies[0] }}
run: |
sudo apt-get update
sudo apt-get install ${{ join(matrix.build_dependencies, ' ') }}
- name: Fix missing "musl-g++" for x86_64-unknown-linux-musl # https://github.com/rust-lang/cargo/issues/3359
if: ${{ matrix.os == 'ubuntu-latest' && matrix.arch == 'x86_64' && matrix.compiler == 'musl' }}
run: sudo ln -s /bin/g++ /bin/musl-g++

- name: Setup Rust toolchain and target
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
default: true
target: ${{ steps.set-target.outputs.result }}

- name: Set defualt target
uses: DamianReeves/[email protected]
with:
path: .cargo/config.toml
write-mode: append
contents: |
[build]
target = "${{ steps.set-target.outputs.result }}"
- name: Set LIBC env
uses: actions/github-script@v5
id: set-libc
with:
script: |
let env = '';
if (${{ matrix.compiler == 'musl' }}) {
env = 'musl'
}
core.info(`Set LIBC env to "${env}"`);
return env;
result-encoding: string

- name: Run tests
run: npm test
if: ${{ matrix.os != '' && matrix.arch != 'aarch64' }} # TODO Run test on Apple M1
env:
LIBC: ${{ steps.set-libc.outputs.result }}
ARCH: ${{ matrix.node_arch }} # Overwrite current arch with target one

- name: Build
run: npm run build:release
env:
LIBC: ${{ steps.set-libc.outputs.result }}
ARCH: ${{ matrix.node_arch }} # Overwrite current arch with target one

- name: Upload prebuild artifacts
uses: actions/upload-artifact@v2
with:
name: prebuilds
path: node-grove/prebuilds/

publish:
name: Publish NPM Package
needs: [build]
runs-on: ubuntu-latest
steps:
- name: Checkout the repo
uses: actions/checkout@v2

- name: Check package version matches tag
uses: geritol/[email protected]
env:
TAG_PREFIX: v

- name: Setup Node.JS
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}

- name: Install NPM deps
run: npm ci

- name: Download prebuild artifacts
uses: actions/download-artifact@v2
with:
name: prebuilds
path: node-grove/prebuilds

- name: List prebuilds
run: ls -laR node-grove/prebuilds

- name: NPM Publish
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/target
.idea
Cargo.lock
index.node
node-grove/prebuilds
node_modules
.DS_Store
.DS_Store?
.DS_Store?
Loading

0 comments on commit 39efe87

Please sign in to comment.