-
Notifications
You must be signed in to change notification settings - Fork 597
64 lines (62 loc) · 2.36 KB
/
sync_cmakebuild.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
name: Sync cmakebuild with main
on:
schedule:
- cron: "0 * * * *" # At minute 0 every hour
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}
cancel-in-progress: true
env:
REPO: ${{ github.repository }}
TOKEN: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
jobs:
sync:
runs-on: ubuntu-latest
steps:
- name: Sync
run: |
mainsha=$(curl -s -H "Accept: application/vnd.github.VERSION.sha" https://api.github.com/repos/$REPO/commits/main)
echo "Main sha: ${mainsha}"
lastsha=$(curl -s https://raw.githubusercontent.com/$REPO/cmakebuild/ydb/ci/cmakegen.txt)
echo "Last sha: ${lastsha}"
if [ "${mainsha}" == "${lastsha}" ];then
echo "No new commits on the main branch to merge, exiting"
exit 0
fi
git clone -b main https://$TOKEN@github.com/$REPO.git ydb
git config --global user.email "alex@ydb.tech"
git config --global user.name "Alexander Smirnov"
cd ydb
git fetch --depth `expr $(git rev-list --count HEAD) + 1`
# Depth 10: 1st with cmake generation, 2nd with previous merge, 3rd is common between main and cmakebuild,
# others for possible commits directly on cmakebuild branch
git fetch origin cmakebuild:cmakebuild --depth 10
mainsha=$(git rev-parse HEAD)
git checkout cmakebuild
prevsha=$(git rev-parse HEAD)
conflicts_file=$(mktemp)
for i in $(seq 1 10);do
(git merge main --no-commit --no-ff main > $conflicts_file) | true
git reset HEAD --hard > /dev/null
git clean -fd > /dev/null
if [ -s $conflicts_file ];then
echo "Conflicts detected, trying to remove referenced CMakeLists* files"
grep -E -o '\s\S*CMakeLists\S*\s' $conflicts_file | xargs rm
git add .
git commit -m "Remove conflicted CMakeLists"
else
break
fi
done
git merge main --no-edit
currsha=$(git rev-parse HEAD)
if [ ${prevsha} == ${currsha} ];then
echo "Merge did not bring any changes, exiting"
exit
fi
# Generate cmakelists
./generate_cmake -k
echo ${mainsha} > ydb/ci/cmakegen.txt
git add .
git commit -m "Generate cmake for ${mainsha}"
git push --set-upstream origin cmakebuild