name: sdl CI

on:
  push:
    paths-ignore:
      - "**.md"
      - "**.yml"
  pull_request:
    paths-ignore:
      - "**.md"
      - "**.yml"

concurrency:
  group: sdl-ci-${{ github.event.pull_request.number || github.sha }}
  cancel-in-progress: true

jobs:
  v-compiles-sdl-examples:
    runs-on: ubuntu-20.04
    if: github.event_name != 'push' || github.event.ref == 'refs/heads/master' || github.event.repository.full_name != 'vlang/v'
    timeout-minutes: 30
    env:
      VFLAGS: -cc tcc
    steps:
      - uses: actions/checkout@v3
      - name: Build V
        run: make && sudo ./v symlink

      - name: Clone sdl into .vmodules
        run: |
          git clone --depth 1 https://github.com/vlang/sdl
          cd sdl
          mkdir -p ~/.vmodules
          ln -s $(pwd) ~/.vmodules/sdl

      - name: Install dependencies
        run: |
          sudo apt-get update
          sudo apt-get install --quiet -y libsdl2-dev libsdl2-ttf-dev
          sudo apt-get install --quiet -y libsdl2-mixer-dev libsdl2-image-dev

      - name: Run tests
        run: ./v test sdl

      - name: Build sdl shared
        run: ./v -shared -g sdl

      - name: Build sdl examples
        run: |
          v shader sdl/examples/sdl_opengl_and_sokol
          v should-compile-all sdl/examples/