fix: shellcheck warnings in scripts (#24035)

This commit is contained in:
Tommaso Sciortino
2026-03-28 19:47:05 -07:00
committed by GitHub
parent b7c86b5497
commit da8c841ef4
4 changed files with 219 additions and 208 deletions

View File

@@ -19,18 +19,20 @@
# - jq installed
# Arguments & Defaults
if [[ -n "$1" && $1 =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}$ ]]; then
SINCE="$1"
elif [[ -n "$1" && $1 =~ ^([0-9]+)d$ ]]; then
if [[ -n "${1}" && "${1}" =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}$ ]]; then
SINCE="${1}"
elif [[ -n "${1}" && "${1}" =~ ^([0-9]+)d$ ]]; then
DAYS="${BASH_REMATCH[1]}"
if [[ "$OSTYPE" == "darwin"* ]]; then
os_type="$(uname || true)"
if [[ "${os_type}" == "darwin"* ]]; then
SINCE=$(date -u -v-"${DAYS}"d +%Y-%m-%d)
else
SINCE=$(date -u -d "${DAYS} days ago" +%Y-%m-%d)
fi
else
# Default to 7 days ago in YYYY-MM-DD format (UTC)
if [[ "$OSTYPE" == "darwin"* ]]; then
os_type="$(uname || true)"
if [[ "${os_type}" == "darwin"* ]]; then
SINCE=$(date -u -v-7d +%Y-%m-%d)
else
SINCE=$(date -u -d "7 days ago" +%Y-%m-%d)
@@ -40,11 +42,11 @@ fi
LIMIT=${2:-300}
BRANCH=${3:-""}
WORKFLOWS=("Testing: E2E (Chained)" "Evals: Nightly")
DEST_DIR=$(mktemp -d -t gemini-reliability-XXXXXX)
DEST_DIR="$(mktemp -d -t gemini-reliability-XXXXXX)"
MERGED_FILE="api-reliability-summary.jsonl"
# Ensure cleanup on exit
trap 'rm -rf "$DEST_DIR"' EXIT
trap 'rm -rf "${DEST_DIR}"' EXIT
if ! command -v gh &> /dev/null; then
echo "❌ Error: GitHub CLI (gh) is not installed."
@@ -57,55 +59,56 @@ if ! command -v jq &> /dev/null; then
fi
# Clean start
rm -f "$MERGED_FILE"
rm -f "${MERGED_FILE}"
# gh run list --created expects a date (YYYY-MM-DD) or a range
CREATED_QUERY=">=$SINCE"
CREATED_QUERY=">=${SINCE}"
for WORKFLOW in "${WORKFLOWS[@]}"; do
echo "🔍 Fetching runs for '$WORKFLOW' created since $SINCE (max $LIMIT runs, branch: ${BRANCH:-all})..."
echo "🔍 Fetching runs for '${WORKFLOW}' created since ${SINCE} (max ${LIMIT} runs, branch: ${BRANCH:-all})..."
# Construct arguments for gh run list
GH_ARGS=("--workflow" "$WORKFLOW" "--created" "$CREATED_QUERY" "--limit" "$LIMIT" "--json" "databaseId" "--jq" ".[].databaseId")
if [ -n "$BRANCH" ]; then
GH_ARGS+=("--branch" "$BRANCH")
GH_ARGS=("--workflow" "${WORKFLOW}" "--created" "${CREATED_QUERY}" "--limit" "${LIMIT}" "--json" "databaseId" "--jq" ".[].databaseId")
if [[ -n "${BRANCH}" ]]; then
GH_ARGS+=("--branch" "${BRANCH}")
fi
RUN_IDS=$(gh run list "${GH_ARGS[@]}")
exit_code=$?
if [ $exit_code -ne 0 ]; then
echo "❌ Failed to fetch runs for '$WORKFLOW' (exit code: $exit_code). Please check 'gh auth status' and permissions." >&2
if [[ "${exit_code}" -ne 0 ]]; then
echo "❌ Failed to fetch runs for '${WORKFLOW}' (exit code: ${exit_code}). Please check 'gh auth status' and permissions." >&2
continue
fi
if [ -z "$RUN_IDS" ]; then
echo "📭 No runs found for workflow '$WORKFLOW' since $SINCE."
if [[ -z "${RUN_IDS}" ]]; then
echo "📭 No runs found for workflow '${WORKFLOW}' since ${SINCE}."
continue
fi
for ID in $RUN_IDS; do
for ID in ${RUN_IDS}; do
# Download artifacts named 'eval-logs-*'
# Silencing output because many older runs won't have artifacts
gh run download "$ID" -p "eval-logs-*" -D "$DEST_DIR/$ID" &>/dev/null || continue
gh run download "${ID}" -p "eval-logs-*" -D "${DEST_DIR}/${ID}" &>/dev/null || continue
# Append to master log
# Use find to locate api-reliability.jsonl in any subdirectory of $DEST_DIR/$ID
find "$DEST_DIR/$ID" -type f -name "api-reliability.jsonl" -exec cat {} + >> "$MERGED_FILE" 2>/dev/null
find "${DEST_DIR}/${ID}" -type f -name "api-reliability.jsonl" -exec cat {} + >> "${MERGED_FILE}" 2>/dev/null
done
done
if [ ! -f "$MERGED_FILE" ]; then
if [[ ! -f "${MERGED_FILE}" ]]; then
echo "📭 No reliability data found in the retrieved logs."
exit 0
fi
echo -e "\n✅ Harvest Complete! Data merged into: $MERGED_FILE"
echo -e "\n✅ Harvest Complete! Data merged into: ${MERGED_FILE}"
echo "------------------------------------------------"
echo "📊 Gemini API Reliability Summary (Since $SINCE)"
echo "📊 Gemini API Reliability Summary (Since ${SINCE})"
echo "------------------------------------------------"
cat "$MERGED_FILE" | jq -s '
# shellcheck disable=SC2312
cat "${MERGED_FILE}" | jq -s '
group_by(.model) | map({
model: .[0].model,
"500s": (map(select(.errorCode == "500")) | length),
@@ -114,4 +117,5 @@ cat "$MERGED_FILE" | jq -s '
skips: (map(select(.status == "SKIP")) | length)
})'
echo -e "\n💡 Total events captured: $(wc -l < "$MERGED_FILE")"
# shellcheck disable=SC2312
echo -e "\n💡 Total events captured: $(wc -l < "${MERGED_FILE}")"

View File

@@ -5,17 +5,17 @@
set -e
if [ -z "$1" ]; then
echo "Usage: $0 <pr#> [model]"
if [[ -z "${1}" ]]; then
echo "Usage: ${0} <pr#> [model]"
exit 1
fi
pr="$1"
pr="${1}"
model="${2:-gemini-3.1-pro-preview}"
REPO="google-gemini/gemini-cli"
REVIEW_DIR="$HOME/git/review/gemini-cli"
REVIEW_DIR="${HOME}/git/review/gemini-cli"
if [ ! -d "$REVIEW_DIR" ]; then
echo "ERROR: Directory $REVIEW_DIR does not exist."
if [[ ! -d "${REVIEW_DIR}" ]]; then
echo "ERROR: Directory ${REVIEW_DIR} does not exist."
echo ""
echo "Please create a new gemini-cli clone at that directory to use for reviews."
echo "Instructions:"
@@ -26,54 +26,56 @@ if [ ! -d "$REVIEW_DIR" ]; then
fi
# 1. Check if the PR exists before doing anything else
echo "review: Validating PR $pr on $REPO..."
if ! gh pr view "$pr" -R "$REPO" > /dev/null 2>&1; then
echo "ERROR: Could not find PR #$pr in $REPO."
echo "Are you sure $pr is a Pull Request number and not an Issue number?"
echo "review: Validating PR ${pr} on ${REPO}..."
if ! gh pr view "${pr}" -R "${REPO}" > /dev/null 2>&1; then
echo "ERROR: Could not find PR #${pr} in ${REPO}."
echo "Are you sure ${pr} is a Pull Request number and not an Issue number?"
exit 1
fi
echo "review: Opening PR $pr in browser..."
if [[ "$(uname)" == "Darwin" ]]; then
open "https://github.com/$REPO/pull/$pr" || true
echo "review: Opening PR ${pr} in browser..."
uname_out="$(uname || true)"
if [[ "${uname_out}" == "Darwin" ]]; then
open "https://github.com/${REPO}/pull/${pr}" || true
else
xdg-open "https://github.com/$REPO/pull/$pr" || true
xdg-open "https://github.com/${REPO}/pull/${pr}" || true
fi
echo "review: Changing directory to $REVIEW_DIR"
cd "$REVIEW_DIR" || exit 1
echo "review: Changing directory to ${REVIEW_DIR}"
cd "${REVIEW_DIR}" || exit 1
# 2. Fetch latest main to ensure we have a clean starting point
echo "review: Fetching latest from origin..."
git fetch origin main
# 3. Handle worktree creation
WORKTREE_PATH="pr_$pr"
if [ -d "$WORKTREE_PATH" ]; then
echo "review: Worktree directory $WORKTREE_PATH already exists."
WORKTREE_PATH="pr_${pr}"
if [[ -d "${WORKTREE_PATH}" ]]; then
echo "review: Worktree directory ${WORKTREE_PATH} already exists."
# Check if it's actually a registered worktree
if git worktree list | grep -q "$WORKTREE_PATH"; then
# shellcheck disable=SC2312
if git worktree list | grep -q "${WORKTREE_PATH}"; then
echo "review: Reusing existing worktree..."
else
echo "review: Directory exists but is not a worktree. Cleaning up..."
rm -rf "$WORKTREE_PATH"
rm -rf "${WORKTREE_PATH}"
fi
fi
if [ ! -d "$WORKTREE_PATH" ]; then
echo "review: Adding new worktree at $WORKTREE_PATH..."
if [[ ! -d "${WORKTREE_PATH}" ]]; then
echo "review: Adding new worktree at ${WORKTREE_PATH}..."
# Create a detached worktree from origin/main
git worktree add --detach "$WORKTREE_PATH" origin/main
git worktree add --detach "${WORKTREE_PATH}" origin/main
fi
echo "review: Changing directory to $WORKTREE_PATH"
cd "$WORKTREE_PATH" || exit 1
echo "review: Changing directory to ${WORKTREE_PATH}"
cd "${WORKTREE_PATH}" || exit 1
# 4. Checkout the PR
echo "review: Cleaning worktree and checking out PR $pr..."
echo "review: Cleaning worktree and checking out PR ${pr}..."
git reset --hard
git clean -fd
gh pr checkout "$pr" --branch "review-$pr" -f -R "$REPO"
gh pr checkout "${pr}" --branch "review-${pr}" -f -R "${REPO}"
# 5. Clean and Build
echo "review: Clearing possibly stale node_modules..."
@@ -87,48 +89,49 @@ npm install
echo "--- build ---"
temp_dir_base="${TMPDIR:-/tmp}"
build_log_file=$(mktemp "${temp_dir_base}/npm_build_log.XXXXXX") || {
build_log_file="$(mktemp "${temp_dir_base}/npm_build_log.XXXXXX" || true)"
if [[ -z "${build_log_file}" || ! -f "${build_log_file}" ]]; then
echo "Attempting to create temporary file in current directory as a fallback." >&2
build_log_file=$(mktemp "./npm_build_log_fallback.XXXXXX")
if [ $? -ne 0 ] || [ -z "$build_log_file" ]; then
build_log_file="$(mktemp "./npm_build_log_fallback.XXXXXX" || true)"
if [[ -z "${build_log_file}" || ! -f "${build_log_file}" ]]; then
echo "ERROR: Critical - Failed to create any temporary build log file. Aborting." >&2
exit 1
fi
}
fi
build_status=0
build_command_to_run="FORCE_COLOR=1 CLICOLOR_FORCE=1 npm run build"
echo "Running build. Output (with colors) will be shown below and saved to: $build_log_file"
echo "Build command: $build_command_to_run"
echo "Running build. Output (with colors) will be shown below and saved to: ${build_log_file}"
echo "Build command: ${build_command_to_run}"
if [[ "$(uname)" == "Darwin" ]]; then
script -q "$build_log_file" /bin/sh -c "$build_command_to_run"
build_status=$?
if [[ "${uname_out}" == "Darwin" ]]; then
script -q "${build_log_file}" /bin/sh -c "${build_command_to_run}" || build_status=$?
else
if script -q -e -c "$build_command_to_run" "$build_log_file"; then
if script -q -e -c "${build_command_to_run}" "${build_log_file}"; then
build_status=0
else
build_status=$?
fi
fi
if [ $build_status -ne 0 ]; then
echo "ERROR: npm build failed with exit status $build_status." >&2
echo "Review output above. Full log (with color codes) was in $build_log_file." >&2
if [[ "${build_status}" -ne 0 ]]; then
echo "ERROR: npm build failed with exit status ${build_status}." >&2
echo "Review output above. Full log (with color codes) was in ${build_log_file}." >&2
exit 1
else
if grep -q -i -E "\berror\b|\bfailed\b|ERR!|FATAL|critical" "$build_log_file"; then
# shellcheck disable=SC2312
if grep -q -i -E "\berror\b|\bfailed\b|ERR!|FATAL|critical" "${build_log_file}"; then
echo "ERROR: npm build completed with exit status 0, but suspicious error patterns were found in the build output." >&2
echo "Review output above. Full log (with color codes) was in $build_log_file." >&2
echo "Review output above. Full log (with color codes) was in ${build_log_file}." >&2
exit 1
fi
echo "npm build completed successfully (exit status 0, no critical error patterns found in log)."
rm -f "$build_log_file"
rm -f "${build_log_file}"
fi
echo "-- running ---"
if ! npm start -- -m "$model" -i="/review-frontend $pr"; then
if ! npm start -- -m "${model}" -i="/review-frontend ${pr}"; then
echo "ERROR: npm start failed. Please check its output for details." >&2
exit 1
fi