ros-industrial / industrial_ci

Easy continuous integration repository for ROS repositories
Apache License 2.0
248 stars 129 forks source link

GitLab templates #627

Open stertingen opened 3 years ago

stertingen commented 3 years ago

Recently I discovered the include feature of the GitLab CI. Building on this, I moved the configuration of ~20 repositories into a single one and added some includes:

my_ci_config.git/ros-industrial-base.yml

.ros-industrial-base:
  before_script:
    - apt-get -qq update && apt-get -qq install bash coreutils git grep # install industrial_ci dependencies
    - git config --add --global "url.${CI_SERVER_PROTOCOL}://gitlab-ci-token:${CI_JOB_TOKEN}@${CI_SERVER_HOST}:${CI_SERVER_PORT}/.insteadOf" "${CI_SERVER_URL}"
    - git config --add --global "url.${CI_SERVER_PROTOCOL}://gitlab-ci-token:${CI_JOB_TOKEN}@${CI_SERVER_HOST}:${CI_SERVER_PORT}/.insteadOf" "ssh://git@${CI_SERVER_HOST}:"
    - git config --add --global "url.${CI_SERVER_PROTOCOL}://gitlab-ci-token:${CI_JOB_TOKEN}@${CI_SERVER_HOST}:${CI_SERVER_PORT}/.insteadOf" "ssh://git@${CI_SERVER_HOST}/"
    - git clone --quiet --depth 1 https://github.com/ros-industrial/industrial_ci .industrial_ci -b master
  script: .industrial_ci/gitlab.sh
  variables:
    BASEDIR: ${CI_PROJECT_DIR}/workspaces
    CCACHE_DIR: "${CI_PROJECT_DIR}/ccache"
    ISOLATION: "shell"
  cache:
    # https://docs.gitlab.com/ee/ci/caching/#sharing-caches-across-different-branches
    key: "${CI_JOB_NAME}"
    paths:
      - ccache
  artifacts:
    when: always
    paths:
      - ${CI_PROJECT_DIR}/workspaces/**/log*/**/*.log
    reports:
      junit: ${CI_PROJECT_DIR}/workspaces/target_ws/**/test_results/**/*.xml

my_ci_config.git/ros-1.yml

ROS Kinetic:
  extends: .ros-industrial-base
  image: ros:kinetic

ROS Melodic:
  extends: .ros-industrial-base
  image: ros:melodic

ROS Noetic:
  extends: .ros-industrial-base
  image: ros:noetic

my_ci_config.git/clang-format.yml

clang-format:
  extends: .ros-industrial-base
  image: ros:noetic
  variables:
    CLANG_FORMAT_CHECK: "file"
    CLANG_FORMAT_VERSION: "8"

my_project.git/.gitlab-ci.yml

include:
  - project: my_ci_config.git'
    ref: master
    file:
      - 'ros-industrial-base.yml'
      - 'clang-format.yml'
      - 'ros-1.yml'

variables:
  CATKIN_LINT: "pedantic"
  UPSTREAM_WORKSPACE: ".rosinstall"

I think that working with these templates makes managing multiple repositories much easier and would propose providing such a template from the industrial CI.

mathias-luedtke commented 3 years ago

Ah, very nice!

would propose providing such a template from the industrial CI.

We could create a top-level gitlab folder that contains the different files. Especially, the base file is very helpful!