name: Pipeline

on:
  workflow_call:

jobs:


  BuildDatabase:
    container: ubuntu:bionic

    runs-on: [self-hosted, Linux, X64]

    strategy:
      fail-fast: false
      matrix:
        family: ['artix7', 'zynq7', 'kintex7', 'spartan7']

    env:
      ALLOW_ROOT: true
      GHA_EXTERNAL_DISK: "tools"
      XILINX_LOCAL_USER_DATA: "no"

    steps:

      - uses: actions/checkout@v3
        with:
          submodules: recursive

      - name: Install
        run: |
          apt update
          apt install -y \
            bash bison build-essential ca-certificates clang-format cmake psmisc \
            colordiff coreutils git flex python3 python3-dev python3-venv xsltproc

      - name: Build
        run: make build --output-sync=target --warn-undefined-variables -j$(nproc)

      - name: Environment
        run: make env --output-sync=target --warn-undefined-variables

      - name: Run Test
        run: .github/workflows/scripts/db.sh
        env:
          XRAY_SETTINGS: ${{ matrix.family }}

      - uses: actions/upload-artifact@v3
        if: ${{ always() }}
        with:
          name: ${{ matrix.family }}
          path: |
            **/results*.gz
            **/plot_*.svg
            **/diff.html
            **/diff.json
            **/diff.patch
            **/*sponge_log.xml
            **/fuzzers/*.tgz
            **/database/${{ matrix.family }}/**"


  Tests:
    container: ubuntu:bionic

    runs-on: [self-hosted, Linux, X64]

    env:
      ALLOW_ROOT: true

    steps:

      - uses: actions/checkout@v3
        with:
          submodules: recursive

      - name: Install
        run: |
          apt update
          apt install -y \
            bash bison build-essential ca-certificates clang-format cmake psmisc \
            colordiff coreutils git flex python3 python3-dev python3-venv xsltproc

      - name: Build
        run: make build --output-sync=target --warn-undefined-variables -j$(nproc)

      - name: Environment
        run: make env --output-sync=target --warn-undefined-variables

      - name: Run Test
        run: make test --output-sync=target --warn-undefined-variables

      - uses: actions/upload-artifact@v3
        if: ${{ always() }}
        with:
          path: |
            **/results*.gz
            **/plot_*.svg
