Skip to content
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
106 changes: 82 additions & 24 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
name: CI

on: [push, pull_request]
on:
push:
branches:
- '**'
tags-ignore:
- '**'
pull_request:
branches:
- '**'

jobs:
lint_and_build:
if: "!contains(github.event.head_commit.message, 'skip ci')"

strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -60,12 +70,6 @@ jobs:
path: ~/.cargo/git
key: stable-${{ matrix.os }}gnu-cargo-index-trimmed-${{ hashFiles('**/Cargo.lock') }}

- name: Cache cargo build
uses: actions/cache@v1
with:
path: target
key: stable-${{ matrix.os }}gnu-cargo-build-trimmed-${{ hashFiles('**/Cargo.lock') }}

- name: Cache NPM dependencies
uses: actions/cache@v1
with:
Expand All @@ -88,16 +92,11 @@ jobs:
- name: Run build
run: npx lerna run build --stream -- --platform

- name: Upload crc32 artifact
uses: actions/upload-artifact@v1
- name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: crc32.${{ env.PLATFORM_NAME }}.node
path: packages/crc32/crc32.${{ env.PLATFORM_NAME }}.node

- name: Clear the cargo caches
run: |
cargo install cargo-cache --no-default-features --features ci-autoclean
cargo-cache
name: bindings-${{ env.PLATFORM_NAME }}
path: packages/*/*.${{ env.PLATFORM_NAME }}.node

test_binding:
name: Test bindings on ${{ matrix.os }} - node@${{ matrix.node }}
Expand All @@ -106,7 +105,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
node: ['10', '12', '14']
node: ['10', '12', '13', '14']
runs-on: ${{ matrix.os }}

steps:
Expand All @@ -123,22 +122,81 @@ jobs:
echo "::set-env name=PLATFORM_NAME::$NODE_PLATFORM_NAME"
shell: bash

# Do not cache node_modules, or yarn workspace links broken
- name: 'Install dependencies'
run: yarn install --frozen-lockfile --registry https://registry.npmjs.org

- name: Download artifacts
uses: actions/download-artifact@v2
with:
name: bindings-${{ env.PLATFORM_NAME }}
path: artifacts

- name: Move artifacts
run: node scripts/mv-artifacts.js
shell: bash

- name: Test bindings
run: yarn test

- name: Build TypeScript
run: yarn build:ts

- name: List packages
run: ls -R packages
shell: bash

- name: Run benchmark
run: yarn bench

publish:
name: Publish
if: "startsWith(github.event.head_commit.message, 'chore(release): publish')"
runs-on: ubuntu-latest
needs: test_binding

steps:
- uses: actions/checkout@v2

- name: Setup node
uses: actions/setup-node@v1
with:
node-version: 12

- name: Cache NPM dependencies
uses: actions/cache@v1
with:
path: node_modules
key: npm-cache-${{ matrix.os }}-${{ hashFiles('yarn.lock') }}
key: npm-cache-ubuntu-latest-${{ hashFiles('yarn.lock') }}
restore-keys: |
npm-cache-

- name: 'Install dependencies'
run: yarn install --frozen-lockfile --registry https://registry.npmjs.org

- name: Download crc32 artifact
uses: actions/download-artifact@v1
- name: Download all artifacts
uses: actions/download-artifact@v2
with:
name: crc32.${{ env.PLATFORM_NAME }}.node
path: packages/crc32
path: artifacts

- name: Test bindings
run: yarn test
- name: List artifacts
run: ls -R artifacts
shell: bash

- name: Move artifacts
run: node scripts/mv-artifacts.js
env:
MOVE_TARGET: all

- name: Build TypeScript
run: yarn build:ts

- name: List packages
run: ls -R packages
shell: bash
- name: Lerna publish
run: |
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
npx lerna publish from-package --no-verify-access --yes
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# node-rs

When `NodeJS` meet `Rust` = 🚀

# Support matrix

| | node 10 | node12 | node13 | node14 |
| ----------------- | ------- | ------ | ------ | ------ |
| Windows 64 latest | ✅ | ✅ | ✅ | ✅ |
| macOS latest | ✅ | ✅ | ✅ | ✅ |
| Linux | ✅ | ✅ | ✅ | ✅ |

# Packages

| Package | Status | Description |
| ---------------- | ------------------------------------------------------------------- | ------------------------------------------- |
| `@node-rs/crc32` | ![](https://github.com/Brooooooklyn/node-rs/workflows/CI/badge.svg) | Fastest `CRC32` implementation using `SIMD` |
7 changes: 6 additions & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,10 @@
"packages": ["packages/*"],
"npmClient": "yarn",
"useWorkspaces": true,
"version": "independent"
"version": "independent",
"command": {
"version": {
"message": "chore(release): publish %s"
}
}
}
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
"private": true,
"workspaces": ["packages/*"],
"scripts": {
"bench": "lerna run bench --stream --no-prefix",
"build:ts": "tsc -b tsconfig.project.json -verbose",
"lint": "eslint . -c ./.eslintrc.yml 'packages/**/*.{ts,js}'",
"test": "ava",
"format": "run-p format:md format:json format:yaml format:source",
Expand All @@ -24,6 +26,7 @@
"benchmark": "^2.1.4",
"chalk": "^4.0.0",
"codecov": "^3.6.5",
"cross-env": "^7.0.2",
"eslint": "^6.8.0",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-import": "^2.20.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/crc32/benchmark/crc32.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const Sse4Crc32 = require('sse4_crc32')
const { crc32: crc32Node } = require('crc')
const chalk = require('chalk')

const { crc32c, crc32 } = require('../crc32.node')
const { crc32c, crc32 } = require('../index')

const TEST_BUFFER = Buffer.from(`Lorem ipsum dolor sit amet, consectetur
adipiscing elit. Morbi mollis cursus metus vel tristique. Proin congue massa
Expand Down
1 change: 1 addition & 0 deletions packages/crc32/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"url": "git+https://github.com/Brooooooklyn/node-rs.git"
},
"scripts": {
"bench": "cross-env NODE_ENV=production node benchmark/crc32.js",
"build": "cargo build --release && napi --release ./crc32",
"build:debug": "cargo build && napi ./index"
},
Expand Down
3 changes: 0 additions & 3 deletions packages/helper/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
"type": "git",
"url": "git+https://github.com/Brooooooklyn/node-rs.git"
},
"scripts": {
"test": "echo \"Error: run tests from root\" && exit 1"
},
"bugs": {
"url": "https://github.com/Brooooooklyn/node-rs/issues"
}
Expand Down
33 changes: 33 additions & 0 deletions scripts/mv-artifacts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const { execSync } = require('child_process')
const { existsSync } = require('fs')
const { platform } = require('os')
const { join } = require('path')

const MOVE_ALL = process.env.MOVE_TARGET === 'all'

const platforms = MOVE_ALL ? ['linux', 'darwin', 'win32'] : [platform()]

const packages = ['crc32']

/**
* @param {string[]} _platforms platforms
* @param {boolean | undefined} moveAll
* @returns {void}
*/
function moveFile(_platforms, moveAll = false) {
for (const package of packages) {
for (const platformName of _platforms) {
const optionalPath = moveAll ? `bindings-${platformName}` : ''
const artifactPath = join(process.cwd(), 'artifacts', optionalPath, package, `${package}.${platformName}.node`)
if (existsSync(artifactPath)) {
execSync(`mv ${artifactPath} ./packages/${package}/`, {
stdio: 'inherit',
})
} else {
throw new TypeError(`${artifactPath} not existed`)
}
}
}
}

moveFile(platforms, MOVE_ALL)
9 changes: 8 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2416,6 +2416,13 @@ crc@^3.8.0:
dependencies:
buffer "^5.1.0"

cross-env@^7.0.2:
version "7.0.2"
resolved "https://registry.yarnpkg.com/cross-env/-/cross-env-7.0.2.tgz#bd5ed31339a93a3418ac4f3ca9ca3403082ae5f9"
integrity sha512-KZP/bMEOJEDCkDQAyRhu3RL2ZO/SUVrxQVI0G3YEQ+OLbRA3c6zgixe8Mq8a/z7+HKlNEjo8oiLUs8iRijY2Rw==
dependencies:
cross-spawn "^7.0.1"

cross-spawn@^6.0.0, cross-spawn@^6.0.5:
version "6.0.5"
resolved "https://registry.npmjs.org/cross-spawn/-/cross-spawn-6.0.5.tgz#4a5ec7c64dfae22c3a14124dbacdee846d80cbc4"
Expand All @@ -2427,7 +2434,7 @@ cross-spawn@^6.0.0, cross-spawn@^6.0.5:
shebang-command "^1.2.0"
which "^1.2.9"

cross-spawn@^7.0.0:
cross-spawn@^7.0.0, cross-spawn@^7.0.1:
version "7.0.2"
resolved "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.2.tgz#d0d7dcfa74e89115c7619f4f721a94e1fdb716d6"
integrity sha512-PD6G8QG3S4FK/XCGFbEQrDqO2AnMMsy0meR7lerlIOHAAbkuavGU/pOqprrlvfTNjvowivTeBsjebAL0NSoMxw==
Expand Down