version: 1.0.{build}
image: 
  - Previous Ubuntu
  - Previous Visual Studio 2017

environment:
  AWS_DEFAULT_REGION: us-east-1
  SAM_CLI_DEV: 1
 
  matrix:

    - PYTHON_HOME: "C:\\Python36-x64"
      PYTHON_VERSION: '3.6.10'
      PYTHON_ARCH: '64'
      NOSE_PARAMETERIZED_NO_WARN: 1
      INSTALL_PY_37_PIP: 1
      INSTALL_PY_38_PIP: 1
      AWS_S3: 'AWS_S3_36'
      APPVEYOR_CONSOLE_DISABLE_PTY: true

    - PYTHON_HOME: "C:\\Python37-x64"
      PYTHON_VERSION: '3.7.7'
      PYTHON_ARCH: '64'
      RUN_SMOKE: 1
      NOSE_PARAMETERIZED_NO_WARN: 1
      INSTALL_PY_36_PIP: 1
      INSTALL_PY_38_PIP: 1
      AWS_S3: 'AWS_S3_37'
      APPVEYOR_CONSOLE_DISABLE_PTY: true

    - PYTHON_HOME: "C:\\Python38-x64"
      PYTHON_VERSION: '3.8.2'
      PYTHON_ARCH: '64'
      RUN_SMOKE: 1
      NOSE_PARAMETERIZED_NO_WARN: 1
      INSTALL_PY_36_PIP: 1
      INSTALL_PY_37_PIP: 1
      AWS_S3: 'AWS_S3_38'
      APPVEYOR_CONSOLE_DISABLE_PTY: true

for:
  - 
    matrix:
      only:
        - image: Previous Visual Studio 2017

    install:
      - "SET PATH=%PYTHON_HOME%;%PATH%"
      - "echo %PYTHON_HOME%"
      - "echo %PATH%"
      - "python --version"
      # Upgrade setuptools, wheel and virtualenv
      - "SET PATH=%PYTHON_HOME%;%PATH%"
      - "echo %PYTHON_HOME%"
      - "echo %PATH%"
      - "python -m pip install --upgrade setuptools wheel virtualenv"

      # Install AWS CLI Globally outside of a venv.
      - "pip install awscli"

      # Create new virtual environment and activate it
      - "rm -rf venv"
      - "python -m virtualenv venv"
      - "venv\\Scripts\\activate"
      - "python --version"

    build_script:
      # Activate virtualenv again on windows
      - "venv\\Scripts\\activate"
      - "python -c \"import sys; print(sys.executable)\""
      - "pip install -e \".[dev]\""

    test_script:
      # Activate virtualenv again on windows
      - "venv\\Scripts\\activate"
      - "pytest --cov samcli --cov-report term-missing --cov-fail-under 95 tests/unit"
      - "pylint --rcfile .pylintrc samcli"
      - "pytest -n 4 tests/functional"

  - 
    matrix:
      only:
        - image: Previous Ubuntu

    install:
      - sh: "gvm use go1.13"
      - sh: "echo $PATH"
      - sh: "ls /usr/"
      - sh: "JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64"
      - sh: "PATH=$JAVA_HOME/bin:$PATH"
      - sh: "source ${HOME}/venv${PYTHON_VERSION}/bin/activate"
      - sh: "rvm use 2.5"

      # Install latest gradle 
      - sh: "sudo apt-get -y remove gradle"
      - sh: "wget https://services.gradle.org/distributions/gradle-5.5-bin.zip -P /tmp"
      - sh: "sudo unzip -d /opt/gradle /tmp/gradle-*.zip"
      - sh: "PATH=/opt/gradle/gradle-5.5/bin:$PATH"

      # Install black
      - sh: "wget -O /tmp/black https://github.com/python/black/releases/download/19.10b0/black"
      - sh: "chmod +x /tmp/black"
      - sh: "/tmp/black --version"

      # Install AWS CLI
      - sh: "virtualenv aws_cli"
      - sh: "./aws_cli/bin/python -m pip install awscli"
      - sh: "PATH=$(echo $PWD'/aws_cli/bin'):$PATH"

      - sh: "sudo apt-get -y install python3.6"
      - sh: "sudo apt-get -y install python2.7"
      - sh: "sudo apt-get -y install python3.7"
      - sh: "sudo apt-get -y install python3.8"

      - sh: "which python3.8"
      - sh: "which python3.6"
      - sh: "which python3.7"
      - sh: "which python2.7"

      - sh: "PATH=$PATH:/usr/bin/python3.8:/usr/bin/python3.7"
      - sh: "curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py"

      - sh: "sudo apt-get -y install python3-distutils"
      - ps: "If ($env:INSTALL_PY_38_PIP) {python3.8 get-pip.py --user}"
      - ps: "If ($env:INSTALL_PY_37_PIP) {python3.7 get-pip.py --user}"
      - ps: "If ($env:INSTALL_PY_36_PIP) {python3.6 get-pip.py --user}"

    build_script:
      - "python -c \"import sys; print(sys.executable)\""
      - "pip install -e \".[dev]\""

    test_script:
      - "pytest --cov samcli --cov-report term-missing --cov-fail-under 95 tests/unit"
      - "pylint --rcfile .pylintrc samcli"
      - "pytest -n 4 tests/functional"

      # Runs only in Linux
      - sh: "pytest -vv tests/integration"
      - sh: "pytest -vv tests/regression"
      - sh: "/tmp/black --check setup.py tests samcli"

      # Set JAVA_HOME to java11
      - sh: "JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64"
      - sh: "pytest -vv tests/integration/buildcmd/test_build_cmd.py -k test_building_java11_in_process"

      # Smoke tests run in parallel - it runs on both Linux & Windows
      # Presence of the RUN_SMOKE envvar will run the smoke tests
      - ps: "If ($env:RUN_SMOKE) {pytest -n 4 -vv tests/smoke}"
