diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 1cd06b14..f96ee712 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -8,13 +8,59 @@ on: name: Run Tests jobs: + prebuild: + name: Prebuild + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: + - ubuntu-20.04 + - macos-latest + - windows-latest + node_version: + - 14 + node_arch: + - x64 + include: + - os: windows-latest + node_version: 14 + node_arch: x86 + steps: + - uses: actions/checkout@v2 + + - name: Install Node + uses: actions/setup-node@v2 + with: + node-version: ${{ matrix.node_version }} + architecture: ${{ matrix.node_arch }} + + - name: Install Dependencies and Build + run: yarn + + - name: Prebuild + run: yarn run prebuild + env: + ARCH: ${{ matrix.node_arch }} + + - name: Upload artifacts + uses: actions/upload-artifact@v2 + with: + path: ./prebuilds test: name: Tests + needs: prebuild strategy: matrix: node: [10, 12] os: [windows-2016, ubuntu-16.04, ubuntu-18.04, macOS-latest] + node_arch: + - x64 + include: + - os: windows-latest + node: 14 + node_arch: x86 runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@master @@ -23,6 +69,18 @@ jobs: uses: actions/setup-node@master with: node-version: ${{ matrix.node }} + architecture: ${{ matrix.node_arch }} + + - name: Download prebuilds + uses: actions/download-artifact@v2 + + - name: Install prebuilds + shell: bash + run: | + rm -rf build + mkdir prebuilds + mv artifact/* prebuilds/ + ls prebuilds - run: yarn diff --git a/.gitignore b/.gitignore index 32d251b6..2ecb07d0 100644 --- a/.gitignore +++ b/.gitignore @@ -21,6 +21,7 @@ coverage # Compiled binary addons (http://nodejs.org/api/addons.html) build/Release +prebuilds # Dependency directory # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 00000000..9e5e8386 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,23 @@ +## Releasing a new npm version + +- Change the version in `package.json`, make a new git tag, and push it to GitHub. +- Wait until the GitHub Actions on the master branch pass. +- The artifacts of the latest GitHub Action run should be downloaded from the actions tab of the GitHub repository +- The artifacts.zip should be extracted and placed under the `prebuilds` folder (replacing the old folder if it exists). + + The `prebuilds` folder should look like the following. + ``` + repository-root + |-prebuilds + |_linux-x64 + |... + |_darwin-x64 + |... + |_win32-x64 + |... + ``` + +- Then: + ``` + npm publish + ``` diff --git a/binding.js b/binding.js new file mode 100644 index 00000000..3da4000f --- /dev/null +++ b/binding.js @@ -0,0 +1,2 @@ +// don't move this file. It should be next to package.json +module.exports = require('node-gyp-build')(__dirname); diff --git a/js/scripts/prebuild.js b/js/scripts/prebuild.js new file mode 100644 index 00000000..0a0ac864 --- /dev/null +++ b/js/scripts/prebuild.js @@ -0,0 +1,39 @@ +const {spawnSync} = require('child_process'); + +main().catch(e => { + throw e; +}); + +async function main() { + console.log('Building distribution binary...'); // eslint-disable-line no-console + + const prebuildArch = getNodearch(process.env.ARCH); + + // napi is forward compatible so we only build for two targets (Node and Electron) + let prebuildScript = `prebuildify --napi --arch=${prebuildArch} -t 12.0.0 -t electron@9.4.4 --strip`; + + if (process.platform == 'linux') { + prebuildScript = `${prebuildScript} --tag-libc`; + } + + spawnSync(prebuildScript, { + shell: true, + stdio: 'inherit', + encoding: 'utf8', + }); +} + +/** + * @param {string | undefined} arch the given architecture + * @returns {string} the Node architecture to build for + */ +function getNodearch(arch) { + if (!arch) { + return process.arch; + } + if (arch === 'x86') { + return 'ia32'; + } else { + return arch; + } +} diff --git a/js/src/index.js b/js/src/index.js index bdddb312..e44e9265 100644 --- a/js/src/index.js +++ b/js/src/index.js @@ -1,7 +1,7 @@ const { promises: fs } = require('fs'); const path = require('path'); -const NSFW = require('../../build/Release/nsfw.node'); +const NSFW = require('../../binding'); function NSFWFilePoller(watchPath, eventCallback, debounceMS) { const { CREATED, DELETED, MODIFIED } = nsfw.actions; diff --git a/package.json b/package.json index 8d7dd790..eaafb69c 100644 --- a/package.json +++ b/package.json @@ -4,8 +4,10 @@ "description": "A simple file watcher for Node", "main": "js/src/index.js", "scripts": { + "install": "node-gyp-build", "lint": "eslint js/src js/spec", - "test": "yarn lint && node js/scripts/test.js" + "test": "yarn lint && node js/scripts/test.js", + "prebuild": "node ./js/scripts/prebuild.js" }, "repository": { "type": "git", @@ -25,17 +27,20 @@ "js/src", "src", "includes", - "binding.gyp" + "binding.gyp", + "prebuilds" ], "homepage": "https://github.com/axosoft/node-simple-file-watcher", "dependencies": { - "node-addon-api": "*" + "node-addon-api": "*", + "node-gyp-build": "^4.2.3" }, "devDependencies": { "eslint": "^6.8.0", "executive": "^1.6.3", "fs-extra": "^7.0.0", - "mocha": "^7.1.1" + "mocha": "^7.1.1", + "prebuildify": "^4.1.2" }, "keywords": [ "FileWatcher",