-
Notifications
You must be signed in to change notification settings - Fork 6
/
sync-feature-branches.yml
463 lines (434 loc) · 17.1 KB
/
sync-feature-branches.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
---
display:
background_image: ((background-image-url))
resource_types:
- name: slack-notification
type: registry-image
source:
repository: elpaasoci/slack-notification-resource
tag: v1.7.0-orange
- name: git-branch-heads
type: registry-image
source:
repository: elpaasoci/git-branch-heads-resource
tag: 328937aaa39f79661ce381295dd262d6803b0c8c
resources:
- name: failure-alert
icon: slack
type: slack-notification
source:
url: ((slack-webhook))
proxy: ((slack-proxy))
proxy_https_tunnel: ((slack-proxy-https-tunnel))
disable: ((slack-disable))
- name: features-or-wip-merged
icon: home-group
type: git
source:
uri: ((paas-templates-uri))
branch: ((paas-templates-merged-branch))
skip_ssl_verification: true
git_config:
- name: merge.renamelimit
value: 10000
- name: paas-templates-reference
icon: shield-home
type: git
source:
uri: ((paas-templates-uri))
branch: ((paas-templates-reference-branch))
skip_ssl_verification: true
git_config:
- name: merge.renamelimit
value: 10000
- name: paas-templates-features
icon: home-import-outline
type: git-branch-heads
source:
uri: ((paas-templates-uri))
branches: [((paas-templates-reference-branch)), WIP-*,wip-*,feature-*, Feature-*]
skip_ssl_verification: true
changed_only: false
- name: cf-ops-automation
icon: rocket
type: git
source:
uri: ((cf-ops-automation-uri))
branch: ((cf-ops-automation-branch))
tag_filter: ((cf-ops-automation-tag-filter))
skip_ssl_verification: true
jobs:
- name: init-wip-from-reference
build_log_retention:
builds: 30
serial_groups: [git]
plan:
- in_parallel:
- get: paas-templates-reference
attempts: 2
params: { submodules: none }
- put: features-or-wip-merged
attempts: 2
get_params: { submodules: none, depth: 1 }
params:
repository: paas-templates-reference
rebase: true
force: true
- name: update-merged-wip-features
build_log_retention:
builds: 30
serial_groups: [git]
plan:
- in_parallel:
- get: paas-templates-features
attempts: 5
params: { submodules: none }
trigger: true
version: every
- get: features-or-wip-merged
attempts: 5
params: { submodules: none }
- task: merge-commit
config:
image_resource:
type: registry-image
source:
repository: elpaasoci/git-ssh
tag: 4966e7c4847f39a6f349536c3a4f993b377e60c5
platform: linux
inputs:
- name: paas-templates-features
- name: features-or-wip-merged
outputs:
- name: rebased-wip
run:
path: /bin/ash
args:
- -ce
- |
git config --global advice.detachedHead false
git config --global merge.renamelimit 10000
if [ "$SKIP_SSL_VERIFICATION" = "true" ]; then
export GIT_SSL_NO_VERIFY=true
echo "Skipping ssl verification"
fi
echo "============================="
echo "Details about latest commit on $(cat paas-templates-features/.git/git-branch-heads-resource/branch)"
echo "Ref: $(cat paas-templates-features/.git/ref)"
echo "Message: $(cat paas-templates-features/.git/commit_message)"
echo "Committer: $(cat paas-templates-features/.git/committer)"
echo "============================="
cd paas-templates-features
echo "Latest commit on WIP branch (last 5 commits)"
git --no-pager log --oneline -n 5
cd ..
echo "============================="
cd features-or-wip-merged
echo "Details about latest commit on features-or-wip-merged"
echo "Ref: $(cat .git/ref)"
echo "Message: $(cat .git/commit_message)"
echo "Committer: $(cat .git/committer)"
echo "============================="
#git fetch
set +e
for i in {1..5}; do
git fetch origin $(cat ../paas-templates-features/.git/ref)
if [ $? -eq 0 ]; then
echo "Fetch successfull"
break;
fi
sleep_duration=$((i*30))
echo "Fetch failed - try $i - sleeping $sleep_duration"
sleep $sleep_duration
done
set -e
cd ..
git clone features-or-wip-merged rebased-wip
cd rebased-wip
echo "Cherry picking change"
#git cherry-pick --allow-empty --keep-redundant-commits -x $(cat ../paas-templates-features/.git/ref)
for i in $(git cherry HEAD $(cat ../paas-templates-features/.git/ref)|grep "+ "|cut -c3-); do
applied="0"
if [ -e commits-applied.lst ]; then
applied=$(grep $i commits-applied.lst|wc -l)
else
echo "commits-applied.lst does not exist"
fi
if [ "$applied" = "0" ]; then
echo "Appling missing commit: $i"
git cherry-pick --allow-empty --keep-redundant-commits -x $i
if [ "$?" = "0" ]; then
touch commits-applied.lst
echo "+ $i" >> commits-applied.lst
git add commits-applied.lst
git commit --amend --no-edit
else
echo "Cherry-pick error detected, skipping 'commits-applied.lst' update"
fi
else
echo "Already applied commit: $i"
fi
done
echo "============================="
echo "Latest commit on WIP branch (last 10 commits)"
git --no-pager log --oneline -n 10
echo "Checking diff with origin/$WIP_BRANCH"
diff_count=$(git diff origin/${WIP_BRANCH} |wc -l)
if [ "$diff_count" = "0" ]; then
echo "No difference detected with origin/$WIP_BRANCH, resetting"
git reset --hard origin/${WIP_BRANCH}
else
echo "Diff detected, keeping changes"
fi
params:
WIP_BRANCH: ((paas-templates-merged-branch))
SKIP_SSL_VERIFICATION: true
on_failure:
do:
- task: display-conficts
config:
image_resource:
type: registry-image
source:
repository: elpaasoci/git-ssh
tag: 4966e7c4847f39a6f349536c3a4f993b377e60c5
platform: linux
inputs:
- name: rebased-wip
- name: paas-templates-features
- name: features-or-wip-merged
outputs:
- name: slack-message
run:
path: /bin/ash
args:
- -c
- |
echo "============================="
echo "Details about latest commit on $(cat paas-templates-features/.git/git-branch-heads-resource/branch)"
echo "Ref: $(cat paas-templates-features/.git/ref)"
echo "Message: $(cat paas-templates-features/.git/commit_message)"
echo "Committer: $(cat paas-templates-features/.git/committer)"
echo "============================="
cd features-or-wip-merged
echo "Details about latest commit on features-or-wip-merged"
echo "Ref: $(cat .git/ref)"
echo "Message: $(cat .git/commit_message)"
echo "Committer: $(cat .git/committer)"
cd ..
cd rebased-wip
echo "============================="
echo "Latest commit on WIP branch (last 10 commits)"
git --no-pager log --oneline -n 10
echo "============================="
git --no-pager diff --diff-filter=U --exit-code
git --no-pager diff --diff-filter=U --exit-code > ../slack-message/git-diff
- put: failure-alert
params:
channel: ((slack-channel))
text: |
@here Branches conflict detected please check [[$BUILD_PIPELINE_NAME/$BUILD_JOB_NAME ($BUILD_NAME)]($ATC_EXTERNAL_URL/teams/$BUILD_TEAM_NAME/pipelines/$BUILD_PIPELINE_NAME/jobs/$BUILD_JOB_NAME/builds/$BUILD_NAME)].
```
$TEXT_FILE_CONTENT
```
text_file: slack-message/git-diff
icon_url: http://cl.ly/image/3e1h0H3H2s0P/concourse-logo.png
username: Concourse
- put: features-or-wip-merged
attempts: 5
get_params: { submodules: none, depth: 1 }
params:
repository: rebased-wip
rebase: true
- name: check-feature-branches-for-conflicts
build_log_retention:
builds: 30
plan:
- in_parallel:
- get: paas-templates-reference
params: { submodules: none }
- get: paas-templates-features
params: { submodules: none }
trigger: true
- get: cf-ops-automation
params: { submodules: none }
- task: reset-wip
file: cf-ops-automation/concourse/tasks/git_reset_wip.yml
input_mapping: {reference-resource: paas-templates-reference}
output_mapping: {updated-git-resource: paas-templates-features-reseted}
params:
GIT_BRANCH_FILTER: WIP-* wip-* feature-* Feature-*
SKIP_SSL_VERIFICATION: true
GIT_CHECKOUT_BRANCH: ((paas-templates-reference-branch))
on_failure:
do:
- task: display-conficts
config:
image_resource:
type: registry-image
source:
repository: elpaasoci/git-ssh
tag: 4966e7c4847f39a6f349536c3a4f993b377e60c5
platform: linux
inputs:
- name: paas-templates-features-reseted
- name: paas-templates-features
outputs:
- name: slack-message
run:
path: /bin/ash
args:
- -c
- |
# ls -l paas-templates-features/.git
echo "HEAD: "
cat paas-templates-features/.git/HEAD
echo "Short ref: "
cat paas-templates-features/.git/short_ref
echo "Committer"
cat paas-templates-features/.git/committer
cd paas-templates-features-reseted
git --no-pager diff --diff-filter=U --exit-code
git --no-pager diff --diff-filter=U --exit-code > ../slack-message/git-diff
- put: failure-alert
params:
channel: ((slack-channel))
text: |
@here Branches conflict detected please check [[$BUILD_PIPELINE_NAME/$BUILD_JOB_NAME ($BUILD_NAME)]($ATC_EXTERNAL_URL/teams/$BUILD_TEAM_NAME/pipelines/$BUILD_PIPELINE_NAME/jobs/$BUILD_JOB_NAME/builds/$BUILD_NAME)].
```
$TEXT_FILE_CONTENT
```
text_file: slack-message/git-diff
icon_url: http://cl.ly/image/3e1h0H3H2s0P/concourse-logo.png
username: Concourse
- name: recreate-features-wip-merged-branch
build_log_retention:
builds: 30
serial_groups: [git]
on_failure:
put: failure-alert
params:
channel: ((slack-channel))
text: Failed to run [[$BUILD_PIPELINE_NAME/$BUILD_JOB_NAME ($BUILD_NAME)]($ATC_EXTERNAL_URL/teams/$BUILD_TEAM_NAME/pipelines/$BUILD_PIPELINE_NAME/jobs/$BUILD_JOB_NAME/builds/$BUILD_NAME)].
icon_url: http://cl.ly/image/3e1h0H3H2s0P/concourse-logo.png
username: Concourse
plan:
- in_parallel:
- get: paas-templates-reference
params: { submodules: none }
- get: cf-ops-automation
params: { submodules: none }
- task: reset-and-squash-wip
input_mapping: {reference-resource: paas-templates-reference}
output_mapping: {updated-git-resource: paas-templates-features-hard-reseted}
config:
platform: linux
image_resource:
type: registry-image
source:
repository: elpaasoci/git-ssh
tag: 4966e7c4847f39a6f349536c3a4f993b377e60c5
inputs:
- name: reference-resource
- name: cf-ops-automation
outputs:
- name: updated-git-resource
- name: logs
run:
path: sh
args:
- -c
- |
set -o pipefail
set -e
git config --global user.email "$GIT_USER_EMAIL"
git config --global user.name "$GIT_USER_NAME"
git config --global merge.renamelimit "$GIT_MERGE_RENAMELIMIT"
git config --global advice.detachedHead false
FINAL_RELEASE_REPO=updated-git-resource
if [ "$SKIP_SSL_VERIFICATION" = "true" ]; then
export GIT_SSL_NO_VERIFY=true
echo "Skipping ssl verification"
fi
cd reference-resource || exit 1
URI=$(git remote get-url origin)
# shellcheck disable=SC2086
# we need GIT_BRANCH_FILTER to be expanded with spaces
current_heads=$(git ls-remote -h "$URI" ${GIT_BRANCH_FILTER} | sed 's/refs\/heads\///' | awk '{print $2, $1}' | sort)
cd ..
echo "selected branches list with associated commit id:"
DISPLAY_SEPARATOR="=================="
echo ${DISPLAY_SEPARATOR}
echo "${current_heads}"
echo ${DISPLAY_SEPARATOR}
git clone "${URI}" "${FINAL_RELEASE_REPO}"
cd ${FINAL_RELEASE_REPO} || exit 1
git checkout -B "${GIT_CHECKOUT_BRANCH}" -t "origin/${GIT_CHECKOUT_BRANCH}"
git_br=$(echo "${current_heads}" |awk '{ for (i=2;i<=NF;i+=2) $i=""; print}' )
echo "WIP Reset Complete" > .git/reset_branches
{
echo ""
echo "Restored branches:"
echo "${current_heads}"
} >> .git/reset_branches
echo "Commits applied:" > commits-applied.lst
for branch_name in ${git_br}; do
echo ${DISPLAY_SEPARATOR}
echo "Processing $branch_name"
git cherry HEAD "origin/${branch_name}" >> commits-applied.lst
git merge -m "Merge branch '$branch_name' after WIP reset [skip ci]" "origin/${branch_name}" 2>&1| tee -a ../logs/"$branch_name.log"
done
git reset origin/${GIT_CHECKOUT_BRANCH}
find . -maxdepth 5 -not \( -path "*.git" -prune \) -type d > .git/all_changed_dirs
echo "Changed dirs:"
cat .git/all_changed_dirs
# add timestamp to force triggering
cat .git/all_changed_dirs|sort |uniq > .git/changed_dirs
echo "Changed detected in the following dirs:"
cat .git/changed_dirs
echo ${DISPLAY_SEPARATOR}
date +'%Y-%m-%d-%H-%M-%S'|tee .git/.last-reset
while IFS= read -r aDir; do
if [ -d "${aDir}" ]; then
cp .git/.last-reset "${aDir}"
fi
done < .git/changed_dirs
echo "Adding changes to git"
git add .
git commit --file .git/reset_branches
params:
GIT_USER_NAME: "Orange Cloud Foundry SKC CI Server"
GIT_USER_EMAIL: "[email protected]"
GIT_BRANCH_FILTER: WIP-* wip-* feature-* Feature-*
GIT_CHECKOUT_BRANCH: ((paas-templates-reference-branch))
SKIP_SSL_VERIFICATION:
GIT_MERGE_RENAMELIMIT: 10000
params:
GIT_BRANCH_FILTER: WIP-* wip-* feature-* Feature-*
SKIP_SSL_VERIFICATION: true
GIT_CHECKOUT_BRANCH: ((paas-templates-reference-branch))
- put: features-or-wip-merged
get_params: { submodules: none, depth: 1 }
params:
repository: paas-templates-features-hard-reseted
force: true
- name: check-all-feature-branches-are-rebased-hard-reset
build_log_retention:
builds: 30
plan:
- in_parallel:
- get: paas-templates-reference
params: { submodules: none }
- get: features-or-wip-merged
passed: [recreate-features-wip-merged-branch]
trigger: true
params: { submodules: none }
- get: cf-ops-automation
params: { submodules: none }
- task: list-outdated-branches
input_mapping: {reference-resource: paas-templates-reference}
output_mapping: {updated-git-resource: paas-templates-features-reseted}
file: cf-ops-automation/concourse/tasks/git_rebase_status/task.yml
params:
GIT_BRANCH_FILTER: WIP-* wip-* feature-* Feature-*
SKIP_SSL_VERIFICATION: true