name: Scala CI

on: [push, pull_request]

jobs:
  build:
    runs-on: ubuntu-22.04
    timeout-minutes: 120

    steps:
    - uses: actions/checkout@v4
      with:
        submodules: 'recursive'

    - name: Set up JDK 11
      uses: actions/setup-java@v4
      with:
        java-version: '11'
        distribution: 'adopt'

    - name: Cache pip
      uses: actions/cache@v4
      with:
        path: ~/.cache/pip
        key: ${{ runner.os }}-pip-v4
        restore-keys: |
          ${{ runner.os }}-pip-

    - name: Cache SBT
      uses: actions/cache@v4
      with:
        path: |
          ~/.ivy2/cache
          ~/.sbt
        key: ${{ runner.os }}-sbt-${{ hashFiles('**/build.sbt') }}

    - name: Cache tools
      id: tools
      uses: actions/cache@v4
      with:
        path: |
          ~/tools
        key: ${{ runner.os }}-tools_v4

    - name: Setup env
      run: echo "$HOME/tools/bin" >> $GITHUB_PATH

    - name: Install cached tools
      if: steps.tools.outputs.cache-hit != 'true'
      run: source tools.sh && (cd ~/ && install_verilator)

    - name: Install uncached tools
      run: (cd .. && git clone https://github.com/SpinalHDL/SpinalHDL.git -b dev)

    - name: Compile tests
      run: sbt "+test:compile"

    - name: Test Dhrystones
      run: make regression_dhrystone -C scripts/regression

    - name: Test Baremetal
      run: make regression_random_baremetal -C scripts/regression

    - name: Test Machine OS
      run: make regression_random_machine_os -C scripts/regression

    - name: Test Linux
      run: make regression_random_linux -C scripts/regression

