Skip to content

Commit 4173f2e

Browse files
authored
[Github Action] Enable automatic sync for main branch from llvm-project to llvm (#2904)
1 parent d44aa3f commit 4173f2e

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

.github/workflows/sync-main.yml

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: automatic sync main branch from llvm-project to llvm
2+
3+
on:
4+
schedule:
5+
- cron: '/10 * * * *'
6+
jobs:
7+
sync:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v2
11+
with:
12+
# persist-credentials: false allows us to use our own credentials for
13+
# pushing to the repository. Otherwise, the default github actions token
14+
# is used.
15+
persist-credentials: false
16+
fetch-depth: 0
17+
path: src
18+
- name: Sync
19+
env:
20+
BRANCH: main
21+
SYNC_REPO: https://github.com/llvm/llvm-project
22+
LLVMBOT_TOKEN: ${{ secrets.LLVM_MAIN_SYNC_BBSYCL_TOKEN }}
23+
run: |
24+
cd $GITHUB_WORKSPACE/src
25+
branch_exist=`git ls-remote --heads origin $BRANCH | wc -l`
26+
if [ $branch_exist -ne 0 ]; then
27+
git checkout $BRANCH
28+
git pull --ff --ff-only $SYNC_REPO $BRANCH
29+
if [ $? -ne 0 ]; then
30+
echo "failed to pull from $SYNC_REPO $BRANCH, abort"
31+
exit 1
32+
fi
33+
git_status=`git rev-list --count --left-right origin/$BRANCH...$BRANCH`
34+
if [ "0 0" == "$git_status" ] ; then
35+
echo "no change, skip"
36+
elif [[ "$git_status" = 0* ]] ; then
37+
git push https://$LLVMBOT_TOKEN@github.com/${{ github.repository }} ${BRANCH}
38+
else
39+
echo "$BRANCH branch invalid state"
40+
exit 1
41+
fi
42+
else
43+
git remote add upstream $SYNC_REPO
44+
git fetch upstream
45+
git checkout -B $BRANCH upstream/$BRANCH
46+
git push https://$LLVMBOT_TOKEN@github.com/${{ github.repository }} ${BRANCH}
47+
fi
48+
echo "sync finished"

0 commit comments

Comments
 (0)