Skip to content

Commit 0ed8e05

Browse files
authored
Merge pull request #2 from Brooooooklyn/cli
Support publish and benchmark in CI
2 parents 09f69b1 + e044e41 commit 0ed8e05

File tree

9 files changed

+148
-30
lines changed

9 files changed

+148
-30
lines changed

.github/workflows/ci.yaml

Lines changed: 82 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
11
name: CI
22

3-
on: [push, pull_request]
3+
on:
4+
push:
5+
branches:
6+
- '**'
7+
tags-ignore:
8+
- '**'
9+
pull_request:
10+
branches:
11+
- '**'
412

513
jobs:
614
lint_and_build:
15+
if: "!contains(github.event.head_commit.message, 'skip ci')"
16+
717
strategy:
818
fail-fast: false
919
matrix:
@@ -60,12 +70,6 @@ jobs:
6070
path: ~/.cargo/git
6171
key: stable-${{ matrix.os }}gnu-cargo-index-trimmed-${{ hashFiles('**/Cargo.lock') }}
6272

63-
- name: Cache cargo build
64-
uses: actions/cache@v1
65-
with:
66-
path: target
67-
key: stable-${{ matrix.os }}gnu-cargo-build-trimmed-${{ hashFiles('**/Cargo.lock') }}
68-
6973
- name: Cache NPM dependencies
7074
uses: actions/cache@v1
7175
with:
@@ -88,16 +92,11 @@ jobs:
8892
- name: Run build
8993
run: npx lerna run build --stream -- --platform
9094

91-
- name: Upload crc32 artifact
92-
uses: actions/upload-artifact@v1
95+
- name: Upload artifact
96+
uses: actions/upload-artifact@v2
9397
with:
94-
name: crc32.${{ env.PLATFORM_NAME }}.node
95-
path: packages/crc32/crc32.${{ env.PLATFORM_NAME }}.node
96-
97-
- name: Clear the cargo caches
98-
run: |
99-
cargo install cargo-cache --no-default-features --features ci-autoclean
100-
cargo-cache
98+
name: bindings-${{ env.PLATFORM_NAME }}
99+
path: packages/*/*.${{ env.PLATFORM_NAME }}.node
101100

102101
test_binding:
103102
name: Test bindings on ${{ matrix.os }} - node@${{ matrix.node }}
@@ -106,7 +105,7 @@ jobs:
106105
fail-fast: false
107106
matrix:
108107
os: [ubuntu-latest, macos-latest, windows-latest]
109-
node: ['10', '12', '14']
108+
node: ['10', '12', '13', '14']
110109
runs-on: ${{ matrix.os }}
111110

112111
steps:
@@ -123,22 +122,81 @@ jobs:
123122
echo "::set-env name=PLATFORM_NAME::$NODE_PLATFORM_NAME"
124123
shell: bash
125124

125+
# Do not cache node_modules, or yarn workspace links broken
126+
- name: 'Install dependencies'
127+
run: yarn install --frozen-lockfile --registry https://registry.npmjs.org
128+
129+
- name: Download artifacts
130+
uses: actions/download-artifact@v2
131+
with:
132+
name: bindings-${{ env.PLATFORM_NAME }}
133+
path: artifacts
134+
135+
- name: Move artifacts
136+
run: node scripts/mv-artifacts.js
137+
shell: bash
138+
139+
- name: Test bindings
140+
run: yarn test
141+
142+
- name: Build TypeScript
143+
run: yarn build:ts
144+
145+
- name: List packages
146+
run: ls -R packages
147+
shell: bash
148+
149+
- name: Run benchmark
150+
run: yarn bench
151+
152+
publish:
153+
name: Publish
154+
if: "startsWith(github.event.head_commit.message, 'chore(release): publish')"
155+
runs-on: ubuntu-latest
156+
needs: test_binding
157+
158+
steps:
159+
- uses: actions/checkout@v2
160+
161+
- name: Setup node
162+
uses: actions/setup-node@v1
163+
with:
164+
node-version: 12
165+
126166
- name: Cache NPM dependencies
127167
uses: actions/cache@v1
128168
with:
129169
path: node_modules
130-
key: npm-cache-${{ matrix.os }}-${{ hashFiles('yarn.lock') }}
170+
key: npm-cache-ubuntu-latest-${{ hashFiles('yarn.lock') }}
131171
restore-keys: |
132172
npm-cache-
133173
134174
- name: 'Install dependencies'
135175
run: yarn install --frozen-lockfile --registry https://registry.npmjs.org
136176

137-
- name: Download crc32 artifact
138-
uses: actions/download-artifact@v1
177+
- name: Download all artifacts
178+
uses: actions/download-artifact@v2
139179
with:
140-
name: crc32.${{ env.PLATFORM_NAME }}.node
141-
path: packages/crc32
180+
path: artifacts
142181

143-
- name: Test bindings
144-
run: yarn test
182+
- name: List artifacts
183+
run: ls -R artifacts
184+
shell: bash
185+
186+
- name: Move artifacts
187+
run: node scripts/mv-artifacts.js
188+
env:
189+
MOVE_TARGET: all
190+
191+
- name: Build TypeScript
192+
run: yarn build:ts
193+
194+
- name: List packages
195+
run: ls -R packages
196+
shell: bash
197+
- name: Lerna publish
198+
run: |
199+
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
200+
npx lerna publish from-package --no-verify-access --yes
201+
env:
202+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
11
# node-rs
22

33
When `NodeJS` meet `Rust` = 🚀
4+
5+
# Support matrix
6+
7+
| | node 10 | node12 | node13 | node14 |
8+
| ----------------- | ------- | ------ | ------ | ------ |
9+
| Windows 64 latest |||||
10+
| macOS latest |||||
11+
| Linux |||||
12+
13+
# Packages
14+
15+
| Package | Status | Description |
16+
| ---------------- | ------------------------------------------------------------------- | ------------------------------------------- |
17+
| `@node-rs/crc32` | ![](https://github.com/Brooooooklyn/node-rs/workflows/CI/badge.svg) | Fastest `CRC32` implementation using `SIMD` |

lerna.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,10 @@
22
"packages": ["packages/*"],
33
"npmClient": "yarn",
44
"useWorkspaces": true,
5-
"version": "independent"
5+
"version": "independent",
6+
"command": {
7+
"version": {
8+
"message": "chore(release): publish %s"
9+
}
10+
}
611
}

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
"private": true,
99
"workspaces": ["packages/*"],
1010
"scripts": {
11+
"bench": "lerna run bench --stream --no-prefix",
12+
"build:ts": "tsc -b tsconfig.project.json -verbose",
1113
"lint": "eslint . -c ./.eslintrc.yml 'packages/**/*.{ts,js}'",
1214
"test": "ava",
1315
"format": "run-p format:md format:json format:yaml format:source",
@@ -24,6 +26,7 @@
2426
"benchmark": "^2.1.4",
2527
"chalk": "^4.0.0",
2628
"codecov": "^3.6.5",
29+
"cross-env": "^7.0.2",
2730
"eslint": "^6.8.0",
2831
"eslint-config-prettier": "^6.11.0",
2932
"eslint-plugin-import": "^2.20.2",

packages/crc32/benchmark/crc32.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const Sse4Crc32 = require('sse4_crc32')
33
const { crc32: crc32Node } = require('crc')
44
const chalk = require('chalk')
55

6-
const { crc32c, crc32 } = require('../crc32.node')
6+
const { crc32c, crc32 } = require('../index')
77

88
const TEST_BUFFER = Buffer.from(`Lorem ipsum dolor sit amet, consectetur
99
adipiscing elit. Morbi mollis cursus metus vel tristique. Proin congue massa

packages/crc32/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"url": "git+https://github.com/Brooooooklyn/node-rs.git"
1515
},
1616
"scripts": {
17+
"bench": "cross-env NODE_ENV=production node benchmark/crc32.js",
1718
"build": "cargo build --release && napi --release ./crc32",
1819
"build:debug": "cargo build && napi ./index"
1920
},

packages/helper/package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@
1313
"type": "git",
1414
"url": "git+https://github.com/Brooooooklyn/node-rs.git"
1515
},
16-
"scripts": {
17-
"test": "echo \"Error: run tests from root\" && exit 1"
18-
},
1916
"bugs": {
2017
"url": "https://github.com/Brooooooklyn/node-rs/issues"
2118
}

scripts/mv-artifacts.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
const { execSync } = require('child_process')
2+
const { existsSync } = require('fs')
3+
const { platform } = require('os')
4+
const { join } = require('path')
5+
6+
const MOVE_ALL = process.env.MOVE_TARGET === 'all'
7+
8+
const platforms = MOVE_ALL ? ['linux', 'darwin', 'win32'] : [platform()]
9+
10+
const packages = ['crc32']
11+
12+
/**
13+
* @param {string[]} _platforms platforms
14+
* @param {boolean | undefined} moveAll
15+
* @returns {void}
16+
*/
17+
function moveFile(_platforms, moveAll = false) {
18+
for (const package of packages) {
19+
for (const platformName of _platforms) {
20+
const optionalPath = moveAll ? `bindings-${platformName}` : ''
21+
const artifactPath = join(process.cwd(), 'artifacts', optionalPath, package, `${package}.${platformName}.node`)
22+
if (existsSync(artifactPath)) {
23+
execSync(`mv ${artifactPath} ./packages/${package}/`, {
24+
stdio: 'inherit',
25+
})
26+
} else {
27+
throw new TypeError(`${artifactPath} not existed`)
28+
}
29+
}
30+
}
31+
}
32+
33+
moveFile(platforms, MOVE_ALL)

yarn.lock

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2416,6 +2416,13 @@ crc@^3.8.0:
24162416
dependencies:
24172417
buffer "^5.1.0"
24182418

2419+
cross-env@^7.0.2:
2420+
version "7.0.2"
2421+
resolved "https://registry.yarnpkg.com/cross-env/-/cross-env-7.0.2.tgz#bd5ed31339a93a3418ac4f3ca9ca3403082ae5f9"
2422+
integrity sha512-KZP/bMEOJEDCkDQAyRhu3RL2ZO/SUVrxQVI0G3YEQ+OLbRA3c6zgixe8Mq8a/z7+HKlNEjo8oiLUs8iRijY2Rw==
2423+
dependencies:
2424+
cross-spawn "^7.0.1"
2425+
24192426
cross-spawn@^6.0.0, cross-spawn@^6.0.5:
24202427
version "6.0.5"
24212428
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:
24272434
shebang-command "^1.2.0"
24282435
which "^1.2.9"
24292436

2430-
cross-spawn@^7.0.0:
2437+
cross-spawn@^7.0.0, cross-spawn@^7.0.1:
24312438
version "7.0.2"
24322439
resolved "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.2.tgz#d0d7dcfa74e89115c7619f4f721a94e1fdb716d6"
24332440
integrity sha512-PD6G8QG3S4FK/XCGFbEQrDqO2AnMMsy0meR7lerlIOHAAbkuavGU/pOqprrlvfTNjvowivTeBsjebAL0NSoMxw==

0 commit comments

Comments
 (0)