# Based on https://github.com/ogrisel/python-appveyor-demo/blob/master/appveyor.yml
version: '{build}'

environment:
  global:
    # SDK v7.0 MSVC Express 2008's SetEnv.cmd script will fail if the
    # /E:ON and /V:ON options are not enabled in the batch script intepreter
    # See: http://stackoverflow.com/a/13751649/163740
    WITH_COMPILER: "cmd /E:ON /V:ON /C .\\appveyor\\run_with_compiler.cmd"

  matrix:
    - PYTHON: "C:\\Python27-x64"
      PYTHON_ARCH: "64"
      MINICONDA: C:\Miniconda-x64

    - PYTHON: "C:\\Python36-x64"
      PYTHON_ARCH: "64"
      MINICONDA: C:\Miniconda36-x64

      
install:
- ps: | # set env vars for versioning
    $env:COMM_TAG = $(git describe --tags $(git rev-list --tags --max-count=1))
    $env:COMM_COUNT = $(git rev-list --count HEAD)
    $env:COMM_HASH = $env:APPVEYOR_REPO_COMMIT.Substring(0,8)
    
    if ($env:APPVEYOR_PULL_REQUEST_NUMBER) {
        $env:BUILD = "rpcs3-{0}-{1}_win64.7z" -f $env:COMM_TAG, $env:COMM_HASH
        $env:AVVER = "{0}-{1}" -f $env:COMM_TAG.TrimStart("v"), $env:COMM_HASH
    }
    else {
        $env:BUILD = "rpcs3-{0}-{1}-{2}_win64.7z" -f $env:COMM_TAG, $env:COMM_COUNT, $env:COMM_HASH
        $env:AVVER = "{0}-{1}" -f $env:COMM_TAG.TrimStart("v"), $env:COMM_COUNT
    }

- ps: | # used for experimental build warnings for pr builds
    $env:BRANCH = "{0}/{1}/#{2}" -f $env:APPVEYOR_REPO_NAME, `
      $env:APPVEYOR_REPO_BRANCH, $env:APPVEYOR_PULL_REQUEST_NUMBER
    $env:BRANCH = $env:BRANCH -replace "/#$"

#- set "PATH=%PYTHON%;%PYTHON%\\Scripts;%PYTHON%\\Tools\\Scripts;%PATH%"
- cmd: set "PATH=%MINICONDA%;%MINICONDA%\\Scripts;%PATH%"
#- set VCINSTALLDIR="C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC"
- cmd: call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat"
- cmd: set CL=-FI"%VCINSTALLDIR%\INCLUDE\stdint.h"
- cmd: conda config --set always_yes yes --set changeps1 no
- cmd: conda config --add channels conda-forge
- cmd: conda config --add channels wheeler-microfluidics
- cmd: conda update -q conda
- cmd: conda info -a
- cmd: conda install --yes conda-build setuptools pip pytest-pylint parameterized cryptography
- cmd: conda install --yes pycryptodomex scrypt pyyaml pytest pytest-mock coverage mock appdirs
- cmd: conda install --yes ecdsa requests future websocket-client pytz six Click events prettytable pyinstaller


  # Upgrade to the latest version of pip to avoid it displaying warnings
  # about it being out of date.
  #- "pip install --disable-pip-version-check --user --upgrade pip"
  #- "python -m pip install -U pip setuptools"
  #- "pip install --user pycrypto Paramiko"
  # - "pip install --user --upgrade graphenelib"

build_script:
 # Build the compiled extension
- cmd: python setup.py build

test_script:
# Run the project tests
- cmd: py.test tests/beembase
- cmd: py.test tests/beemgraphene

after_test:
 # If tests are successful, create binary packages for the project.
- cmd: pyinstaller beempy-onedir.spec

# package artifacts
- cmd: copy /Y C:\OpenSSL-Win64\bin\libeay32.dll dist\beempy
- cmd: copy /Y C:\OpenSSL-Win64\bin\ssleay32.dll dist\beempy
- ps: 7z a beempy.zip %APPVEYOR_BUILD_FOLDER%\dist\beempy
- ps: 7z a -m0=LZMA2 -mx9 $env:BUILD %APPVEYOR_BUILD_FOLDER%\dist\beempy

- ps: | # generate sha256 hashes
    (get-filehash $env:BUILD -algorithm SHA256).Hash | out-file ("{0}.sha256" -f $env:BUILD) -encoding ascii
    (get-filehash beempy.zip -algorithm SHA256).Hash | out-file "beempy.zip.sha256" -encoding ascii 

artifacts:
  # Archive the generated packages in the ci.appveyor.com build report.
- path: $(BUILD)
  name: beempy
- path: $(BUILD).sha256
  name: beempy sha256 hash
- path: beempy.zip
  name: beempy_zip
- path: beempy.zip.sha256
  name: beempy_zip sha256 hash

on_finish: 
- ps: | # update appveyor build version, done last to prevent webhook breakage
    update-appveyorbuild -version $env:AVVER