name: Pipeline

on:
  workflow_call:
    secrets:
      LICENSE_TUNNEL_KEY_DATA:
        required: false

jobs:


  BuildDatabase:
    container: ubuntu:focal

    runs-on: [self-hosted, Linux, X64]
    timeout-minutes: 600

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

    env:
      GHA_SSH_TUNNEL_KEY: "${{ secrets.LICENSE_TUNNEL_KEY_DATA }}"
      GHA_SSH_TUNNEL_CONFIG: "${{ secrets.LICENSE_TUNNEL_SSH_CONFIG }}"
      GHA_SSH_TUNNEL_CONFIG_SECRET_NAME: "xilinx_license_server_config"
      GHA_SSH_TUNNEL_KEY_SECRET_NAME: "xilinx_license_server_key"
      ALLOW_ROOT: true
      GHA_EXTERNAL_DISK: "tools"
      XILINX_LOCAL_USER_DATA: "no"

    steps:

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

      - name: Install
        run: |
          DEBIAN_FRONTEND=noninteractive apt update -qq
          DEBIAN_FRONTEND=noninteractive apt install -qq -y \
            bash \
            bison \
            build-essential \
            ca-certificates \
            clang-format \
            cmake \
            colordiff \
            coreutils \
            flex \
            git \
            iproute2 \
            iputils-ping \
            libtinfo5 \
            netcat-openbsd \
            psmisc \
            python3 \
            python3-dev \
            python3-venv \
            xsltproc \
            sudo \

      - name: Xilinx Setup
        run: |
          git config --global --add safe.directory /root/prjxray/prjxray
          .github/scripts/xilinx.sh
        env:
          USE_LICENSE_SERVER: "true"
          XRAY_SETTINGS: ${{ matrix.family }}

      - 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/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:focal

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

    env:
      ALLOW_ROOT: true

    steps:

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

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

      - 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
