name: CI

on:
  pull_request:
    branches:
    - master
    - dev

jobs:
  presubmit:
    runs-on: ubuntu-latest
    steps:
    - name: Cancel previous
      uses: styfle/cancel-workflow-action@0.8.0
      with:
        access_token: ${{ github.token }}
    - uses: actions/checkout@v2
    - run: |  # Needed for presubmit to work.
        git fetch origin master --unshallow
        git symbolic-ref refs/remotes/origin/HEAD refs/remotes/origin/master

    - name: Setup Python environment
      uses: actions/setup-python@v2
      with:
        python-version: 3.10.8

    # Copied from:
    # https://docs.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions
    - name: Cache pip
      uses: actions/cache@v2
      with:
        # This path is specific to Ubuntu.
        path: ~/.cache/pip
        # Look to see if there is a cache hit for the corresponding requirements
        # file.
        key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }}
        restore-keys: |
          ${{ runner.os }}-pip-
          ${{ runner.os }}-

    - name: Install dependencies
      run: |
        make install-dependencies

    - name: Run presubmit checks
      run: |
        FUZZBENCH_TEST_INTEGRATION=1 make presubmit