-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
125 additions
and
222 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,191 +1,51 @@ | ||
#!/bin/bash | ||
|
||
# What this script does: | ||
# - Update and initialize all aha repo submodules. | ||
# - Check out aha branch BUILDKITE_COMMIT if build triggered from aha repo | ||
# or AHA DEFAULT (no-heroku now, master later) if triggered from submod push/pull. | ||
# - Check out aha branch BUILDKITE_COMMIT if build triggered from aha repo. | ||
# - Else check out master if triggered from submod push/pull. | ||
# - Update and initialize all submodules. | ||
# - If triggered from submod, update submod to match commit hash of triggering repo. | ||
|
||
# Setup | ||
set +u # nounset? not on my watch! | ||
set +x # debug OFF | ||
PS4="_" # Prevents "+++" prefix during 3-deep "set -x" execution | ||
PS4=">" # Prevents "+++" prefix during 3-deep "set -x" execution | ||
|
||
echo "--- CHECKOUT FULL REPO, submodules and all" | ||
|
||
# Checkout | ||
echo "+++ custom-checkout.sh BEGIN" | ||
echo I am `whoami` | ||
echo "+++ BEGIN custom-checkout.sh" | ||
echo I am in dir `pwd` | ||
cd $BUILDKITE_BUILD_CHECKOUT_PATH # Just in case, I dunno, whatevs. | ||
|
||
|
||
############################################################################## | ||
# FIXME yeah okay this could be offloaded as a separate script maybe something | ||
# like "source annotate-w-pr-links.sh" | ||
echo "+++ BEGIN TRIGGERED-FROM LINKS" | ||
|
||
# If pull request, show where request came from. | ||
if [ "$BUILDKITE_PULL_REQUEST_REPO" ]; then | ||
# BUILDKITE_PULL_REQUEST_REPO="https://github.com/StanfordAHA/lake.git" | ||
# BUILDKITE_PULL_REQUEST="166" | ||
# BUILDKITE_COMMIT=7c5e88021a01fef1a04ea56b570563cae2050b1f | ||
|
||
# E.g. repo="https://github.com/StanfordAHA/lake" | ||
repo=`echo "$BUILDKITE_PULL_REQUEST_REPO" | sed 's/.git$//'` | ||
r=`echo "$repo" | sed 's/http.*github.com.//'` | ||
|
||
# E.g. url_cm="https://github.com/StanfordAHA/lake/commit/7c5...0b1f" | ||
first7=`expr "$BUILDKITE_COMMIT" : '\(.......\)'` # 7c5e880 | ||
url_cm=${repo}/commit/${BUILDKITE_COMMIT} | ||
mdlink_cm="[${first7}](${url_cm})" | ||
|
||
# E.g. url_pr="https://github.com/StanfordAHA/lake/pull/166" | ||
url_pr=${repo}/pull/${BUILDKITE_PULL_REQUEST} | ||
mdlink_pr="[Pull Request #${BUILDKITE_PULL_REQUEST}](${url_pr})" | ||
|
||
# E.g. "Triggered from StanfordAHA/canal ca602ef (Pull Request #58)" | ||
cat <<EOF | buildkite-agent annotate --style "info" --context foo3 | ||
### Triggered from ${r} ${mdlink_cm} (${mdlink_pr}) | ||
EOF | ||
fi | ||
|
||
echo "--- END TRIGGERED-FROM LINKS" | ||
# Checkout master or BUILDKITE_COMMIT | ||
|
||
# FIXME don't need this after heroku is gone! FIXME | ||
# Heroku sets BUILDKITE_COMMIT to sha of aha master branch. | ||
# We want to rewrite that to be the sha of submod repo that | ||
# originally triggered the build. | ||
|
||
if [ "$FLOW_HEAD_SHA" ]; then | ||
echo "Found heroku, rewriting BUILDKITE_COMMIT"; | ||
BUILDKITE_COMMIT=$FLOW_HEAD_SHA; | ||
fi | ||
|
||
# If trigger came from a submod repo, we will do "pr" regressions. | ||
# Otherwise, trigger came from aha repo push/pull and we just do "daily" regressions. | ||
# We use commdir to pass information to other steps. | ||
# THIS ASSUMES THAT ALL STEPS RUN ON SAME HOST MACHINE and thus see the same commdir! | ||
|
||
echo "--- Determine whether to do daily or pr regressions" | ||
if git checkout -qf $BUILDKITE_COMMIT; then | ||
echo "+++ UNSET DO_PR" | ||
echo "BUILDKITE_COMMIT found in aha repo, we will do daily regressions." | ||
cd $BUILDKITE_BUILD_CHECKOUT_PATH | ||
# REQUEST_TYPE comes from set-trigfrom-and-reqtype.sh | ||
if [ "$REQUEST_TYPE" == "SUBMOD_PR" ]; then | ||
echo "Pull request from a submod repo: check out aha master branch" | ||
git fetch -v --prune -- origin master | ||
git checkout -qf master | ||
else | ||
echo "+++ SET DO_PR" | ||
echo "BUILDKITE_COMMIT not found in aha repo, we will do pr regressions." | ||
# FIXME could combine this with env-BNO temp file used by update-pr-repo.sh | ||
commdir=/var/lib/buildkite-agent/builds/DELETEME; mkdir -p $commdir; | ||
echo true > $commdir/DO_PR-${BUILDKITE_BUILD_NUMBER} | ||
echo "Push or PR from aha repo: check out requested aha branch $BUILDKITE_COMMIT" | ||
git fetch -v --prune -- origin $BUILDKITE_COMMIT | ||
git checkout -qf $BUILDKITE_COMMIT | ||
fi | ||
|
||
echo "--- Check out appropriate AHA branch: $BUILDKITE_COMMIT, $DEV_BRANCH, or master" | ||
cd $BUILDKITE_BUILD_CHECKOUT_PATH | ||
# FIXME can delete DEV_BRANCH part once dev branch merges to master FIXME | ||
DEV_BRANCH=remotes/origin/no-heroku | ||
echo 'git checkout -qf $BUILDKITE_COMMIT || git checkout -qf $DEV_BRANCH || git checkout -qf master'; set -x | ||
git checkout -qf $BUILDKITE_COMMIT || git checkout -qf $DEV_BRANCH || git checkout -qf master | ||
|
||
echo "--- PREP AHA REPO and all its submodules"; set -x | ||
pwd | ||
# E.g. CHECKOUT_PATH=/var/lib/buildkite-agent/builds/r7cad-docker-1/stanford-aha/aha-flow | ||
cd $BUILDKITE_BUILD_CHECKOUT_PATH # Actually I think we're already there but whatevs | ||
echo "--- Initialize all submodules YES THIS TAKES AWHILE" | ||
|
||
set -x | ||
git submodule update --checkout # This is probably unnecessary but whatevs | ||
git remote set-url origin https://github.com/hofstee/aha | ||
git submodule foreach --recursive "git clean -ffxdq" | ||
git clean -ffxdq | ||
set +x | ||
|
||
# FIXME can of course delete this after heroku is gone FIXME | ||
# Heroku always sets message to "PR from <repo>" with BUILDKITE_COMMIT="HEAD" | ||
# so as to checkout aha master. Heroku also sends desired submod commit <repo> | ||
# hash as env var FLOW_HEAD_SHA. In this new regime, we set BUILDKITE_COMMIT | ||
# as the desired submod commit, and auto-discover the repo that goes with the commit. | ||
|
||
echo "--- See if we need to update a submodule" | ||
unset PR_FROM_SUBMOD | ||
|
||
# PR_FROM_SUBMOD means build was triggered by foreign (non-aha) repo, | ||
# i.e. one of the submods. The submod sends its commit hash BUT DOES | ||
# NOT TELL US WHAT REPO IT IS. :( | ||
|
||
# We detect this by attempting to fetch BUILDKITE_COMMIT from aha repo. | ||
# Success means this is an aha-triggered build. Failure means we need to | ||
# find what repo actually did trigger the commit. | ||
|
||
echo git fetch -v --prune -- origin $BUILDKITE_COMMIT | ||
if git fetch -v --prune -- origin $BUILDKITE_COMMIT; then | ||
|
||
# Pretty sure we already did this, in pipeline.xml BDI step pre-checkout hook | ||
# But what the heck, let's do it again, don't break what is working already. | ||
git checkout -f $BUILDKITE_COMMIT | ||
echo "Found aha commit '$BUILDKITE_COMMIT'; no need to update submodule" | ||
|
||
else | ||
echo '-------------------------------------------' | ||
echo 'REQUESTED COMMIT DOES NOT EXIST in aha repo' | ||
echo '(This must be a pull request from one of the submods)' | ||
echo 'Will checkout aha default branch' | ||
PR_FROM_SUBMOD=true | ||
|
||
# FIXME don't need if-then-else below after dev merges to master. | ||
# Use dev branch as default until it gets merged and deleted. | ||
AHA_DEFAULT_BRANCH=no-heroku | ||
echo "Meanwhile, will use default branch '$AHA_DEFAULT_BRANCH' for aha repo" | ||
if git fetch -v --prune -- origin $AHA_DEFAULT_BRANCH; then | ||
echo "Fetching aha branch '$AHA_DEFAULT_BRANCH'" | ||
git checkout -f $AHA_DEFAULT_BRANCH | ||
else | ||
echo "Aha branch '$AHA_DEFAULT_BRANCH' does not exist" | ||
echo "Fetching aha master branch" | ||
git fetch -v --prune -- origin master | ||
git checkout -f master | ||
fi | ||
fi | ||
|
||
set -x | ||
git submodule sync --recursive | ||
echo "--- git submodule update --init --recursive --force" | ||
git submodule update --init --recursive --force | ||
echo '--- git submodule foreach --recursive "git reset --hard"' | ||
git submodule foreach --recursive "git reset --hard" | ||
set +x | ||
|
||
update_repo=`git config --get remote.origin.url` | ||
# Update submod | ||
|
||
# To find out what repo triggered the commit, we iterate through | ||
# all the submodules and find which one can successfully checkout | ||
# the desired BUILKITE_COMMIT. | ||
|
||
# NOTE this is not necessary for pull requests, which embed the | ||
# repo information as BUILDKITE_PULL_REQUEST. Push requests have | ||
# no such mechanism however :( | ||
# In general we don't process push requests from submodules, but | ||
# this was useful for development etc. | ||
|
||
if [ "$PR_FROM_SUBMOD" ]; then | ||
echo "--- Handle PR" | ||
echo "+++ Looking for submod commit $BUILDKITE_COMMIT" | ||
unset FOUND_SUBMOD | ||
submods=`git submodule status | awk '{print $2}'` # canal lake hwtypes... | ||
for submod in $submods; do | ||
echo "- " Looking in submod $submod | ||
# --- THIS IS WHERE THE CHECKOUT HAPPENS --- | ||
(set -x; cd $submod; git fetch origin && git checkout $BUILDKITE_COMMIT) && FOUND_SUBMOD=true || echo "NOT " $submod | ||
[ "$FOUND_SUBMOD" ] && echo "- FOUND valid commit in submod" $submod | ||
[ "$FOUND_SUBMOD" ] && break | ||
done | ||
|
||
if [ "$FOUND_SUBMOD" ]; then | ||
echo "--- Updated submodule '$submod' w commit '$BUILDKITE_COMMIT'" | ||
update_repo=`cd $submod; git config --get remote.origin.url` | ||
else | ||
echo "ERROR could not find requesting submod"; exit 13 | ||
fi | ||
set +x | ||
else | ||
echo "--- NOT A PULL REQUEST" | ||
# Note PR_REPO_TAIL comes from set-trigfrom-and-reqtype.sh | ||
if [ "$REQUEST_TYPE" == "SUBMOD_PR" ]; then | ||
echo "--- Update submodule '$PR_REPO_TAIL' w commit '$BUILDKITE_COMMIT'" | ||
(set -x; cd $PR_REPO_TAIL; git fetch origin && git checkout $BUILDKITE_COMMIT) | ||
fi | ||
|
||
echo "--- custom-checkout.sh END" | ||
echo "--- END custom-checkout.sh" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#!/bin/bash | ||
|
||
# What does this script do? | ||
# 1. If build was triggered by a pull request, annotate build with | ||
# links pointing to pull request on github. | ||
# 2. Set REQUEST_TYPE to one of "AHA_PUSH", "AHA_PR", or "SUBMOD_PR" | ||
# 3. Set PR_REPO_TAIL to submod associated with the PR, e.g. "canal" | ||
# 4. Add REQUEST_TYPE env temp file for use by later steps | ||
|
||
echo "+++ set-trigfrom-and-reqtype.sh BEGIN" | ||
cd $BUILDKITE_BUILD_CHECKOUT_PATH # Just in case, I dunno, whatevs. | ||
|
||
echo "+++ BEGIN TRIGGERED-FROM LINKS" | ||
|
||
# If pull request, show where request came from. | ||
# And set e.g. PR_REPO_TAIL="lake" | ||
PR_REPO_TAIL= | ||
if [ "$BUILDKITE_PULL_REQUEST_REPO" ]; then | ||
# BUILDKITE_PULL_REQUEST_REPO="https://github.com/StanfordAHA/lake.git" | ||
# BUILDKITE_PULL_REQUEST="166" | ||
# BUILDKITE_COMMIT=7c5e88021a01fef1a04ea56b570563cae2050b1f | ||
|
||
# E.g. repo="https://github.com/StanfordAHA/lake" | ||
repo=`echo "$BUILDKITE_PULL_REQUEST_REPO" | sed 's/.git$//'` | ||
r=`echo "$repo" | sed 's/http.*github.com.//'` # "StanfordAHA/lake" | ||
PR_REPO_TAIL=`echo "$repo" | sed "s,http.*github.com/.*/,,"` # "lake" | ||
echo "Found PR from submod $PR_REPO_TAIL" | ||
|
||
# E.g. url_cm="https://github.com/StanfordAHA/lake/commit/7c5...0b1f" | ||
first7=`expr "$BUILDKITE_COMMIT" : '\(.......\)'` # 7c5e880 | ||
url_cm=${repo}/commit/${BUILDKITE_COMMIT} | ||
mdlink_cm="[${first7}](${url_cm})" | ||
|
||
# E.g. url_pr="https://github.com/StanfordAHA/lake/pull/166" | ||
url_pr=${repo}/pull/${BUILDKITE_PULL_REQUEST} | ||
mdlink_pr="[Pull Request #${BUILDKITE_PULL_REQUEST}](${url_pr})" | ||
|
||
# E.g. "Triggered from StanfordAHA/canal ca602ef (Pull Request #58)" | ||
cat <<EOF | buildkite-agent annotate --style "info" --context foo3 | ||
### Triggered from ${r} ${mdlink_cm} (${mdlink_pr}) | ||
EOF | ||
fi | ||
echo "--- END TRIGGERED-FROM LINKS" | ||
|
||
case "$PR_REPO_TAIL" in | ||
"aha") REQUEST_TYPE="AHA_PR" ;; | ||
"") REQUEST_TYPE="AHA_PUSH" ;; | ||
*) REQUEST_TYPE="SUBMOD_PR" ;; | ||
esac | ||
echo "--- FOUND REQUEST_TYPE '$REQUEST_TYPE'" | ||
|
||
# Squirrel away the info for later use | ||
temp=/var/lib/buildkite-agent/builds/DELETEME; mkdir -p $temp | ||
env=$temp/env-$BUILDKITE_BUILD_NUMBER | ||
echo REQUEST_TYPE=${REQUEST_TYPE} >> $env | ||
|
||
echo "+++ set-trigfrom-and-reqtype.sh END" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.