-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_upstream_patch.sh
executable file
·61 lines (51 loc) · 1.85 KB
/
generate_upstream_patch.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
#!/bin/bash
set -eo pipefail
cleanup() {
rm -rf "$1"
echo "cleaned up $1"
}
# This script generates a patch for the diffs between commit-A and commit-B
# of the upstream repo (https://github.com/integritee-network/worker), where
# commit-A: the commit recorded in tee-worker/upstream_commit
# commit-B: the HEAD commit of upstream master or a given commit
#
# The patch will be generated under tee-worker/upstream.patch
# to apply this patch:
# git am -3 --exclude=Cargo.lock --exclude=enclave-runtime/Cargo.lock < upstream.patch
UPSTREAM="[email protected]:zTgx/upstream.git"
ROOTDIR=$(git rev-parse --show-toplevel)
echo "$ROOTDIR"
cd "$ROOTDIR"
if [ -f upstream_commit ]; then
OLD_COMMIT=$(head -1 upstream_commit)
else
echo "Can't find upstream_commit file, quit"
exit 1
fi
echo "$OLD_COMMIT"
if [ "$(git remote get-url upstream 2>/dev/null)" != "$UPSTREAM" ]; then
echo "please set your upstream origin to $UPSTREAM"
exit 1
else
git fetch -q upstream
fi
TMPDIR=$(mktemp -d)
trap 'cleanup "$TMPDIR"' ERR EXIT INT
cd "$TMPDIR"
echo "cloning $UPSTREAM ..."
git clone -q "$UPSTREAM" worker
cd worker
[ ! -z "$1" ] && git checkout "$1"
echo "generating patch ..."
git diff $OLD_COMMIT HEAD > "$ROOTDIR/upstream.patch"
git rev-parse --short HEAD > "$ROOTDIR/upstream_commit"
echo "======================================================================="
echo "upstream_commit is updated."
echo "be sure to fetch the upstream to update the hashes of files."
echo "upstream.patch is generated, to apply it, run:"
echo ' git am -3 --exclude=Cargo.lock --exclude=enclave-runtime/Cargo.lock < upstream.patch'
echo "after that, please:"
echo "- resolve any conflicts"
echo "- optionally update both Cargo.lock files"
echo "- apply the changes to <root-dir>/.github/workflows/tee-worker-ci.yml"
echo "======================================================================="