stages:          # List of stages for jobs, and their order of execution
  - build

build-job:       # This job runs in the build stage, which runs first.
  stage: build
  variables:
    BUILD_OPTIONS_DIRECTORY: "custom-fpga-design"
    BRANCH_UNDER_TEST: "develop"
  rules:
    - if: $CI_PIPELINE_SOURCE == "merge_request_event" && ($CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "main" || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "develop")
      variables:
        BUILD_OPTIONS_DIRECTORY: "build-options"
        BRANCH_UNDER_TEST: $CI_MERGE_REQUEST_SOURCE_BRANCH_NAME
    - if: $CI_PIPELINE_SOURCE == "push"
      variables:
        BUILD_OPTIONS_DIRECTORY: "custom-fpga-design"
        BRANCH_UNDER_TEST: $CI_COMMIT_BRANCH
        
  script:
    - echo "Cloning the tester and gateware..."
    - export
    - source ~/Microchip/Microchip-FPGA-Tools-Setup/setup-microchip-tools.sh
    - git clone https://git.beagleboard.org/beaglev-fire/gateware-builds-tester.git
    - cd gateware-builds-tester
    - git clone $CI_MERGE_REQUEST_SOURCE_PROJECT_URL -b $BRANCH_UNDER_TEST
    - echo "Building the gateware..."
    - python3 bitstream-builds-tester.py $BUILD_OPTIONS_DIRECTORY
    - echo "$CI_MERGE_REQUEST_SOURCE_BRANCH_NAME"
    - echo "$CI_MERGE_REQUEST_TARGET_BRANCH_NAME"
    - echo "Compile complete."
  artifacts:
    when: always
    paths:
      - gateware-builds-tester/artifacts/
    reports:
      junit: gateware-builds-tester/artifacts/tests_report.xml
