Files
ROS2_learn/.gitlab-ci.yml
T

84 lines
2.2 KiB
YAML

# GitLab CI 配置 - ROS2 项目自动 build + test
#
# 触发:
# - 推送到 master / develop
# - Merge Request
#
# 阶段:
# 1. lint - 静态检查(ruff + flake8 + cpp linter)
# 2. build - Docker 镜像 + colcon build
# 3. test - colcon test(全部包)
# 4. docs - (可选)生成 sphinx 文档
stages:
- lint
- build
- test
variables:
DOCKER_IMAGE: "ros2-humble-dev:latest"
DOCKER_COMPOSE_PROJECT: "ros2-ci"
PACKAGES: "py_pubsub cpp_pubsub py_srv py_action_demo cpp_robot_tf2 py_vision_demo py_params cpp_custom_interface py_lifecycle_composable cpp_qos_demo py_overlay_dds bringup"
# ---------- 共享缓存 ----------
.cache-template: &docker-cache
key: docker-cache
paths:
- docker/.cache/
# ---------- Lint ----------
lint:python:
stage: lint
image: python:3.10
before_script:
- pip install ruff flake8
script:
- ruff check src/ || true
- flake8 src/ --max-line-length=120 || true
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
- if: $CI_COMMIT_BRANCH == "master"
- if: $CI_COMMIT_BRANCH == "develop"
# ---------- Build ----------
build:docker:
stage: build
image: docker:24
services:
- docker:dind
variables:
DOCKER_TLS_CERTDIR: ""
DOCKER_HOST: tcp://docker:2375
before_script:
- docker info
script:
- docker compose -p ${DOCKER_COMPOSE_PROJECT} -f docker/docker-compose.yml build
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
- if: $CI_COMMIT_BRANCH == "master"
- if: $CI_COMMIT_BRANCH == "develop"
# ---------- Test ----------
test:colcon:
stage: test
image: ${DOCKER_IMAGE}
needs: ["build:docker"]
before_script:
- apt-get update -qq
- apt-get install -y --no-install-recommends colcon
script:
- source /opt/ros/humble/setup.bash
- cd /root/ros2_ws
- colcon build --symlink-install --packages-select ${PACKAGES}
- colcon test --packages-select ${PACKAGES}
- colcon test-result --verbose
artifacts:
when: always
paths:
- build/**/test_results/
- log/
expire_in: 7 days
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
- if: $CI_COMMIT_BRANCH == "master"
- if: $CI_COMMIT_BRANCH == "develop"