2017-08-03 22:43:05 +00:00
|
|
|
#!/usr/bin/env bash
|
2016-06-21 18:38:54 +00:00
|
|
|
#
|
|
|
|
# Copyright (c) 2016, Facebook. All rights reserved.
|
|
|
|
#
|
|
|
|
# Overall wrapper script for RocksDB continuous builds. The implementation is a
|
|
|
|
# trivial pulling scheme. We loop infinitely, check if any new changes have been
|
|
|
|
# committed, if yes then trigger a Sandcastle run, and finally go to sleep again
|
|
|
|
# for a certain interval.
|
|
|
|
#
|
|
|
|
|
2016-12-28 06:21:34 +00:00
|
|
|
SRC_GIT_REPO=/data/git/rocksdb-public
|
2016-06-23 18:52:31 +00:00
|
|
|
error=0
|
|
|
|
|
2016-06-21 18:38:54 +00:00
|
|
|
function log {
|
|
|
|
DATE=`date +%Y-%m-%d:%H:%M:%S`
|
|
|
|
echo $DATE $@
|
|
|
|
}
|
|
|
|
|
|
|
|
function log_err {
|
2016-06-23 18:52:31 +00:00
|
|
|
log "ERROR: $@ Error code: $error."
|
2016-06-21 18:38:54 +00:00
|
|
|
}
|
|
|
|
|
2016-06-23 19:08:44 +00:00
|
|
|
function update_repo_status {
|
2016-06-23 18:52:31 +00:00
|
|
|
# Update the parent first.
|
|
|
|
pushd $SRC_GIT_REPO
|
|
|
|
|
|
|
|
# This is a fatal error. Something in the environment isn't right and we will
|
|
|
|
# terminate the execution.
|
|
|
|
error=$?
|
|
|
|
if [ ! $error -eq 0 ]; then
|
|
|
|
log_err "Where is $SRC_GIT_REPO?"
|
|
|
|
exit $error
|
|
|
|
fi
|
|
|
|
|
|
|
|
HTTPS_PROXY=fwdproxy:8080 git fetch -f
|
|
|
|
|
|
|
|
error=$?
|
|
|
|
if [ ! $error -eq 0 ]; then
|
|
|
|
log_err "git fetch -f failed."
|
|
|
|
popd
|
|
|
|
return $error
|
|
|
|
fi
|
|
|
|
|
|
|
|
git update-ref refs/heads/master refs/remotes/origin/master
|
|
|
|
|
|
|
|
error=$?
|
|
|
|
if [ ! $error -eq 0 ]; then
|
|
|
|
log_err "git update-ref failed."
|
|
|
|
popd
|
|
|
|
return $error
|
|
|
|
fi
|
|
|
|
|
|
|
|
popd
|
|
|
|
|
|
|
|
# We're back in an instance-specific directory. Get the latest changes.
|
|
|
|
git pull --rebase
|
|
|
|
|
|
|
|
error=$?
|
|
|
|
if [ ! $error -eq 0 ]; then
|
|
|
|
log_err "git pull --rebase failed."
|
|
|
|
return $error
|
|
|
|
fi
|
2016-06-23 19:08:44 +00:00
|
|
|
}
|
|
|
|
|
2016-06-21 18:38:54 +00:00
|
|
|
#
|
|
|
|
# Execution starts here.
|
|
|
|
#
|
|
|
|
|
|
|
|
# Path to the determinator from the root of the RocksDB repo.
|
2017-07-27 02:01:45 +00:00
|
|
|
CONTRUN_DETERMINATOR=./build_tools/RocksDBCommonHelper.php
|
2016-06-21 18:38:54 +00:00
|
|
|
|
|
|
|
# Value of the previous commit.
|
|
|
|
PREV_COMMIT=
|
|
|
|
|
|
|
|
log "Starting to monitor for new RocksDB changes ..."
|
|
|
|
log "Running under `pwd` as `whoami`."
|
|
|
|
|
|
|
|
# Paranoia. Make sure that we're using the right branch.
|
|
|
|
git checkout master
|
|
|
|
|
2016-06-23 18:52:31 +00:00
|
|
|
error=$?
|
|
|
|
if [ ! $error -eq 0 ]; then
|
2016-06-21 18:38:54 +00:00
|
|
|
log_err "This is not good. Can't checkout master. Bye-bye!"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# We'll run forever and let the execution environment terminate us if we'll
|
|
|
|
# exceed whatever timeout is set for the job.
|
|
|
|
while true;
|
|
|
|
do
|
|
|
|
# Get the latest changes committed.
|
2016-06-23 18:52:31 +00:00
|
|
|
update_repo_status
|
2016-06-21 18:38:54 +00:00
|
|
|
|
2016-06-23 18:52:31 +00:00
|
|
|
error=$?
|
|
|
|
if [ $error -eq 0 ]; then
|
2016-06-21 18:38:54 +00:00
|
|
|
LAST_COMMIT=`git log -1 | head -1 | grep commit | awk '{ print $2; }'`
|
|
|
|
|
|
|
|
log "Last commit is '$LAST_COMMIT', previous commit is '$PREV_COMMIT'."
|
|
|
|
|
|
|
|
if [ "$PREV_COMMIT" == "$LAST_COMMIT" ]; then
|
|
|
|
log "There were no changes since the last time I checked. Going to sleep."
|
|
|
|
else
|
|
|
|
if [ ! -z "$LAST_COMMIT" ]; then
|
2016-06-22 18:05:52 +00:00
|
|
|
log "New code has been committed or previous commit not known. " \
|
2016-06-21 18:38:54 +00:00
|
|
|
"Will trigger the tests."
|
|
|
|
|
|
|
|
PREV_COMMIT=$LAST_COMMIT
|
|
|
|
log "Updated previous commit to '$PREV_COMMIT'."
|
|
|
|
|
|
|
|
#
|
|
|
|
# This is where we'll trigger the Sandcastle run. The values for
|
|
|
|
# HTTPS_APP_VALUE and HTTPS_APP_VALUE will be set in the container we're
|
|
|
|
# running in.
|
|
|
|
#
|
|
|
|
POST_RECEIVE_HOOK=1 php $CONTRUN_DETERMINATOR
|
|
|
|
|
2016-06-23 18:52:31 +00:00
|
|
|
error=$?
|
|
|
|
if [ $error -eq 0 ]; then
|
2016-06-21 18:38:54 +00:00
|
|
|
log "Sandcastle run successfully triggered."
|
|
|
|
else
|
|
|
|
log_err "Failed to trigger Sandcastle run."
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
log_err "Previous commit not updated. Don't know what the last one is."
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
else
|
2016-06-23 18:52:31 +00:00
|
|
|
log_err "Getting latest changes failed. Will skip running tests for now."
|
2016-06-21 18:38:54 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Always sleep, even if errors happens while trying to determine the latest
|
|
|
|
# commit. This will prevent us terminating in case of transient errors.
|
|
|
|
log "Will go to sleep for 5 minutes."
|
|
|
|
sleep 5m
|
|
|
|
done
|