Skip to content

Commit

Permalink
Merge #140787
Browse files Browse the repository at this point in the history
140787: build: fix microbenchmark weekly fetch r=golgeek a=herkolategan

The fetch should happen before checking `is_branch` or `is_tag` otherwise it won't be able to find the ref.

Epic: None
Release note: None

Co-authored-by: Herko Lategan <[email protected]>
  • Loading branch information
craig[bot] and herkolategan committed Feb 19, 2025
2 parents 9547614 + 8dcb9d5 commit 416e269
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ EOF
current_sha=$(git rev-parse HEAD)
shas=("$@")
for sha in "${shas[@]}"; do
git fetch origin "$sha"
git checkout "$sha"
build_and_upload_binaries "$sha"
done
Expand Down
71 changes: 24 additions & 47 deletions build/teamcity/cockroach/nightlies/microbenchmark_weekly.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,46 +44,12 @@ remote_dir="/mnt/data1"
benchmarks_commit=$(git rev-parse HEAD)
exit_status=0

# Set up credentials
google_credentials="$GOOGLE_EPHEMERAL_CREDENTIALS"
log_into_gcloud
export GOOGLE_APPLICATION_CREDENTIALS="$PWD/.google-credentials.json"
export ROACHPROD_USER=teamcity
export ROACHPROD_CLUSTER=teamcity-microbench-${TC_BUILD_ID}
generate_ssh_key

# Sanatize the package name for use in paths
SANITIZED_BENCH_PACKAGE=${BENCH_PACKAGE//\//-}
export SANITIZED_BENCH_PACKAGE=${SANITIZED_BENCH_PACKAGE/.../all}

# Build rochprod and roachprod-microbench
run_bazel <<'EOF'
bazel build --config crosslinux //pkg/cmd/roachprod //pkg/cmd/roachprod-microbench
BAZEL_BIN=$(bazel info bazel-bin --config crosslinux)
mkdir -p bin
cp $BAZEL_BIN/pkg/cmd/roachprod/roachprod_/roachprod bin
cp $BAZEL_BIN/pkg/cmd/roachprod-microbench/roachprod-microbench_/roachprod-microbench bin
chmod a+w bin/roachprod bin/roachprod-microbench
EOF

# Check if a string is a valid SHA (otherwise it's a branch or tag name).
is_sha() {
local sha="$1"
[[ "$sha" =~ ^[0-9a-f]{40}$ ]]
}

# Check if a string is a valid branch
is_branch() {
local branch="$1"
git rev-parse --verify "refs/heads/$branch" >/dev/null 2>&1
}

# Check if a string is a valid tag
is_tag() {
local tag="$1"
git rev-parse --verify "refs/tags/$tag" >/dev/null 2>&1
}

get_latest_patch_tag() {
local latest_tag
latest_tag=$(git tag -l 'v*' \
Expand All @@ -93,37 +59,48 @@ get_latest_patch_tag() {
echo "$latest_tag"
}

git fetch origin --tags

# Create arrays for the revisions and their corresponding SHAs.
revisions=("${BENCH_REVISION}" "${BENCH_COMPARE_REVISION}")
declare -a sha_arr
declare -a name_arr
for rev in "${revisions[@]}"; do
if [ "$rev" == "LATEST_PATCH_RELEASE" ]; then
git fetch origin --tags
rev=$(get_latest_patch_tag)
fi
if is_sha "$rev"; then
sha="$rev"
name="${sha:0:8}"
else
# Named revision (branch or tag)
if is_branch "$rev"; then
git fetch origin "$rev"
sha=$(git rev-parse origin/"$rev")
elif is_tag "$rev"; then
sha=$(git rev-parse "$rev")
else
echo "Invalid revision: $rev"
exit 1
fi
sha=$(git ls-remote origin "$rev" | awk '{print $1}')
name="$rev (${sha:0:8})"
fi

name_arr+=("$name")
sha_arr+=("$sha")
done

# Set up credentials
google_credentials="$GOOGLE_EPHEMERAL_CREDENTIALS"
log_into_gcloud
export GOOGLE_APPLICATION_CREDENTIALS="$PWD/.google-credentials.json"
export ROACHPROD_USER=teamcity
export ROACHPROD_CLUSTER=teamcity-microbench-${TC_BUILD_ID}
generate_ssh_key

# Sanatize the package name for use in paths
SANITIZED_BENCH_PACKAGE=${BENCH_PACKAGE//\//-}
export SANITIZED_BENCH_PACKAGE=${SANITIZED_BENCH_PACKAGE/.../all}

# Build rochprod and roachprod-microbench
run_bazel <<'EOF'
bazel build --config crosslinux //pkg/cmd/roachprod //pkg/cmd/roachprod-microbench
BAZEL_BIN=$(bazel info bazel-bin --config crosslinux)
mkdir -p bin
cp $BAZEL_BIN/pkg/cmd/roachprod/roachprod_/roachprod bin
cp $BAZEL_BIN/pkg/cmd/roachprod-microbench/roachprod-microbench_/roachprod-microbench bin
chmod a+w bin/roachprod bin/roachprod-microbench
EOF

# Check if the baseline cache exists and copy it to the output directory.
baseline_cache_path="gs://$BENCH_BUCKET/cache/$GCE_MACHINE_TYPE/$SANITIZED_BENCH_PACKAGE/${sha_arr[1]}"
declare -a build_sha_arr
Expand Down

0 comments on commit 416e269

Please sign in to comment.