name: CI

on: [push, pull_request]

jobs:
  build:
    name: "${{ matrix.name }}"
    runs-on: [ubuntu-latest]

    # We want to run on external PRs, but not on our own internal PRs as they'll be run
    # by the push to the branch.
    if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository

    strategy:
      fail-fast: false
      matrix:
        include:
          - name: default
            command: make -f misc/docker-ci.mk
          - name: openssl-3.0
            command: make -f misc/docker-ci.mk CONTAINER_NAME=h2oserver/h2o-ci:ubuntu2204
          - name: boringssl
            command: make -f misc/docker-ci.mk CONTAINER_NAME=h2oserver/h2o-ci:ubuntu2204 CMAKE_ARGS='-DOPENSSL_ROOT_DIR=/opt/boringssl'
          - name: asan
            command: make -f misc/docker-ci.mk CONTAINER_NAME=h2oserver/h2o-ci:ubuntu2204 CMAKE_ARGS='-DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_FLAGS=-fsanitize=address -DCMAKE_CXX_FLAGS=-fsanitize=address' CHECK_ENVS='ASAN_OPTIONS=detect_leaks=0'

    timeout-minutes: 10
    steps:
    - uses: actions/checkout@v2
      with:
        submodules: recursive
    - name: setup
      run: |
        sudo sysctl -w vm.mmap_rnd_bits=28 # new default is 32 that causes libasan crashes

    - name: Run with Docker
      shell: 'script -q -e -c "bash -xe {0}"'
      run: |
        chmod -R ugo+w .
        ${{ matrix.command }}
