variables:
  DOCKER_DRIVER: overlay2
  PACKAGES_LIST: tracetools_analysis ros2trace_analysis
  BASE_IMAGE_ID: registry.gitlab.com/ros-tracing/ci_base
  DISTRO: foxy
  ROS2TRACING_BRANCH: foxy

stages:
  - build_test
  - report

.global_artifacts: &global_artifacts
  artifacts:
    paths:
      - install
      - build/*/test_results/*/*.xunit.xml
      - build/*/pytest.xml
    reports:
      junit:
        - build/*/test_results/*/*.xunit.xml
        - build/*/pytest.xml

before_script:
  - . /root/ws/install/local_setup.sh
  - python3 get_branch.py --check
  - git clone https://gitlab.com/ros-tracing/ros2_tracing.git --branch $(python3 get_branch.py)

build:
  stage: build_test
  image: $BASE_IMAGE_ID:$DISTRO
  script:
    - colcon build --symlink-install --event-handlers console_cohesion+ --packages-up-to $PACKAGES_LIST
    - colcon test --event-handlers console_cohesion+ --packages-select $PACKAGES_LIST
    - colcon test-result --all
  <<: *global_artifacts

coverage:
  stage: report
  image: $BASE_IMAGE_ID:$DISTRO
  script:
    - colcon build --symlink-install --event-handlers console_cohesion+ --packages-up-to $PACKAGES_LIST --mixin coverage-pytest --cmake-args -DBUILD_TESTING=ON --no-warn-unused-cli
    - colcon test --event-handlers console_cohesion+ --packages-select $PACKAGES_LIST --mixin coverage-pytest
    - colcon test-result --all
    - bash <(curl -s https://codecov.io/bash)
    - colcon coveragepy-result --packages-select $PACKAGES_LIST --verbose --coverage-report-args -m
  allow_failure: true
  <<: *global_artifacts

trigger_gen_docs:
  stage: report
  only:
    refs:
      - master
      - foxy
  trigger: ros-tracing/tracetools_analysis-api
