{%- raw %}
name: Testing

on: [push, pull_request]

jobs:
  Pre-Commit:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - name: Set up Python
      uses: actions/setup-python@v1
      with:
        python-version: 3.7
    - name: Set Cache Key
      run: echo "PY=$(python --version --version | sha256sum | cut -d' ' -f1)" >> $GITHUB_ENV
    - name: Install System Deps
      run: |
        sudo apt-get update
        sudo apt-get install -y libxml2 libxml2-dev libxslt-dev
    - uses: actions/cache@v1
      with:
        path: ~/.cache/pre-commit
        key: pre-commit|${{ env.PY }}|${{ hashFiles('.pre-commit-config.yaml') }}
    - uses: pre-commit/action@v1.0.1

  Docs:
    runs-on: ubuntu-latest
    needs: Pre-Commit

    timeout-minutes: 10

    steps:
    - uses: actions/checkout@v2

    - name: Set up Python 3.7 For Nox
      uses: actions/setup-python@v1
      with:
        python-version: 3.7

    - name: Install Nox
      run: |
        python -m pip install --upgrade pip
        pip install nox

    - name: Install Doc Requirements
      run: |
        nox --force-color -e docs --install-only

    - name: Build Docs
      env:
        SKIP_REQUIREMENTS_INSTALL: YES
      run: |
        nox --force-color -e docs

  Linux:
    runs-on: ubuntu-latest
    needs: Pre-Commit

    timeout-minutes: 15

    strategy:
      fail-fast: false
      max-parallel: 4
      matrix:
        python-version:
          - 3.5
          - 3.6
          - 3.7
          - 3.8
        salt-version:
{%- endraw %}
          - {{ salt_version }}
{%- raw %}

    steps:
    - uses: actions/checkout@v2

    - name: Set up Python ${{ matrix.python-version }}
      uses: actions/setup-python@v1
      with:
        python-version: ${{ matrix.python-version }}

    - name: Install Nox
      run: |
        python -m pip install --upgrade pip
        pip install nox

    - name: Install Test Requirements
      env:
        SALT_REQUIREMENT: salt==${{ matrix.salt-version }}
      run: |
        nox --force-color -e tests-3 --install-only

    - name: Test
      env:
        SALT_REQUIREMENT: salt==${{ matrix.salt-version }}
        SKIP_REQUIREMENTS_INSTALL: YES
      run: |
        nox --force-color -e tests-3 -- -vv tests/

    - name: Create CodeCov Flags
      if: always()
      id: codecov-flags
      run: |
        echo ::set-output name=flags::$(python -c "import sys; print('{},{},salt_{}'.format('${{ runner.os }}'.replace('-latest', ''), 'py{}{}'.format(*sys.version_info), '_'.join(str(v) for v in '${{ matrix.salt-version }}'.replace('==', '_').split('.'))))")

    - name: Upload Project Code Coverage
      if: always()
      shell: bash
      env:
        CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
        REPORT_FLAGS: ${{ steps.codecov-flags.outputs.flags }},project
        REPORT_NAME: ${{ runner.os }}-Py${{ matrix.python-version }}-Salt${{ matrix.salt-version }}-project
        REPORT_PATH: artifacts/coverage-project.xml
      run: |
        if [ ! -f codecov.sh ]; then
          n=0
          until [ "$n" -ge 5 ]
          do
          if curl --max-time 30 -L https://codecov.io/bash --output codecov.sh; then
              break
          fi
            n=$((n+1))
            sleep 15
          done
        fi
        if [ -f codecov.sh ]; then
          n=0
          until [ "$n" -ge 5 ]
          do
            if bash codecov.sh -R $(pwd) -n "${REPORT_NAME}" -f "${REPORT_PATH}" -F "${REPORT_FLAGS}"; then
                break
            fi
            n=$((n+1))
            sleep 15
          done
        fi

    - name: Upload Tests Code Coverage
      if: always()
      shell: bash
      env:
        CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
        REPORT_FLAGS: ${{ steps.codecov-flags.outputs.flags }},tests
        REPORT_NAME: ${{ runner.os }}-Py${{ matrix.python-version }}-Salt${{ matrix.salt-version }}-tests
        REPORT_PATH: artifacts/coverage-tests.xml
      run: |
        if [ ! -f codecov.sh ]; then
          n=0
          until [ "$n" -ge 5 ]
          do
          if curl --max-time 30 -L https://codecov.io/bash --output codecov.sh; then
              break
          fi
            n=$((n+1))
            sleep 15
          done
        fi
        if [ -f codecov.sh ]; then
          n=0
          until [ "$n" -ge 5 ]
          do
            if bash codecov.sh -R $(pwd) -n "${REPORT_NAME}" -f "${REPORT_PATH}" -F "${REPORT_FLAGS}"; then
                break
            fi
            n=$((n+1))
            sleep 15
          done
        fi

    - name: Upload Logs
      if: always()
      uses: actions/upload-artifact@main
      with:
        name: runtests-${{ runner.os }}-py${{ matrix.python-version }}-Salt${{ matrix.salt-version }}.log
        path: artifacts/runtests-*.log

  Windows:
    runs-on: windows-latest
    needs: Pre-Commit

    timeout-minutes: 40

    strategy:
      fail-fast: false
      max-parallel: 3
      matrix:
        python-version:
          - 3.6
          - 3.7
        salt-version:
{%- endraw %}
          - {{ salt_version }}
{%- raw %}

    steps:
    - uses: actions/checkout@v2

    - name: Set up Python ${{ matrix.python-version }}
      uses: actions/setup-python@v1
      with:
        python-version: ${{ matrix.python-version }}

    - name: Install Nox
      run: |
        python -m pip install --upgrade pip
        pip install nox

    - name: Install Test Requirements
      shell: bash
      env:
        SALT_REQUIREMENT: salt==${{ matrix.salt-version }}
        EXTRA_REQUIREMENTS_INSTALL: Cython
      run: |
        export PATH="/C/Program Files (x86)/Windows Kits/10/bin/10.0.18362.0/x64;$PATH"
        nox --force-color -e tests-3 --install-only

    - name: Test
      shell: bash
      env:
        SALT_REQUIREMENT: salt==${{ matrix.salt-version }}
        SKIP_REQUIREMENTS_INSTALL: YES
      run: |
        export PATH="/C/Program Files (x86)/Windows Kits/10/bin/10.0.18362.0/x64;$PATH"
        nox --force-color -e tests-3 -- -vv tests/

    - name: Create CodeCov Flags
      if: always()
      id: codecov-flags
      run: |
        echo ::set-output name=flags::$(python -c "import sys; print('{},{},salt_{}'.format('${{ runner.os }}'.replace('-latest', ''), 'py{}{}'.format(*sys.version_info), '_'.join(str(v) for v in '${{ matrix.salt-version }}'.replace('==', '_').split('.'))))")

    - name: Upload Project Code Coverage
      if: always()
      shell: bash
      env:
        CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
        REPORT_FLAGS: ${{ steps.codecov-flags.outputs.flags }},project
        REPORT_NAME: ${{ runner.os }}-Py${{ matrix.python-version }}-Salt${{ matrix.salt-version }}-project
        REPORT_PATH: artifacts/coverage-project.xml
      run: |
        if [ ! -f codecov.sh ]; then
          n=0
          until [ "$n" -ge 5 ]
          do
          if curl --max-time 30 -L https://codecov.io/bash --output codecov.sh; then
              break
          fi
            n=$((n+1))
            sleep 15
          done
        fi
        if [ -f codecov.sh ]; then
          n=0
          until [ "$n" -ge 5 ]
          do
            if bash codecov.sh -R $(pwd) -n "${REPORT_NAME}" -f "${REPORT_PATH}" -F "${REPORT_FLAGS}"; then
                break
            fi
            n=$((n+1))
            sleep 15
          done
        fi

    - name: Upload Tests Code Coverage
      if: always()
      shell: bash
      env:
        CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
        REPORT_FLAGS: ${{ steps.codecov-flags.outputs.flags }},tests
        REPORT_NAME: ${{ runner.os }}-Py${{ matrix.python-version }}-Salt${{ matrix.salt-version }}-tests
        REPORT_PATH: artifacts/coverage-tests.xml
      run: |
        if [ ! -f codecov.sh ]; then
          n=0
          until [ "$n" -ge 5 ]
          do
          if curl --max-time 30 -L https://codecov.io/bash --output codecov.sh; then
              break
          fi
            n=$((n+1))
            sleep 15
          done
        fi
        if [ -f codecov.sh ]; then
          n=0
          until [ "$n" -ge 5 ]
          do
            if bash codecov.sh -R $(pwd) -n "${REPORT_NAME}" -f "${REPORT_PATH}" -F "${REPORT_FLAGS}"; then
                break
            fi
            n=$((n+1))
            sleep 15
          done
        fi

    - name: Upload Logs
      if: always()
      uses: actions/upload-artifact@main
      with:
        name: runtests-${{ runner.os }}-py${{ matrix.python-version }}-Salt${{ matrix.salt-version }}.log
        path: artifacts/runtests-*.log

  macOS:
    runs-on: macOS-latest
    needs: Pre-Commit

    timeout-minutes: 40

    strategy:
      fail-fast: false
      max-parallel: 3
      matrix:
        python-version:
          - 3.5
          - 3.6
          - 3.7
          - 3.8
        salt-version:
{%- endraw %}
          - {{ salt_version }}
{%- raw %}

    steps:
    - uses: actions/checkout@v2

    - name: Set up Python ${{ matrix.python-version }}
      uses: actions/setup-python@v1
      with:
        python-version: ${{ matrix.python-version }}

    - name: Install Nox
      run: |
        python -m pip install --upgrade pip
        pip install nox

    - name: Install Test Requirements
      env:
        SALT_REQUIREMENT: salt==${{ matrix.salt-version }}
      run: |
        nox --force-color -e tests-3 --install-only

    - name: Test
      env:
        SALT_REQUIREMENT: salt==${{ matrix.salt-version }}
        SKIP_REQUIREMENTS_INSTALL: YES
      run: |
        nox --force-color -e tests-3 -- -vv tests/

    - name: Create CodeCov Flags
      if: always()
      id: codecov-flags
      run: |
        echo ::set-output name=flags::$(python -c "import sys; print('{},{},salt_{}'.format('${{ runner.os }}'.replace('-latest', ''), 'py{}{}'.format(*sys.version_info), '_'.join(str(v) for v in '${{ matrix.salt-version }}'.replace('==', '_').split('.'))))")

    - name: Upload Project Code Coverage
      if: always()
      shell: bash
      env:
        CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
        REPORT_FLAGS: ${{ steps.codecov-flags.outputs.flags }},project
        REPORT_NAME: ${{ runner.os }}-Py${{ matrix.python-version }}-Salt${{ matrix.salt-version }}-project
        REPORT_PATH: artifacts/coverage-project.xml
      run: |
        if [ ! -f codecov.sh ]; then
          n=0
          until [ "$n" -ge 5 ]
          do
          if curl --max-time 30 -L https://codecov.io/bash --output codecov.sh; then
              break
          fi
            n=$((n+1))
            sleep 15
          done
        fi
        if [ -f codecov.sh ]; then
          n=0
          until [ "$n" -ge 5 ]
          do
            if bash codecov.sh -R $(pwd) -n "${REPORT_NAME}" -f "${REPORT_PATH}" -F "${REPORT_FLAGS}"; then
                break
            fi
            n=$((n+1))
            sleep 15
          done
        fi

    - name: Upload Tests Code Coverage
      if: always()
      shell: bash
      env:
        CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
        REPORT_FLAGS: ${{ steps.codecov-flags.outputs.flags }},tests
        REPORT_NAME: ${{ runner.os }}-Py${{ matrix.python-version }}-Salt${{ matrix.salt-version }}-tests
        REPORT_PATH: artifacts/coverage-tests.xml
      run: |
        if [ ! -f codecov.sh ]; then
          n=0
          until [ "$n" -ge 5 ]
          do
          if curl --max-time 30 -L https://codecov.io/bash --output codecov.sh; then
              break
          fi
            n=$((n+1))
            sleep 15
          done
        fi
        if [ -f codecov.sh ]; then
          n=0
          until [ "$n" -ge 5 ]
          do
            if bash codecov.sh -R $(pwd) -n "${REPORT_NAME}" -f "${REPORT_PATH}" -F "${REPORT_FLAGS}"; then
                break
            fi
            n=$((n+1))
            sleep 15
          done
        fi

    - name: Upload Logs
      if: always()
      uses: actions/upload-artifact@main
      with:
        name: runtests-${{ runner.os }}-py${{ matrix.python-version }}-Salt${{ matrix.salt-version }}.log
        path: artifacts/runtests-*.log
{%- endraw %}
