os: unstable
environment:
  NODE_PRE_GYP_GITHUB_TOKEN:
    secure: VYJPed/ilAHFpd7S0zW/C2U1jVqayW5QFBitwBqralJlKlgAPW6n1L1VUIOJswiW

  matrix:
  - nodejs_version: "4"
  - nodejs_version: "6"
  - nodejs_version: "7"

platform:
- x86
- x64

install:
- ps: Update-NodeJsInstallation (Get-NodeJsLatestBuild $env:nodejs_version) $env:platform;
- ps: $env:Path += ";$(pwd)\node_modules\.bin";
- ps: >
    @{
      "nodejs_version" = $env:nodejs_version
      "platform" = $env:platform
      "node binary version" = $(node -v)
      "node platform@arch" = $(node -p 'process.platform + process.arch')
      "npm version" = $(npm -v)
      "APPVEYOR_REPO_COMMIT_MESSAGE" = $env:APPVEYOR_REPO_COMMIT_MESSAGE
      "git latest tag" = "$(git describe --tags --always HEAD)"
      "appveyor_repo_tag" = $env:appveyor_repo_tag
      "electron_version" = $env:electron_version
      "PRE_GYP_GITHUB_TOKEN" = $env:NODE_PRE_GYP_GITHUB_TOKEN
    } | Out-String | Write-Host;

# work around bug in npm 2.15.1 where checksums were coming back bad (node 0.12)
- ps: >
    if ($(npm -v) -eq "2.15.1") {
      npm install -g npm@3 | Write-Host;
    }
    npm -v | Write-Host;

# work around an issue with node-gyp v3.3.1 and node 4x
# package.json has no certificates in it so we're cool
# https://github.com/nodejs/node-gyp/issues/921
- ps: npm config set -g cafile=package.json | Write-Host;
- ps: npm config set -g strict-ssl=false | Write-Host;

# Check if we're building the latest tag, if so
# then we publish the binaries if tests pass.
- ps: >
    if ($env:appveyor_repo_tag -match "true" -and ("$(git describe --tags --always HEAD)" -eq $env:appveyor_repo_tag_name)) {
      $env:publish_binary = 1;
    } else {
      $env:publish_binary = 0;
    }
    true;

- ps: >
    if ($env:publish_binary -eq 1) {
      "We're publishing a binary!" | Write-Host
    } else {
      "We're not publishing a binary" | Write-Host
    }
    true;

# Cleanup the output of npm
- ps: >
    npm config set progress false
    npm config set spin false

build_script:
- git submodule update --init
- npm install --build-from-source --msvs_version=2015

test_script:
- ps: npm run test

# If we run npm test in powershell it'll have the wrong encoding
# so we have to do it like this

- IF %PUBLISH_BINARY% == 1 (node-pre-gyp package 2>&1)
- IF %PUBLISH_BINARY% == 1 (node-pre-gyp-github publish --release 2>&1)

deploy: OFF

matrix:
  fast_finish: true
