name: Regression tests
on:   [workflow_dispatch]

env:
   installDir: ${{ github.workspace }}/coriolis-2.x/Linux.x86_64/Release.Shared/install

jobs:
  Regression-Tests:
    runs-on: ubuntu-latest
    steps:
     - uses: actions/checkout@v3
       with:
         submodules: true
         path:       coriolis-2.x/src/coriolis
     - uses: actions/checkout@v3
       with:
         repository: lip6/alliance
         path:       coriolis-2.x/src/alliance
     - uses: actions/checkout@v3
       with:
         repository: lip6/alliance-check-toolkit
         path:       coriolis-2.x/src/alliance-check-toolkit
     - uses: actions/checkout@v3
       with:
         repository: YosysHQ/yosys
         path:       coriolis-2.x/src/yosys
         ref:        yosys-0.24
     - name: Update APT cache
       run: sudo apt-get update
     - name: Install software dependencies
       run: >
         sudo apt-get install libboost-all-dev rapidjson-dev \
                              python-dev-is-python3 python3-doit \
                              qtbase5-dev qtbase5-dev-tools libqt5svg5-dev libqwt-qt5-dev \
                              libeigen3-dev liblemon-dev \
                              autotools-dev automake \
                              libxt-dev libxpm-dev libmotif-dev \
                              tcl-dev libffi-dev
     - name: ccache
       uses: hendrikmuhs/ccache-action@v1.2
     - name: Build Yosys
       run: |
         export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH"
         cd ${{ github.workspace }}/coriolis-2.x/src/yosys
         make ENABLE_PYOSYS=1 config-gcc
         make ENABLE_PYOSYS=1 \
              PREFIX=${{ env.installDir }} \
              PYTHON_DESTDIR=${{ env.installDir }}/lib64/python3/dist-packages \
              LIBDIR=${{ env.installDir }}/lib64/yosys \
              DATDIR=${{ env.installDir }}/share/yosys \
              install
         sudo ln -s ${{ env.installDir }}/bin/* /usr/bin/
     - name: Check Yosys share directory
       run: ls -1 ${{ github.workspace }}/coriolis-2.x/Linux.x86_64/Release.Shared/install/share/yosys
     - name: Build Alliance
       run: |
         export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH"
         ${{ github.workspace }}/coriolis-2.x/src/coriolis/bootstrap/allianceInstaller.sh --github-runner=${{ github.workspace }}
     - name: Build Coriolis
       run: |
         export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH"
         ${{ github.workspace }}/coriolis-2.x/src/coriolis/bootstrap/ccb.py --root=${{ github.workspace }}/coriolis-2.x --project=coriolis --make="-j4 install"
     - name: Check for binaries
       run: ls -1 ${{ github.workspace }}/coriolis-2.x/Linux.x86_64/Release.Shared/install/bin
     - name: Run the reference set of designs
       run: |
         export CORIOLIS_TOP=${{ github.workspace }}/coriolis-2.x/Linux.x86_64/Release.Shared/install
         cd ${{ github.workspace }}/coriolis-2.x/src/alliance-check-toolkit/benchs
         ../bin/crlenv.py --verbose
         ../bin/gopy.sh --github-runner
#    - name: Bundle installed tree
#      uses: actions/upload-artifact@v3
#      with:
#        name: installed-tree
#        path: ${{ github.workspace }}/coriolis-2.x/Linux.x86_64/Release.Shared/install
#        retention-days: 1
     - name: Archive test design set logs
       uses: actions/upload-artifact@v3
       with:
         name: design-set-full-logs
         path: ${{ github.workspace }}/coriolis-2.x/src/alliance-check-toolkit/benchs/doit-gopy.log
         retention-days: 5
     - name: Make the runner fail *after* the log has been saved.
       run: |
          if [ -f ${{ github.workspace }}/coriolis-2.x/src/alliance-check-toolkit/benchs/doit-gopy.failed ]; then
            exit 1
          fi