diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 021a1df7..1862114b 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -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: @@ -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: @@ -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 }} @@ -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: @@ -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 }} diff --git a/README.md b/README.md index c331dd70..f2c443f6 100644 --- a/README.md +++ b/README.md @@ -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` | diff --git a/lerna.json b/lerna.json index bcdca041..18e1ae52 100644 --- a/lerna.json +++ b/lerna.json @@ -2,5 +2,10 @@ "packages": ["packages/*"], "npmClient": "yarn", "useWorkspaces": true, - "version": "independent" + "version": "independent", + "command": { + "version": { + "message": "chore(release): publish %s" + } + } } diff --git a/package.json b/package.json index 22d87bf0..306b28d0 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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", diff --git a/packages/crc32/benchmark/crc32.js b/packages/crc32/benchmark/crc32.js index f199f99f..a8931d2a 100644 --- a/packages/crc32/benchmark/crc32.js +++ b/packages/crc32/benchmark/crc32.js @@ -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 diff --git a/packages/crc32/package.json b/packages/crc32/package.json index b63bd5db..283aea66 100644 --- a/packages/crc32/package.json +++ b/packages/crc32/package.json @@ -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" }, diff --git a/packages/helper/package.json b/packages/helper/package.json index 1b66ba49..ba499362 100644 --- a/packages/helper/package.json +++ b/packages/helper/package.json @@ -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" } diff --git a/scripts/mv-artifacts.js b/scripts/mv-artifacts.js new file mode 100644 index 00000000..e9d920fa --- /dev/null +++ b/scripts/mv-artifacts.js @@ -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) diff --git a/yarn.lock b/yarn.lock index b3fbe121..c1123c0a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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" @@ -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==