Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / llvm / utils / git / sync-release-repo.sh
blob479407c65ed9bd2d39f926552e0cec874edd8c98
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)
23 # depth here must make sure to fetch enough history to make a merge,
24 # it's an arbritary value at this point. Consider using --shallow-since=
25 FETCH_OPTIONS="--prune --no-tags --progress --depth=100"
27 git remote add $MAIN_REMOTE "https://github.com/llvm/llvm-project"
28 git remote add $RELEASE_REMOTE "https://token:$GH_TOKEN@github.com/llvm/llvm-project-release-prs"
30 # Make sure we are up to date on all our repos first
31 git fetch $FETCH_OPTIONS $MAIN_REMOTE $RELEASE_BRANCH
32 git fetch $FETCH_OPTIONS $RELEASE_REMOTE $RELEASE_BRANCH
34 # Create our sync branch. Starting with the main
35 # repo first since it's important to get those
36 # changes
37 MERGE_BRANCH=$(uuidgen)
38 git switch -c $MERGE_BRANCH $MAIN_REMOTE/$RELEASE_BRANCH
40 # Merge changes from the release repo
41 git merge --ff-only $RELEASE_REMOTE/$RELEASE_BRANCH
43 if ! git diff-index --quiet $MAIN_REMOTE/$RELEASE_BRANCH; then
44 echo "Changes in the release remote - pushing to main remote"
45 git push $MAIN_REMOTE $MERGE_BRANCH:$RELEASE_BRANCH
48 # Before we merge back into the release repo
49 # let's update to make sure nothing has been
50 # pushed to either repo while we do this work.
51 # Most of the time this won't do anything, and
52 # the real solution would instead be to fetch
53 # in a loop if pushing fails. But that's a very
54 # tiny edge-case, so let's not complicate this.
55 git fetch $FETCH_OPTIONS $MAIN_REMOTE $RELEASE_BRANCH
56 git fetch $FETCH_OPTIONS $RELEASE_REMOTE $RELEASE_BRANCH
58 # And merge all the new data to the current branch
59 git merge --ff-only $MAIN_REMOTE/$RELEASE_BRANCH
61 # If anything changed let's merge it
62 if ! git diff-index --quiet $RELEASE_REMOTE/$RELEASE_BRANCH; then
63 echo "Changes in main - pushing to release"
64 # Remove the token stored by GH Actions, otherwise it
65 # won't use our own token in $GH_TOKEN
66 git config --unset-all http.https://github.com/.extraheader
67 git push $RELEASE_REMOTE $MERGE_BRANCH:$RELEASE_BRANCH
70 # Cleanup - enable for debug
71 if false; then
72 git remote remove $RELEASE_REMOTE
73 git remote remove $MAIN_REMOTE
75 git switch $CURRENT_BRANCH
76 git branch -D $MERGE_BRANCH