2021-12-06 19:49:32 +00:00
|
|
|
#!/bin/bash
|
|
|
|
# Copyright 2021 The Chromium OS Authors. All rights reserved.
|
|
|
|
# Use of this source code is governed by a BSD-style license that can be
|
|
|
|
# found in the LICENSE file.
|
|
|
|
set -e
|
|
|
|
cd "${KOKORO_ARTIFACTS_DIR}/git/crosvm"
|
|
|
|
|
|
|
|
ORIGIN=https://chromium.googlesource.com/chromiumos/platform/crosvm
|
|
|
|
RETRIES=3
|
|
|
|
|
|
|
|
gerrit_prerequisites() {
|
|
|
|
set -e
|
|
|
|
|
|
|
|
# Authenticate to GoB if we don't already have a cookie.
|
|
|
|
# This should only happen when running in Kokoro, not locally.
|
|
|
|
# See: go/gob-gce
|
|
|
|
if [[ -z $(git config http.cookiefile) ]]; then
|
|
|
|
git clone https://gerrit.googlesource.com/gcompute-tools \
|
|
|
|
"${KOKORO_ARTIFACTS_DIR}/gcompute-tools"
|
|
|
|
"${KOKORO_ARTIFACTS_DIR}/gcompute-tools/git-cookie-authdaemon" --no-fork
|
|
|
|
fi
|
|
|
|
|
|
|
|
# We cannot use the original origin that kokoro used, as we no longer have
|
|
|
|
# access the GoB host via rpc://.
|
|
|
|
git remote remove origin
|
|
|
|
git remote add origin ${ORIGIN}
|
|
|
|
git fetch -q origin
|
|
|
|
|
|
|
|
# Set up gerrit Change-Id hook.
|
|
|
|
mkdir -p .git/hooks
|
|
|
|
curl -Lo .git/hooks/commit-msg \
|
|
|
|
https://gerrit-review.googlesource.com/tools/hooks/commit-msg
|
|
|
|
chmod +x .git/hooks/commit-msg
|
|
|
|
}
|
|
|
|
|
|
|
|
upload() {
|
2021-12-07 20:30:06 +00:00
|
|
|
git push origin HEAD:refs/for/chromeos%r=crosvm-uprev@google.com
|
|
|
|
}
|
|
|
|
|
|
|
|
upload_with_retries() {
|
2021-12-06 19:49:32 +00:00
|
|
|
# Try uploading to gerrit. Retry due to errors on first upload.
|
|
|
|
# See: b/209031134
|
|
|
|
for i in $(seq 1 $RETRIES); do
|
|
|
|
echo "Push attempt $i"
|
2021-12-07 20:30:06 +00:00
|
|
|
if upload; then
|
2021-12-06 19:49:32 +00:00
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
main() {
|
|
|
|
set -e
|
|
|
|
gerrit_prerequisites
|
|
|
|
|
2021-12-07 20:30:06 +00:00
|
|
|
# Make a copy of the merge script, so we are using the HEAD version to
|
|
|
|
# create the merge.
|
|
|
|
cp ./tools/chromeos/create_merge "${KOKORO_ARTIFACTS_DIR}/create_merge"
|
|
|
|
|
2021-12-07 20:55:45 +00:00
|
|
|
# Clean possible stray files from previous builds.
|
|
|
|
git clean -f -d -x
|
|
|
|
git checkout -f
|
|
|
|
|
2021-12-06 19:49:32 +00:00
|
|
|
# Perform merge on a tracking branch.
|
2021-12-07 20:30:06 +00:00
|
|
|
git checkout -b chromeos origin/chromeos
|
2021-12-06 19:49:32 +00:00
|
|
|
git branch --set-upstream-to origin/chromeos chromeos
|
2021-12-07 20:30:06 +00:00
|
|
|
"${KOKORO_ARTIFACTS_DIR}/create_merge"
|
2021-12-06 19:49:32 +00:00
|
|
|
|
2021-12-07 20:30:06 +00:00
|
|
|
upload_with_retries
|
2021-12-06 19:49:32 +00:00
|
|
|
}
|
|
|
|
main
|