name: Mars Continuous Benchmark

on:
  pull_request:
    branches:
      - master
      - main

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

jobs:
  asv-benchmarks:
    name: ASV Benchmarks
    runs-on: ubuntu-latest
    defaults:
      run:
        shell: bash -l {0}

    concurrency:
      # https://github.community/t/concurrecy-not-work-for-push/183068/7
      group: ${{ github.event_name == 'push' && github.run_number || github.ref }}-asv-benchmarks
      cancel-in-progress: true

    steps:
      - name: Checkout
        uses: actions/checkout@v2
        with:
          fetch-depth: 0

      - name: Set up conda 3.8
        env:
          PYTHON: 3.8
        shell: bash
        run: |
          source ./ci/install-conda.sh
          python -m pip install --upgrade pip setuptools wheel coverage;

      - name: Install dependencies
        id: build
        run: |
          source ./ci/reload-env.sh
          export DEFAULT_VENV=$VIRTUAL_ENV
          pip install numpy scipy cython oss2 asv
          pip install -e ".[dev,extra]"

      - name: Run ASV benchmarks
        run: |
          source ./ci/reload-env.sh
          unset CI
          cd benchmarks/asv_bench
          git config --global user.email "mars_asv_benchmark@outlook.com"
          git config --global user.name "Mars ASV Benchmark"
          asv check -E existing
          git remote add upstream https://github.com/mars-project/mars.git
          git fetch upstream
          git merge upstream/master
          asv machine --yes
          asv continuous -e -f 1.1 --strict upstream/master HEAD
        if: ${{ steps.build.outcome == 'success' }}

      - name: Publish benchmarks artifact
        uses: actions/upload-artifact@v2
        with:
          name: Benchmarks log
          path: benchmarks/asv_bench/results
        if: failure()
