|
| 1 | +stages: |
| 2 | + - upstream_sync |
| 3 | + |
| 4 | +image: ${CI_DOCKER_REGISTRY}/llvm-build:5 |
| 5 | + |
| 6 | +default: |
| 7 | + interruptible: true |
| 8 | + |
| 9 | +variables: |
| 10 | + REBASE_PUSH_REMOTE: "https://gitlab-ci-token:${ESP_MAIN_MAINT_TOKEN}@${GITLAB_HTTPS_SERVER}/${CI_PROJECT_PATH}.git" |
| 11 | + |
| 12 | +workflow: |
| 13 | + rules: |
| 14 | + - if: $CI_PIPELINE_SOURCE == 'merge_request_event' |
| 15 | + - if: $CI_COMMIT_TAG |
| 16 | + - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH |
| 17 | + - if: $CI_PIPELINE_SOURCE == "schedule" && $SCHEDULE_TYPE == "rebase_on_main" |
| 18 | + - if: $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == $SCHED_REBASE_BR |
| 19 | + |
| 20 | +.use_ci_tools: &use_ci_tools | |
| 21 | + curl -sSL ${CIT_LOADER_URL} -o cit_loader.sh && sh cit_loader.sh |
| 22 | + source citools/import_functions |
| 23 | + |
| 24 | +.add_gitlab_key: &add_gitlab_key | |
| 25 | + cit_add_ssh_key "${GITLAB_KEY}" |
| 26 | + |
| 27 | +.rules:scheduled-rebase-on-main: |
| 28 | + rules: |
| 29 | + - if: $CI_PIPELINE_SOURCE == "schedule" && $SCHEDULE_TYPE == "rebase_on_main" |
| 30 | + variables: |
| 31 | + PUSH_RESULT: "ON" |
| 32 | + |
| 33 | +.rules:not-scheduled-rebase-on-main: |
| 34 | + rules: |
| 35 | + - if: $CI_PIPELINE_SOURCE != "schedule" || $SCHEDULE_TYPE != "rebase_on_main" |
| 36 | + |
| 37 | +before_script: |
| 38 | + - *use_ci_tools |
| 39 | + - *add_gitlab_key |
| 40 | + |
| 41 | +rebase_on_main: |
| 42 | + stage: upstream_sync |
| 43 | + extends: |
| 44 | + - .rules:scheduled-rebase-on-main |
| 45 | + tags: [ "amd64", "build" ] |
| 46 | + dependencies: [] |
| 47 | + variables: |
| 48 | + PUSH_RESULT: "OFF" |
| 49 | + script: |
| 50 | + - | |
| 51 | + set -euxo pipefail |
| 52 | + git config --global user.email "[email protected]" |
| 53 | + git config --global user.name "LLVM Project CI Rebase" |
| 54 | + GIT_DIR=$( git rev-parse --git-dir ) |
| 55 | + git fetch origin $SCHED_REBASE_ONTO_BR |
| 56 | + git remote add push-remote ${REBASE_PUSH_REMOTE} |
| 57 | + git remote -v |
| 58 | + BRANCH_NAME=${CI_COMMIT_REF_NAME} |
| 59 | + git branch -D $BRANCH_NAME || true |
| 60 | + git checkout -b $BRANCH_NAME |
| 61 | + rc=0 |
| 62 | + echo "Rebase branch '$BRANCH_NAME' on 'origin/$SCHED_REBASE_ONTO_BR'" |
| 63 | + if git rebase origin/$SCHED_REBASE_ONTO_BR ; then |
| 64 | + echo "Successfully rebased branch '$BRANCH_NAME'" |
| 65 | + if [[ "${PUSH_RESULT}" == "ON" ]]; then |
| 66 | + # --force-with-lease doesn't work on shallow clones |
| 67 | + echo "Push rebased branch '$BRANCH_NAME' to '$REBASE_PUSH_REMOTE'" |
| 68 | + git push push-remote $BRANCH_NAME --force |
| 69 | + else |
| 70 | + echo "Skip pushing rebased branch '$BRANCH_NAME'" |
| 71 | + fi |
| 72 | + else |
| 73 | + rc=$? |
| 74 | + echo "Rebasing branch '$BRANCH_NAME' on 'origin/$SCHED_REBASE_ONTO_BR' failed!" |
| 75 | + echo “Please rebase '$BRANCH_NAME' onto 'origin/$SCHED_REBASE_ONTO_BR' branch manually.” |
| 76 | + if [ -d "${GIT_DIR}/rebase-merge" ] || [ -d "${GIT_DIR}/rebase-apply" ] ; then |
| 77 | + echo "Abort rebase" |
| 78 | + git rebase --abort |
| 79 | + fi |
| 80 | + fi |
| 81 | + git status |
| 82 | + exit $rc |
0 commit comments