You are reading content from Scuttlebutt
@mmckegg %ttOgSGxgXllkVagurGhx38qDxde2ukvVYipCgmcWggo=.sha256

Automated prebuilds of native modules

Using prebuild and prebuild-ci (with travis-ci and appveyor) you can automate the building of native dependencies for almost all platforms!

prebuild creates .tar.gz bundles for each platform and uploads them to github. You can then add prebuild-install to your npm install and it will try to download the prebuilds from github before fallback to actually building locally.

I've recently been experimenting creating a fork of electron-spellchecker that builds prebuilds this so that I will be able to build patchwork for all platforms from my one machine!

Thought I'd share my process for anyone else that wants to give this a go!

Adding prebuild-ci to your project

In the module that you want to add automated prebuilds:

npm install prebuild --save-dev
npm install prebuild-ci --save-dev
npm install prebuild-install --save

Then add prebuild-ci to test and prebuild-install to install under scripts in package.json (and for local prebuilds you can add the prebuild script)

{
  "scripts": {
    "test": "tape && prebuild-ci",
    "install": "prebuild-install || node-gyp rebuild",
    "prebuild": "prebuild --all --strip --verbose"
  }
}

Add .travis.yml and appveyor.yml files:

# .travis.yml

sudo: false

language: node_js

addons:
  apt:
    sources:
      - ubuntu-toolchain-r-test
    packages:
      - g++-4.8

before_install:
  - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then export CXX=g++-4.8; fi
  - export JOBS=max

os:
  - osx
  - linux

node_js:
  - "8"
# appveyor.yml

version: "{build}"
build: off
skip_tags: true

environment:
  matrix:
    - nodejs_version: "8"

platform:
  - x86
  - x64

install:
  - ps: Install-Product node $env:nodejs_version $env:platform
  - ps: if ($env:nodejs_version -eq "5") { npm i npm@latest -g }
  - set PATH=%APPDATA%\npm;%APPVEYOR_BUILD_FOLDER%\node_modules\.bin;%PATH%
  - npm i

test_script:
  - npm test

Setup the travis build env (for mac and linux builds)

Add the github repo to travis on your profile: https://travis-ci.org/profile

Generate a token for uploading the prebuilds to github: https://github.com/settings/tokens/new (try adding repodeployment, repo:status, public_repo) _not sure if all these are needed, but it worked with just those selected

Then edit the settings on that repo in travis CI and then add the generated github token as an encrypted environment variable PREBUILD_TOKEN.

You can probably turn off "Build branch updates" and "Build pull request updates".

Setup appveyor build env (for windows builds)

Add the repo as a "Project" using "New Project" on https://ci.appveyor.com/projects

Go into the project settings and add the same PREBUILD_TOKEN as above (make sure you select the padlock to encrypt!)

Now whenever you push a new version, prebuilds will magically be added!

You should probably wait for the prebuilds to finish uploading before running npm publish just to make sure people get the automated builds.

#patchwork-dev #electron #node #npm

@mix %5fiPtI+ZIAHUpdlB8TQ+EPxj4QWlAM27RbKotaVcFhY=.sha256

this is awesome @matt.
Any progress on the automated builds for installers?
(I came into town to do a Mac build for Ticktack today, and I have to wait another day because the machine I was going to use is not available D:)

@mmckegg %okaORwieaQbx+hVndti0kGEkJCmlE4jpq+fGFESynyk=.sha256

One further note: it is important to make sure that the repo field in the package.json matches your repo's actual location and that the PREBUILD_TOKEN has the appropriate permissions to access it.

@mmckegg %paQ2X9rKEFvrvvhjiYXStOLl7WDrmJ2R/sYQwgpeDcQ=.sha256

@mix

Any progress on the automated builds for installers?

Automated no, but have just verified that I can build for the big 3 platforms from my Mac using electron-builder! The only thing that was missing was prebuilds for electron-spellchecker.

You can probably just run npm run release:all in ticktack and it would just work... unless you are using other native deps besides the sbot ones (in which case you'll need to fork and follow the instructions above).

But it looks like automating the entire builds should be possible too! It is just key management that is a little tricky - but possible I think (oh besides key management is already a problem when not running macOS and trying to do mac builds). So I think it should totally be possible to do a fully signed Mac build using travis-ci and a similar technique to above.

Join Scuttlebutt now