-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdotweaks
103 lines (84 loc) · 4.4 KB
/
dotweaks
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/bin/sh
set -eux
export LOG_NAME="$(pwd)/vpp-daily-tweaks/RUN-LOG.md"
echo " - Started at $(date)" >"${LOG_NAME}"
export SECRET_GERRIT_KEY_FILE="$(pwd)/secret_gerrit_key"
export VPP_ROOT="$(pwd)/vpp"
export SAVE_DIR_ROOT="$(pwd)"
# $ echo -n | git hash-object --stdin
# e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
NO_CHANGE_HASH="e69de29bb2d1d6434b8b29ae775ad8c2e48c5391"
cd "${VPP_ROOT}"
git config user.name "GH Actions"
git config user.email "[email protected]"
cd "${SAVE_DIR_ROOT}"
# Go into the "volatile" copy of tweaks, possibly we will be modifying data
cd vpp-daily-tweaks/tweaks
for TWEAK_NAME in [0-9]*; do
echo " - Running tweak ${TWEAK_NAME}..." >>"${LOG_NAME}"
# run each tweak on its own vpp branch
BRANCH_NAME="ayourtch-${TWEAK_NAME}"
(cd "${VPP_ROOT}"; git branch -D "${BRANCH_NAME}" || true)
(cd "${VPP_ROOT}"; git checkout -b "${BRANCH_NAME}")
# get the last known hash of the diff seen and the last known change ID
SAVE_DIR_TWEAKS="$(pwd)"
cd "${TWEAK_NAME}"
LAST_HASH_FILENAME="$(pwd)/last-diff-hash"
CHANGE_ID_FILENAME="$(pwd)/last-change-id"
COMMIT_MSG_FILENAME="$(pwd)/commit-message"
# get the saved hash from previous time
if [ -f "${LAST_HASH_FILENAME}" ]; then
LAST_HASH="$(cat "${LAST_HASH_FILENAME}")"
echo "Last seen diff hash: ${LAST_HASH}"
else
LAST_HASH="${NO_CHANGE_HASH}"
echo "Not seen a diff before, so assign a 'no-diff' hash of ${LAST_HASH}"
fi
# what is the change ID that we have been working with before...
if [ -f "${CHANGE_ID_FILENAME}" ]; then
CHANGE_ID="$(cat "${CHANGE_ID_FILENAME}")"
echo "Last change id: ${CHANGE_ID}"
# check if it has been merged already and if so, pick a new one
if (cd "${VPP_ROOT}"; git log --grep="${CHANGE_ID}" | grep "${CHANGE_ID}"); then
CHANGE_ID=$( (whoami ; hostname ; date; echo $LAST_HASH) | git hash-object --stdin)
echo "Merged already, pick a new one: ${CHANGE_ID}"
fi
else
# no change ID submitted before, so pick a random new in case we have to
CHANGE_ID=$( (whoami ; hostname ; date; echo $LAST_HASH) | git hash-object --stdin)
echo "New change ID: ${CHANGE_ID}"
fi
TEMP_FILENAME="/tmp/change-${CHANGE_ID}"
bash action
cd "${SAVE_DIR_TWEAKS}"
# see if there is anything to submit
cd "${VPP_ROOT}"
CHANGE_HASH="$(git diff | git hash-object --stdin)"
if [ "${CHANGE_HASH}" != "${NO_CHANGE_HASH}" ] && [ "${CHANGE_HASH}" != "${LAST_HASH}" ]; then
# this is not an empty diff *and* it is not the same diff as we have last seen and submitted
# leave some trace in the version-controlled log
echo '```' >>"${LOG_NAME}"
echo "Found something to submit after ${TWEAK_NAME}:" >>"${LOG_NAME}"
git branch >> "${LOG_NAME}"
git diff >> "${LOG_NAME}"
echo '```' >>"${LOG_NAME}"
# fixup the commit message and save it into version-controlled space
git interpret-trailers --if-exists replace --trailer "Change-Id: I${CHANGE_ID}" < "${COMMIT_MSG_FILENAME}" >"${TEMP_FILENAME}"
mv "${TEMP_FILENAME}" "${COMMIT_MSG_FILENAME}"
git commit -a -F "${COMMIT_MSG_FILENAME}"
# Upload the new or updated change to gerrit
ssh-agent bash -c 'ssh-add "${SECRET_GERRIT_KEY_FILE}"; GIT_SSH_COMMAND="ssh -o StrictHostKeyChecking=no" git push fdio.origin HEAD:refs/for/master'
# save the state of the change in the to-be-updated tweaks repo and come back to VPP repo
cd "${SAVE_DIR_TWEAKS}"
echo "${CHANGE_HASH}" >"${LAST_HASH_FILENAME}"
git add "${LAST_HASH_FILENAME}"
echo "${CHANGE_ID}" >"${CHANGE_ID_FILENAME}"
git add "${CHANGE_ID_FILENAME}"
cd "${VPP_ROOT}"
fi
# reset back to master
git checkout -f master
cd "${SAVE_DIR_TWEAKS}"
done
cd "${SAVE_DIR_ROOT}"
echo " - Last done at $(date)" >>"${LOG_NAME}"