# vim: set shiftwidth=2 tabstop=2 softtabstop=-1 expandtab:
# DO NOT CHANGE the "init" and "install" sections below
#
# https://github.com/krlmlr/r-appveyor
# for many environment variables to configure

# Download script file from GitHub
init:
  ps: |
        $ErrorActionPreference = "Stop"
        Invoke-WebRequest http://raw.github.com/krlmlr/r-appveyor/master/scripts/appveyor-tool.ps1 -OutFile "..\appveyor-tool.ps1"
        Import-Module '..\appveyor-tool.ps1'

install:
  ps: Bootstrap

cache:
  - C:\RLibrary

before_build:
  - ls -aR
  - bash tools/dump-env.sh
  - rm .Rinstignore  # do install everything for testing
  - sed -i'' -e '/.*[Dd]ata.*/d' .Rbuildignore # do include data for testing, some data not in github though
  - bash -c 'tools/DESCRIPTION-minimalize.sh > DESC.min && cp DESCRIPTION DESC.orig && cp -f DESC.min DESCRIPTION;'

environment:
  global:
    APPVEYOR_SKIP_FINALIZE_ON_EXIT: true
    # env vars that may need to be set, at least temporarily, from time to time
    # see https://github.com/krlmlr/r-appveyor#readme for details
    NOT_CRAN: true
    WARNINGS_ARE_ERRORS: 0
    _R_CHECK_EXIT_ON_FIRST_ERROR_: true
    USE_RTOOLS: true
    R_BUILD_ARGS: "--no-manual --no-build-vignettes"
    R_CHECK_ARGS: "--no-manual --ignore-vignettes --no-build-vignettes"
    R_CHECK_ENVIRON: "tools/env/appveyor"
    # TODO: use an environment script in tools/env
    #_R_CHECK_FORCE_SUGGESTS_: false
    ICD_VERBOSE: true
    ICD_OFFLINE: true
    ICD_INTERACT: false
    # KEEP_VIGNETTES: ""
    # by default, don't set environment, to be more like CRAN?
    #  ICD_DATA_ABSENT_ACTION: 'message'
    #  R_REMOTES_STANDALONE: Set this to true if builds are failing due to the inability to update infrastructure packages such as curl, git2r and rlang. Read more in the docs for the remotes package.

  matrix:
    - R_VERSION: patched
      #MINI_BENCH: "no"

    - R_VERSION: release
      #MINI_BENCH: "no"

    - R_VERSION: devel
      #MINI_BENCH: "no"

platform:
  - x86
  - x64

matrix:
  fast_finish: true
  # allow_failures:
  #   - platform: x64
  #     MINI_BENCH: "yes"

build_script:
  - travis-tool.sh install_deps
  #- see https://github.com/craigcitro/r-travis/wiki#configuration-options
  #- travis-tool.sh install_github r-lib/covr

test_script:
  - travis-tool.sh run_tests

on_failure:
  - 7z a failure.zip *.Rcheck\*
  - appveyor PushArtifact failure.zip
  - exit 1 # with APPVEYOR_SKIP_FINALIZE_ON_EXIT: true, this should exit immediately

#on_finish:
#  - IF NOT "%MINI_BENCH%"=="yes" exit 0 # with APPVEYOR_SKIP_FINALIZE_ON_EXIT: true, this should exit immediately
#  - cd benchmarks/icd-JSS3447-replication && make bench3
  # - make replmat # needs to call the Rscript on appveyor path.
  # - cd ../.. && Rscript -e "covr::codecov()"

artifacts:
  - path: '*.Rcheck\**\*.log'
    name: Logs

  - path: '*.Rcheck\**\*.out'
    name: Logs

  - path: '*.Rcheck\**\*.fail'
    name: Logs

  - path: '*.Rcheck\**\*.Rout'
    name: Logs

  - path: '\*_*.tar.gz'
    name: Bits

  - path: '\*_*.zip'
    name: Bits

notifications:
  - provider: Email
    to:
      - appveyor@jackwasey.com
        #   subject: 'r-appveyor build {{status}}'                  # optional
        #   message: "https://ci.appveyor.com/project/krlmlr/r-appveyor"    # optional
    on_build_success: false
    on_build_failure: true
    on_build_status_changed: true
