forked from envoyproxy/envoy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
api_mirror.sh
executable file
·46 lines (37 loc) · 1.61 KB
/
api_mirror.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
#!/bin/bash
set -e
CHECKOUT_DIR=../data-plane-api
if [ -z "$CIRCLE_PULL_REQUEST" ] && [ "$CIRCLE_BRANCH" == "master" ]
then
echo "Cloning..."
git clone [email protected]:envoyproxy/data-plane-api "$CHECKOUT_DIR"
git -C "$CHECKOUT_DIR" config user.name "data-plane-api(CircleCI)"
git -C "$CHECKOUT_DIR" config user.email [email protected]
git -C "$CHECKOUT_DIR" fetch
git -C "$CHECKOUT_DIR" checkout -B master origin/master
# Determine last envoyproxy/envoy SHA in envoyproxy/data-plane-api
MIRROR_MSG="Mirrored from https://github.com/envoyproxy/envoy"
LAST_ENVOY_SHA=$(git -C "$CHECKOUT_DIR" log --grep="$MIRROR_MSG" -n 1 | grep "$MIRROR_MSG" | \
tail -n 1 | sed -e "s#.*$MIRROR_MSG @ ##")
echo "Last mirrored envoyproxy/envoy SHA is $LAST_ENVOY_SHA"
# Compute SHA sequence to replay in envoyproxy/data-plane-api
SHAS=$(git rev-list --reverse "$LAST_ENVOY_SHA"..HEAD api/)
# For each SHA, hard reset, rsync api/ and generate commit in
# envoyproxy/data-plane-api
API_WORKING_DIR="../envoy-api-mirror"
git worktree add "$API_WORKING_DIR"
for sha in $SHAS
do
git -C "$API_WORKING_DIR" reset --hard "$sha"
COMMIT_MSG=$(git -C "$API_WORKING_DIR" log --format=%B -n 1)
QUALIFIED_COMMIT_MSG=$(echo -e "$COMMIT_MSG\n\n$MIRROR_MSG @ $sha")
rsync -acv --delete --exclude "ci/" --exclude ".*" --exclude LICENSE \
--exclude WORKSPACE \
"$API_WORKING_DIR"/api/ "$CHECKOUT_DIR"/
git -C "$CHECKOUT_DIR" add .
git -C "$CHECKOUT_DIR" commit -m "$QUALIFIED_COMMIT_MSG"
done
echo "Pushing..."
git -C "$CHECKOUT_DIR" push origin master
echo "Done"
fi