Skip to content

Commit e6cd8bb

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

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,10 @@ crc: crc-start crc-build crc-deploy
186186
clean:
187187
rm -rf bin
188188

189+
.PHONY: sync
190+
sync:
191+
./scripts/sync.sh
192+
189193
.PHONY: help
190194
help: ## Display this help.
191195
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)

scripts/sync.sh

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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 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" upstream/master 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+
main() {
62+
add_remote
63+
fetch_remote
64+
new_candidate_branch
65+
candidates
66+
pop
67+
check_local_branch_commit_diff
68+
}
69+
70+
main

0 commit comments

Comments
 (0)