-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.gitlab-ci.yml
87 lines (84 loc) · 3.49 KB
/
.gitlab-ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
variables:
GIT_CLONE_PATH: $CI_BUILDS_DIR/rover-soft
DEVELOP_IMAGE: $CI_REGISTRY_IMAGE/rover-soft:develop
MAIN_IMAGE: $CI_REGISTRY_IMAGE/rover-soft:stable
# This job is used to check the code.
# It invokes c++ and python linters checking for abidance to our coding guidelines.
# Then builds project checking for build errors.
#
# Uses build cache created by latest pipeline run on develop branch.
# This way we skip rebuilding majority of the packages (those that didn't change since branching from develop) each run.
#
# Different job is executed for the main branch, which doesn't use any cache.
run-code-checks:
image: $DEVELOP_IMAGE
cache:
key: ${CI_COMMIT_REF_SLUG}
paths:
- ccache
- build
- devel
stage: build
script:
# Prepare the environment:
- export CCACHE_BASEDIR="${CI_PROJECT_DIR}"
- export CCACHE_DIR="${CI_PROJECT_DIR}/ccache"
- export PATH="/usr/lib/ccache:$PATH"
- if ! ( test -d $CI_PROJECT_DIR/ccache && [ "$(ls -A $CI_PROJECT_DIR/ccache)" ] ); then
- cp -r /rover-soft/ccache $CI_PROJECT_DIR
- fi
- cd $CI_PROJECT_DIR
- apt-get update
- rosdep update
- rosdep install --from-paths src -iy
# Invoke linters:
- catkin_lint -W2 --output=explain --color=always src/
# Automatically format code
- curl https://raw.githubusercontent.com/Sarcasm/run-clang-format/master/run-clang-format.py | python3 - -r src --clang-format-executable clang-format-11
- if [[ -n $(find ./src/ -type f -name "*.py") ]] ; then yapf3 --diff --recursive --style ./.yapf-format ./src/ ; fi
# Try to build the project and save cache on success
- catkin build --cmake-args -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_CC_COMPILER_LAUNCHER=ccache
- ccache -s
except:
- main
# This job creates docker image based on develop branch and publishes it to project's container registry.
# The image is used as a base in run-code-checks job so that packages aren't rebuild if they didn't change.
#
# run-code-checks depends on image created by this job, but it is run after run-code-checks succeedes.
# This means that, when starting to use the pipeline, we need to manually create "first" image in the repository
# so that first stage can be run.
deploy-develop-image:
image: docker:20.10
services:
- docker:20.10-dind
variables:
DOCKER_DRIVER: overlay2
DOCKER_HOST: tcp://docker:2376
DOCKER_TLS_CERTDIR: "/certs"
stage: deploy
needs: [run-code-checks]
script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- docker build --pull -f ci/Dockerfile.develop -t $DEVELOP_IMAGE $GIT_CLONE_PATH
- docker push $DEVELOP_IMAGE
only:
- develop
# This job creates docker image based on main branch and publishes it to project's container registry.
# It doesn't use any cache and performs clean build, so it may take longer than other jobs.
deploy-main-image:
image: jdrouet/docker-with-buildx
services:
- docker:20.10-dind
variables:
DOCKER_DRIVER: overlay2
DOCKER_HOST: tcp://docker:2375
DOCKER_TLS_CERTDIR: ""
PLATFORM: linux/amd64,linux/arm64
stage: deploy
script:
- echo "$CI_REGISTRY_PASSWORD" | docker login $CI_REGISTRY --username $CI_REGISTRY_USER --password-stdin
- docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
- docker buildx create --use
- docker buildx build --push -f ci/Dockerfile.stable -t $MAIN_IMAGE --platform "$PLATFORM" --cache-from $MAIN_IMAGE --build-arg BUILDKIT_INLINE_CACHE=1 $GIT_CLONE_PATH
only:
- main