name: "ci"

on:
  - "push"

jobs:
  unit-tests:
    runs-on: "windows-latest"
    strategy:
      matrix:
        python-version:
          - "2.7"

    steps:
    # Avoid letting Windows newlines confusing milksnake.
    - run: "git config --global core.autocrlf false"

    - uses: actions/checkout@v2
      with:
        fetch-depth: "0"

      # Get tags not fetched by the checkout action, needed for auto-versioning.
    - name: "Finish checkout"
      run: |
        git fetch --tags

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

    - name: "Upgrade Pip"
      run: |
        python -m pip install -v --upgrade pip

    - name: "Install CI Dependencies"
      run: |
        python -m pip install -v wheel

    - name: "Install ZKAPAuthorizer and dependencies"
      run: |
        # Get a Python 2 compatible version of setuptools_scm so that pip
        # doesn't install a Python 2 incompatible version for cbor2.  There's
        # always a chance cbor2 will help us out with a 5.2.1 that declares
        # the constraint for us:
        # https://github.com/agronholm/cbor2/issues/124
        pip install setuptools_scm<6
        python -m pip install -v ./[test]

    - name: "Dump Python Environment"
      run: |
        pip freeze

    - name: "Run Tests"
      env:
        MAGIC_FOLDER_HYPOTHESIS_PROFILE: "ci"
      run: |
        python -m coverage run --debug=config -m twisted.trial _zkapauthorizer

    - name: "Convert Coverage"
      run: |
        echo "Files:"
        dir
        echo "Combining"
        coverage combine
        echo "Reporting"
        coverage report
        echo "Converting to XML"
        coverage xml

    - uses: codecov/codecov-action@v1
      with:
        file: "./coverage.xml"
