Blame


1 3e9e6cca 2022-07-04 thomas #!/bin/bash
2 3e9e6cca 2022-07-04 thomas #
3 3e9e6cca 2022-07-04 thomas # Script to sync changes from upstream to -portable
4 3e9e6cca 2022-07-04 thomas #
5 3e9e6cca 2022-07-04 thomas # This script is under the same licence as gameoftrees itself.
6 3e9e6cca 2022-07-04 thomas
7 3e9e6cca 2022-07-04 thomas die()
8 3e9e6cca 2022-07-04 thomas {
9 3e9e6cca 2022-07-04 thomas echo "$@" >&2
10 3e9e6cca 2022-07-04 thomas exit 1
11 3e9e6cca 2022-07-04 thomas }
12 3e9e6cca 2022-07-04 thomas
13 3e9e6cca 2022-07-04 thomas [ -z "$(git status --porcelain)" ] || die "Working tree is not clean"
14 3e9e6cca 2022-07-04 thomas
15 3e9e6cca 2022-07-04 thomas echo "Updating main from origin..."
16 3e9e6cca 2022-07-04 thomas
17 3e9e6cca 2022-07-04 thomas # Update our copy of main
18 3e9e6cca 2022-07-04 thomas git checkout -q main && \
19 3e9e6cca 2022-07-04 thomas git fetch -q -n upstream >/dev/null 2>&1 && \
20 3e9e6cca 2022-07-04 thomas git reset -q --hard upstream/main || {
21 3e9e6cca 2022-07-04 thomas die "Couldn't fetch from main and reset to that branch"
22 3e9e6cca 2022-07-04 thomas }
23 3e9e6cca 2022-07-04 thomas
24 3e9e6cca 2022-07-04 thomas # Gather a list of commits to cherry-pick.
25 3e9e6cca 2022-07-04 thomas # Don't proceed with no commits.
26 3e9e6cca 2022-07-04 thomas commitc="$(git rev-list --count main...origin/main)"
27 3e9e6cca 2022-07-04 thomas [ -z "$commitc" -o "$commitc" -eq 0 ] && {
28 3e9e6cca 2022-07-04 thomas echo "All commits uptodate. Nothing to cherry-pick"
29 3e9e6cca 2022-07-04 thomas exit
30 3e9e6cca 2022-07-04 thomas }
31 3e9e6cca 2022-07-04 thomas
32 3e9e6cca 2022-07-04 thomas # Create a branch from linux (which is where the result of the cherry-picks
33 3e9e6cca 2022-07-04 thomas # will ultimately end up, but we do this work on a topic branch so that we can
34 3e9e6cca 2022-07-04 thomas # perform CI on it, and not break the 'linux' branch.
35 3e9e6cca 2022-07-04 thomas
36 3e9e6cca 2022-07-04 thomas echo "Creating sync branch..."
37 3e9e6cca 2022-07-04 thomas git branch -q -D syncup >/dev/null 2>&1
38 3e9e6cca 2022-07-04 thomas git checkout -q linux && git checkout -q -b syncup || {
39 3e9e6cca 2022-07-04 thomas die "Can't checkout syncup branch"
40 3e9e6cca 2022-07-04 thomas }
41 3e9e6cca 2022-07-04 thomas
42 3e9e6cca 2022-07-04 thomas echo "The following ($commitc) commits will be cherry-picked..."
43 3e9e6cca 2022-07-04 thomas git log --oneline main...origin/main
44 3e9e6cca 2022-07-04 thomas
45 3e9e6cca 2022-07-04 thomas read -p "Proceed? [Y/n]: " resp
46 3e9e6cca 2022-07-04 thomas
47 3e9e6cca 2022-07-04 thomas [ "$resp" = "N" -o "$resp" = "n" ] && exit
48 3e9e6cca 2022-07-04 thomas
49 a8fa2ba8 2022-07-05 thomas # Pick the commits in reverse order.
50 a8fa2ba8 2022-07-05 thomas git rev-list --reverse --first-parent main...origin/main | \
51 a8fa2ba8 2022-07-05 thomas git cherry-pick --stdin --no-rerere-autoupdate -Xtheirs
52 3e9e6cca 2022-07-04 thomas
53 3e9e6cca 2022-07-04 thomas [ $? -eq 0 ] && {
54 c82e62cb 2022-07-04 thomas # Sanity-check header files which are found portably and remove them.
55 c82e62cb 2022-07-04 thomas for h in 'sys\/queue.h' 'ssl\.h' 'endian\.h'
56 c82e62cb 2022-07-04 thomas do
57 c82e62cb 2022-07-04 thomas # Use git's pathspec notation to exclude matching on files
58 c82e62cb 2022-07-04 thomas # where we *want* to keep those headers.
59 c82e62cb 2022-07-04 thomas git grep -Li "$h" -- \
60 c82e62cb 2022-07-04 thomas ':!maintscripts/**' \
61 c82e62cb 2022-07-04 thomas ':!configure.ac' \
62 c82e62cb 2022-07-04 thomas ':!gotweb/parse.y' \
63 c82e62cb 2022-07-04 thomas ':!include/got_compat.h' | \
64 c82e62cb 2022-07-04 thomas while read file
65 c82e62cb 2022-07-04 thomas do
66 c82e62cb 2022-07-04 thomas sed -i -e "/$h/d" "$file"
67 c82e62cb 2022-07-04 thomas done
68 c82e62cb 2022-07-04 thomas done
69 c82e62cb 2022-07-04 thomas
70 3e9e6cca 2022-07-04 thomas echo "Performing sanity build..."
71 3e9e6cca 2022-07-04 thomas ./autogen.sh >/dev/null 2>&1 && \
72 3e9e6cca 2022-07-04 thomas ./configure >/dev/null 2>&1 && \
73 3e9e6cca 2022-07-04 thomas make -j $(nproc) >/dev/null 2>&1 && {
74 3e9e6cca 2022-07-04 thomas echo " Passed!"
75 c82e62cb 2022-07-04 thomas echo "Creating commit for portable changes..."
76 c82e62cb 2022-07-04 thomas git commit -am "portable: remove include files found portably"
77 3e9e6cca 2022-07-04 thomas echo "...Merging branch to linux"
78 3e9e6cca 2022-07-04 thomas git checkout linux && git merge --ff-only - && {
79 3e9e6cca 2022-07-04 thomas echo "Pushing to GH..."
80 3e9e6cca 2022-07-04 thomas git push gh || die "Couldn't push linux to GH"
81 3e9e6cca 2022-07-04 thomas git checkout main && \
82 3e9e6cca 2022-07-04 thomas git push gh || die "Couldn't push main to GH"
83 3e9e6cca 2022-07-04 thomas }
84 3e9e6cca 2022-07-04 thomas } || die "Build failed"
85 3e9e6cca 2022-07-04 thomas }
86 3e9e6cca 2022-07-04 thomas
87 3e9e6cca 2022-07-04 thomas echo "Wait for Cirrus-CI..."
88 3e9e6cca 2022-07-04 thomas echo "Then push main and linux to origin"