name: Benchmarks

on: [push, pull_request]

jobs:
  vs-master:

    runs-on: ubuntu-latest

    steps:
    - name: Set up system
      shell: bash
      run: |
        bash <(wget -q -O- http://neuro.debian.net/_files/neurodebian-travis.sh)
        sudo apt-get update -qq
        sudo apt-get install eatmydata
        sudo eatmydata apt-get install git-annex-standalone
    - name: Set up environment
      run: |
        git config --global user.email "test@github.land"
        git config --global user.name "GitHub Almighty"
    - uses: actions/checkout@v1
    - name: Set up Python 3.7
      uses: actions/setup-python@v1
      with:
        python-version: 3.7
    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip
        pip install -r requirements.txt
        pip install ".[devel-docs]"
    - name: Run benchmarks
      env:
        # fake environment to be able to reuse script for travis
        TRAVIS_PULL_REQUEST: true
      run: |
        tools/ci/benchmark-travis-pr.sh
    - name: Compare
      run: |
        # Invocation from tools/ci/benchmark-travis-pr.sh for convenience
        asv compare refs/bm/merge-target refs/bm/pr
    - name: Fail if any benchmarks have slowed down too much
      run: |
        ! asv compare --factor 1.2 --split refs/bm/merge-target refs/bm/pr | grep -q "got worse"
