# AppVeyor CI for Windows

version: '{branch}-{build}'

pull_requests:
  do_not_increment_build_number: true

environment:
  matrix:
  - TARGET: vs2015
    APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
    VisualStudioVersion: 14.0
    platform: x86
    configuration: Release
    artifact_postfix: win32
  - TARGET: vs2015
    APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
    VisualStudioVersion: 14.0
    platform: x86
    configuration: Debug
  - TARGET: vs2015
    APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
    VisualStudioVersion: 14.0
    platform: x64
    configuration: Release
    artifact_postfix: win64
  - TARGET: vs2015
    APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
    VisualStudioVersion: 14.0
    platform: x64
    configuration: Debug
  - TARGET: cygwin

for:
-
  matrix:
    only:
    - TARGET: cygwin

  # Disable the installation of flex and bison packages. For some reason this
  # now (2021-04-19) upgrades the perl_base package to version 5.32.1-1 which
  # later fails with error:
  # Can't locate threads.pm in @INC (you may need to install the threads module)
  #
  # before_build:
  # - cmd: C:\cygwin64\setup-x86_64.exe --quiet-mode --no-desktop --no-shortcuts --no-startmenu --no-admin --packages flex,bison

  build_script:
  - cmd: C:\cygwin64\bin\bash -e -l -c "cd c:/projects/yara && ./build.sh"

  test_script:
  - cmd: C:\cygwin64\bin\bash -e -l -c "cd c:/projects/yara && make check"

-
  matrix:
    only:
      - TARGET: vs2015
      - configuration: Release

  before_build:
  - ps: nuget restore windows/vs2015/yara.sln

  build:
    project: windows/vs2015/yara.sln
    verbosity: minimal

  after_build:
  - cmd: 7z a yara-%APPVEYOR_BUILD_VERSION%-%ARTIFACT_POSTFIX%.zip %APPVEYOR_BUILD_FOLDER%\windows\%TARGET%\%CONFIGURATION%\yara*.exe

  artifacts:
  - path: yara-$(APPVEYOR_BUILD_VERSION)-$(ARTIFACT_POSTFIX).zip
    name: yara-$(APPVEYOR_BUILD_VERSION)-$(ARTIFACT_POSTFIX)
    type: zip

  deploy:
    tag: $(APPVEYOR_REPO_TAG_NAME)
    release: YARA $(APPVEYOR_REPO_TAG_NAME)
    provider: GitHub
    repository: VirusTotal/yara
    auth_token:
      secure: k+4xp4M/IEqXhKKYwo3DY2ko6VenOfSBEij3AasSiz1i8vsCwfcGxhuae0kj7Gj2
    artifact: yara-$(APPVEYOR_BUILD_VERSION)-$(ARTIFACT_POSTFIX)
    draft: true
    on:
      APPVEYOR_REPO_TAG: true        # deploy on tag push only

  test_script:
  - cmd: c:/projects/yara/windows/vs2015/%CONFIGURATION%/test-alignment.exe

-
  matrix:
    only:
      - TARGET: vs2015
      - configuration: Debug

  before_build:
  - ps: nuget restore windows/vs2015/yara.sln

  build:
    project: windows/vs2015/yara.sln
    verbosity: minimal

  test_script:
  - cmd: c:/projects/yara/windows/vs2015/%CONFIGURATION%/test-alignment.exe


# Uncomment the lines below for enabling Remote Desktop in the Appveyor. This
# allows connecting to the remote machine and debug issues.
# on_finish:
# - ps: $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1'))
