Skip to content

Commit c4b1106

Browse files
Rebase branches on main
1 parent 9200096 commit c4b1106

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

.gitlab-ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ stages:
88
- release
99
- postrelease
1010
- deploy
11+
- rebase
1112
- docs
1213

1314
include:
@@ -32,6 +33,7 @@ include:
3233
- local: /.gitlab/ci/postrelease.gitlab-ci.yml
3334
- local: /.gitlab/ci/deploy.gitlab-ci.yml
3435
- local: /.gitlab/ci/docs.gitlab-ci.yml
36+
- local: /.gitlab/ci/rebase.gitlab-ci.yml
3537
- component: ${CI_SERVER_FQDN}/gitlab-org/components/danger-review/[email protected]
3638
inputs:
3739
job_stage: qa

.gitlab/ci/_rules.gitlab-ci.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@
5555
.if-runner-or-security-runner-stable-ref: &if-runner-or-security-runner-stable-ref
5656
if: $CI_COMMIT_REF_NAME =~ /\A[0-9]+-[0-9]+-stable\z/ && ($CI_PROJECT_PATH == "gitlab-org/gitlab-runner" || $CI_PROJECT_PATH == "gitlab-org/security/gitlab-runner")
5757

58+
.if-runner-or-security-runner-feature-ref: &if-runner-or-security-runner-feature-ref
59+
if: $CI_COMMIT_REF_NAME =~ /feature\/.+/ && ($CI_PROJECT_PATH == "gitlab-org/gitlab-runner" || $CI_PROJECT_PATH == "gitlab-org/security/gitlab-runner")
60+
5861
.if-runner-release-ref: &if-runner-release-ref
5962
if: $CI_COMMIT_REF_NAME =~ /\Av[0-9]+\.[0-9]+\.[0-9]+(-rc[0-9]+)?\z/ && $CI_PROJECT_PATH == "gitlab-org/gitlab-runner"
6063

@@ -94,6 +97,7 @@
9497
- <<: *if-merge-request-pipeline
9598
- <<: *if-runner-or-security-runner-default-branch
9699
- <<: *if-runner-or-security-runner-stable-ref
100+
- <<: *if-runner-or-security-runner-feature-ref
97101
- <<: *if-runner-release-ref
98102
- <<: *if-security-runner-release-ref
99103

@@ -105,6 +109,8 @@
105109
changes: *code-backstage-patterns
106110
- <<: *if-runner-or-security-runner-stable-ref
107111
changes: *code-backstage-patterns
112+
- <<: *if-runner-or-security-runner-feature-ref
113+
changes: *code-backstage-patterns
108114
- <<: *if-runner-release-ref
109115
changes: *code-backstage-patterns
110116
- <<: *if-security-runner-release-ref
@@ -120,6 +126,8 @@
120126
changes: *code-backstage-patterns
121127
- <<: *if-runner-or-security-runner-stable-ref
122128
changes: *code-backstage-patterns
129+
- <<: *if-runner-or-security-runner-feature-ref
130+
changes: *code-backstage-patterns
123131
- <<: *if-runner-release-ref
124132
changes: *code-backstage-patterns
125133
- <<: *if-security-runner-release-ref
@@ -175,6 +183,10 @@
175183
changes: *code-backstage-patterns
176184
- <<: *if-runner-bleeding-edge-release-ref
177185
changes: *code-backstage-patterns
186+
- <<: *if-runner-or-security-runner-stable-ref
187+
changes: *code-backstage-patterns
188+
- <<: *if-runner-or-security-runner-feature-ref
189+
changes: *code-backstage-patterns
178190

179191
.rules:release-or-security:bleeding-edge-or-stable:
180192
rules:
@@ -184,6 +196,8 @@
184196
changes: *code-backstage-patterns
185197
- <<: *if-runner-or-security-runner-stable-ref
186198
changes: *code-backstage-patterns
199+
- <<: *if-runner-or-security-runner-feature-ref
200+
changes: *code-backstage-patterns
187201

188202
.rules:release:stable-or-rc:
189203
rules:

.gitlab/ci/rebase.gitlab-ci.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Rebase branches in $REPO_REBASE_BRANCHES, separated by a comma on top of main
2+
rebase on main:
3+
stage: rebase
4+
rules:
5+
- if: $REPO_REBASE_BRANCHES != "" && $REPO_REBASE_BRANCHES != null && $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $CI_PROJECT_PATH == "gitlab-org/gitlab-runner"
6+
allow_failure: true
7+
script:
8+
- |
9+
git config --global user.email "[email protected]"
10+
git config --global user.name "GitLab Runner CI Rebase"
11+
12+
git fetch origin $CI_DEFAULT_BRANCH
13+
git checkout -B $CI_DEFAULT_BRANCH origin/$CI_DEFAULT_BRANCH
14+
15+
git remote add push-remote https://oauth2:${REPO_REBASE_PUSH_TOKEN}@${CI_SERVER_HOST}/${CI_PROJECT_PATH}.git
16+
17+
IFS=',' read -ra BRANCHES <<< "$REPO_REBASE_BRANCHES"
18+
for BRANCH in "${BRANCHES[@]}"; do
19+
echo "Processing branch: $BRANCH"
20+
21+
git fetch origin $BRANCH
22+
23+
git checkout $BRANCH
24+
25+
if ! git rebase $CI_DEFAULT_BRANCH; then
26+
echo "Rebase failed for branch $BRANCH"
27+
exit 1
28+
fi
29+
30+
# --force-with-lease doesn't work on shallow clones
31+
git push push-remote $BRANCH --force
32+
33+
git checkout $CI_DEFAULT_BRANCH
34+
done

0 commit comments

Comments
 (0)