Add Kokoro build script for merging main into chromeos

The Kokoro build script sets up access to the chromium
gerrit, creates the merge commit and uploads it.

BUG=b:209034086
TEST=./ci/kokoro/simulate merge-to-chromeos.sh

Change-Id: Ia686b937c3d6b0b744d5c2162eb2847c5952e977
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3318793
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
This commit is contained in:
Dennis Kempin 2021-12-06 11:49:32 -08:00 committed by Commit Bot
parent 89759de1d1
commit e061930706
2 changed files with 73 additions and 15 deletions

View file

@ -0,0 +1,59 @@
#!/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() {
# 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"
if git push origin HEAD:refs/for/chromeos; then
return 0
fi
done
return 1
}
main() {
set -e
gerrit_prerequisites
# Perform merge on a tracking branch.
git checkout -b chromeos
git branch --set-upstream-to origin/chromeos chromeos
./tools/chromeos/create_merge
upload
}
main

View file

@ -15,26 +15,25 @@
# To merge with a specific commit, use: ./tools/chromeos/create_merge $SHA
set -e
cd "$(dirname "${BASH_SOURCE[0]}")/../../" || exit
ORIGIN="$(git remote get-url cros)"
MERGE_TARGET="${1:-cros/main}"
LOCAL_BRANCH=$(git branch --show-current)
REMOTE_NAME=$(git config "branch.${LOCAL_BRANCH}.remote")
URL=$(git remote get-url "${REMOTE_NAME}")
DEFAULT_TARGET="${REMOTE_NAME}/main"
MERGE_TARGET="${1:-${DEFAULT_TARGET}}"
commit_list() {
git log --oneline --decorate=no --no-color "HEAD..${MERGE_TARGET}"
}
prerequisites() {
if [[ -e "${ORIGIN}" ]]; then
echo "'cros' remote does not exist."
echo "Are you running this in a ChromeOS checkout?"
exit 1
fi
local tracking="$(git rev-parse --abbrev-ref --symbolic-full-name @{u})"
if [[ "${tracking}" != "cros/chromeos" ]]; then
echo "Not tracking the cros/chromeos branch."
if [[ -e "${LOCAL_BRANCH}" ]] ||
[[ -e "${REMOTE_NAME}" ]] ||
[[ -e "${URL}" ]]; then
echo "This script requires the local repository to be on" \
"a tracking branch."
exit 1
fi
@ -55,11 +54,11 @@ merge_message() {
local new=$(git rev-parse "${MERGE_TARGET}")
local count=$(commit_list | wc -l)
echo "Merge ${count} commits from ${MERGE_TARGET}"
echo "Merge ${count} commits from ${MERGE_TARGET} ($(date +%F))"
echo ""
commit_list
echo ""
echo "${ORIGIN}/+log/${old}..${new}"
echo "${URL}/+log/${old}..${new}"
echo ""
echo "BUG=None"
echo "TEST=CQ"
@ -68,7 +67,7 @@ merge_message() {
main() {
prerequisites
git merge --no-ff "${MERGE_TARGET}" -m "$(merge_message)"
git log -n 1
git --no-pager log -n 1
}
main