Skip to content

Commit 49bc58d

Browse files
committed
Introduce a helper script for automating the upstream/downstream sync process
Signed-off-by: timflannagan <[email protected]>
1 parent 1fcee65 commit 49bc58d

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

scripts/sync.sh

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#! /bin/bash
2+
3+
set -o nounset
4+
set -o errexit
5+
set -o pipefail
6+
7+
ROOT_DIR=$(dirname "${BASH_SOURCE[0]}")/..
8+
# shellcheck disable=SC1091
9+
source "${ROOT_DIR}/scripts/common.sh"
10+
11+
SYNC_BRANCH_NAME="sync-$(printf '%(%Y-%m-%d)T\n' -1)"
12+
13+
add_remote() {
14+
echo "Adding upstream remotes if they don't already exist"
15+
git config remote.api.url >&- || git remote add api https://github.com/operator-framework/api
16+
git config remote.operator-registry.url >&- || git remote add api https://github.com/operator-framework/operator-registry
17+
git config remote.operator-lifecycle-manager.url >&- || git remote add api https://github.com/operator-framework/operator-lifecycle-manager
18+
git config remote.upstream.url >&- || git remote add upstream https://github.com/openshift/operator-framework-olm
19+
}
20+
21+
fetch_remote() {
22+
git fetch upstream
23+
24+
echo "Fetching upstream UPSTREAM_REMOTES"
25+
for remote in "${UPSTREAM_REMOTES[@]}"; do
26+
git fetch "$remote"
27+
done
28+
}
29+
30+
new_candidate_branch() {
31+
echo "Creating a sync branch if it doesn't already exist"
32+
git checkout -b "$SYNC_BRANCH_NAME" 2>/dev/null || git checkout "$SYNC_BRANCH_NAME"
33+
}
34+
35+
candidates() {
36+
# TODO: add support for only collecting a single remote.
37+
echo "Collecting all upstream commits since last sync"
38+
for remote in "${UPSTREAM_REMOTES[@]}"; do
39+
"${ROOT_DIR}"/scripts/sync_get_candidates.sh "$remote"
40+
done
41+
}
42+
43+
pop() {
44+
echo "Applying all upstream commit candidates"
45+
for remote in "${UPSTREAM_REMOTES[@]}"; do
46+
"${ROOT_DIR}"/scripts/sync_pop_candidate.sh "$remote" -a
47+
done
48+
}
49+
50+
check_local_branch_commit_diff() {
51+
commits_ahead=$(git rev-list upstream/master..HEAD | wc -l)
52+
53+
if [[ "$commits_ahead" -gt 1 ]]; then
54+
# TODO: automatically open a new pull request here.
55+
echo "The local sync branch is $commits_ahead commits ahead of the upstream/master branch"
56+
else
57+
echo "No sync PR is needed as the upstream/master branch is up-to-date"
58+
fi
59+
60+
}
61+
62+
main() {
63+
add_remote
64+
fetch_remote
65+
new_candidate_branch
66+
candidates
67+
pop
68+
check_local_branch_commit_diff
69+
}
70+
71+
main

0 commit comments

Comments
 (0)