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