[Workflow] Add Release Repo sync script
[llvm-project.git] / llvm / utils / git / sync-release-repo.sh
bloba8264b3bdeb1e85fa60917f21b7981183d365f29
1 #!/bin/bash
3 # This script will sync github.com/llvm/llvm-project with
4 # github.com/llvm/llvm-project-release-prs and try to merge
5 # the changes in the release branch.
7 set -e
8 set -x
10 # We should always get the branch from the environment.
11 # But otherwise just default to something. We can probably
12 # have a better default here?
13 RELEASE_BRANCH="${RELEASE_BRANCH:-release/16.x}"
15 # We will add two remotes here:
16 # main - which will point to the main llvm-project repo
17 # release - which will point to the release-prs repo
18 # The remotes will use random strings to avoid
19 # collisions
20 MAIN_REMOTE=$(uuidgen)
21 RELEASE_REMOTE=$(uuidgen)
22 CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
24 git remote add $MAIN_REMOTE "https://github.com/llvm/llvm-project"
25 git remote add $RELEASE_REMOTE "https://github.com/llvm/llvm-project-release-prs"
27 # Make sure we are up to date on all our repos first
28 git fetch $MAIN_REMOTE
29 git fetch $RELEASE_REMOTE
31 # Create our sync branch. Starting with the main
32 # repo first since it's important to get those
33 # changes
34 MERGE_BRANCH=$(uuidgen)
35 git switch -c $MERGE_BRANCH $MAIN_REMOTE/$RELEASE_BRANCH
37 # Merge changes from the release repo
38 git merge --ff-only $RELEASE_REMOTE/$RELEASE_BRANCH
40 if ! git diff-index --quiet $MAIN_REMOTE/$RELEASE_BRANCH; then
41 echo "Changes in the release remote - pushing to main remote"
42 git push $MAIN_REMOTE $MERGE_BRANCH:$RELEASE_BRANCH
45 # Before we merge back into the release repo
46 # let's update to make sure nothing has been
47 # pushed to either repo while we do this work.
48 # Most of the time this won't do anything, and
49 # the real solution would instead be to fetch
50 # in a loop if pushing fails. But that's a very
51 # tiny edge-case, so let's not complicate this.
52 git fetch $MAIN_REMOTE
53 git fetch $RELEASE_REMOTE
55 # And merge all the new data to the current branch
56 git merge --ff-only $MAIN_REMOTE/$RELEASE_BRANCH
58 # If anything changed let's merge it
59 if ! git diff-index --quiet $RELEASE_REMOTE/$RELEASE_BRANCH; then
60 echo "Changes in main - pushing to release"
61 git push $RELEASE_REMOTE $MERGE_BRANCH:$RELEASE_BRANCH
64 # Cleanup - enable for debug
65 if false; then
66 git remote remove $RELEASE_REMOTE
67 git remote remove $MAIN_REMOTE
69 git switch $CURRENT_BRANCH
70 git branch -D $MERGE_BRANCH