.gitlab-ci.yml 2 KB
Newer Older
1
2
3
4
5
stages:
  - checkRepository

RebaseCheck:
  stage: checkRepository
6
  image: alpine
7
  tags:
8
    - docker
9
10
11
12
13
14
15
16
17
18
  only:
    refs:
      - merge_requests
    variables:
      - $CI_MERGE_REQUEST_PROJECT_PATH == "CbmSoft/cbmroot_geometry" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "master"
  script:
    # Get the upstream repository manually. I did not find any other way to have it for
    # comparison
    # Check if a rebase is needed
    # If a rebase is needed stop immediately
19
    - apk update && apk add git bash
20
    - ci_scripts/connect_upstream_repo.sh $CI_MERGE_REQUEST_PROJECT_URL
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
    - git fetch upstream
    - hash1=$(git show-ref upstream/master | cut -f1 -d' ')
    - hash2=$(git merge-base upstream/master origin/$CI_MERGE_REQUEST_SOURCE_BRANCH_NAME)
    - echo "${hash1}"
    - echo "${hash2}"
    - if [ "${hash1}" = "${hash2}" ]; then
    -   echo "No rebase required"
    -   exit 0
    - else
    -   echo "The Merge Request is not up-to-date"
    -   echo "Rebase is required"
    -   exit 1
    - fi

LinearHistCheck:
  stage: checkRepository
37
  image: alpine
38
  tags:
39
    - docker
40
41
42
43
44
45
46
47
48
49
  only:
    refs:
      - merge_requests
    variables:
      - $CI_MERGE_REQUEST_PROJECT_PATH == "CbmSoft/cbmroot_geometry" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "master"
  script:
    # Get the upstream repository manually. I did not find any other way to have it for
    # comparison
    # Check if the history introduced by the MR is linear (no branch loop in fork)
    # If not linear stop immediately
50
    - apk update && apk add git bash
51
    - ci_scripts/connect_upstream_repo.sh $CI_MERGE_REQUEST_PROJECT_URL
52
53
54
55
56
57
58
59
60
61
62
    - git fetch upstream
    - count=$(git rev-list --min-parents=2 --count upstream/master..HEAD)
    - echo "${count}"
    - if [ 0 = "${count}" ]; then
    -   echo "History introduced in fork is linear"
    -   exit 0
    - else
    -   echo "History introduced in fork is not linear"
    -   echo "${count} merge commits must be removed or the other new commits have to be replayed in a new branch"
    -   exit 1
    - fi