Skip to content

Update select-into-outfile #77

Update select-into-outfile

Update select-into-outfile #77

name: Validate SQL Execution
on:
pull_request:
paths:
- 'docs/**/*.md'
- 'scripts/doc-validator/**'
workflow_dispatch:
inputs:
branch:
description: 'Target branch for image selection (leave empty for auto-detect)'
required: false
type: string
env:
TENCENT_TCR_REPO: ccr.ccs.tencentyun.com/matrixone-dev/matrixone
jobs:
validate-sql:
name: SQL Execution Validation
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 9.15.0
run_install: false
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'pnpm'
cache-dependency-path: 'pnpm-lock.yaml'
- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- name: Setup pnpm cache
uses: actions/cache@v4
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Install MySQL client
run: |
echo "πŸ“¦ Installing MySQL client..."
sudo apt-get update
sudo apt-get install -y mysql-client
- name: Run SQL Validation with Branch Fallback
run: |
echo "πŸ” Starting SQL Execution Validation with Branch Fallback"
echo "============================================================"
# Get sorted commit list
echo "πŸ“‹ Fetching commit list from main and dev branches..."
COMMITS=$(bash ./scripts/mo-test-env.sh get-commits)
if [ -z "$COMMITS" ]; then
echo "❌ Failed to fetch commits"
exit 1
fi
echo "Available commits:"
echo "$COMMITS" | while read -r sha branch; do
echo " - $sha ($branch)"
done
echo ""
# Track which branches have been tested
TESTED_MAIN=false
TESTED_DEV=false
LAST_FAILED_BRANCH=""
TEST_PASSED=false
# Iterate through commits
while IFS= read -r line; do
SHA=$(echo "$line" | cut -d' ' -f1)
BRANCH=$(echo "$line" | cut -d' ' -f2)
if [ -z "$SHA" ]; then
continue
fi
# Skip if this branch type already failed and we're looking at the same branch
if [ -n "$LAST_FAILED_BRANCH" ] && [ "$BRANCH" = "$LAST_FAILED_BRANCH" ]; then
echo "⏭️ Skipping $SHA ($BRANCH) - already tested this branch"
continue
fi
echo ""
echo "============================================================"
echo "πŸ§ͺ Testing commit: $SHA ($BRANCH)"
echo "============================================================"
IMAGE="${TENCENT_TCR_REPO}:commit-${SHA}"
# Try to start database with this image
echo "πŸš€ Starting MatrixOne with $IMAGE..."
if ! bash ./scripts/mo-test-env.sh start-image "$IMAGE"; then
echo "⚠️ Failed to start database with $SHA, trying next..."
continue
fi
# Wait for database to be ready
echo "⏳ Waiting for database to be ready..."
MAX_RETRIES=30
RETRY_COUNT=0
DB_READY=false
while [ $RETRY_COUNT -lt $MAX_RETRIES ]; do
if pnpm run db:test 2>/dev/null; then
echo "βœ… Database is ready!"
DB_READY=true
break
fi
RETRY_COUNT=$((RETRY_COUNT + 1))
echo "Attempt $RETRY_COUNT/$MAX_RETRIES - waiting 10s..."
sleep 10
done
if [ "$DB_READY" = false ]; then
echo "⚠️ Database failed to start with $SHA, trying next..."
pnpm run db:stop || true
continue
fi
# Run SQL validation
echo ""
echo "πŸ” Running SQL Execution Validation..."
if pnpm run check:sql-exec:changed; then
echo ""
echo "============================================================"
echo "βœ… SQL Validation PASSED with $SHA ($BRANCH)"
echo "============================================================"
TEST_PASSED=true
pnpm run db:stop || true
break
else
echo ""
echo "⚠️ SQL Validation FAILED with $SHA ($BRANCH)"
# Mark this branch as tested
if [ "$BRANCH" = "main" ]; then
TESTED_MAIN=true
else
TESTED_DEV=true
fi
LAST_FAILED_BRANCH="$BRANCH"
# Check if both branches have been tested
if [ "$TESTED_MAIN" = true ] && [ "$TESTED_DEV" = true ]; then
echo ""
echo "============================================================"
echo "❌ Both main and dev branches have been tested and failed"
echo "============================================================"
pnpm run db:stop || true
exit 1
fi
echo "πŸ”„ Will try another branch..."
pnpm run db:stop || true
fi
done <<< "$COMMITS"
if [ "$TEST_PASSED" = false ]; then
echo ""
echo "============================================================"
echo "❌ No available commit passed the SQL validation"
echo "============================================================"
exit 1
fi
- name: Show Docker logs on failure
if: failure()
run: |
echo "πŸ“‹ Docker container logs (if any):"
docker logs mo-test 2>/dev/null || echo "No container logs available"
- name: Cleanup
if: always()
run: |
echo "🧹 Cleaning up..."
pnpm run db:stop || true