Add comprehensive MySQL test workflow with 6 tests including CRUD ope… #1
This file contains hidden or 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
| # MySQL Test Workflow | |
| # Tests MySQL on ARM64 architecture | |
| # MySQL is an open-source relational database management system | |
| name: Test MySQL on Arm64 | |
| on: | |
| workflow_dispatch: | |
| workflow_call: | |
| push: | |
| branches: | |
| - main | |
| - smoke_tests | |
| paths: | |
| - 'content/opensource_packages/mysql.md' | |
| - '.github/workflows/test-mysql.yml' | |
| jobs: | |
| test-mysql: | |
| runs-on: ubuntu-24.04-arm | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set test metadata | |
| id: metadata | |
| run: | | |
| echo "timestamp=$(date -u +%Y-%m-%dT%H:%M:%SZ)" >> $GITHUB_OUTPUT | |
| echo "package_slug=mysql" >> $GITHUB_OUTPUT | |
| echo "dashboard_link=/opensource_packages/mysql" >> $GITHUB_OUTPUT | |
| # ============================================================ | |
| # Install MySQL | |
| # ============================================================ | |
| - name: Install MySQL | |
| id: install | |
| run: | | |
| echo "Installing MySQL Server..." | |
| # Update package list | |
| sudo apt-get update | |
| # Install MySQL Server (will use default Ubuntu repository) | |
| sudo DEBIAN_FRONTEND=noninteractive apt-get install -y mysql-server mysql-client | |
| # Verify installation | |
| if command -v mysql &> /dev/null && command -v mysqld &> /dev/null; then | |
| echo "MySQL installed successfully" | |
| echo "install_status=success" >> $GITHUB_OUTPUT | |
| else | |
| echo "MySQL installation failed" | |
| echo "install_status=failed" >> $GITHUB_OUTPUT | |
| exit 1 | |
| fi | |
| # ============================================================ | |
| # Get MySQL version | |
| # ============================================================ | |
| - name: Get MySQL version | |
| id: version | |
| run: | | |
| VERSION=$(mysql --version | grep -oP 'mysql\s+Ver\s+\K[0-9.]+' | head -1 || echo "unknown") | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| echo "Detected MySQL version: $VERSION" | |
| # ============================================================ | |
| # MySQL Tests | |
| # ============================================================ | |
| - name: Test 1 - Check mysql client binary exists | |
| id: test1 | |
| run: | | |
| START_TIME=$(date +%s) | |
| if command -v mysql &> /dev/null; then | |
| echo "✓ mysql client binary found" | |
| echo "status=passed" >> $GITHUB_OUTPUT | |
| else | |
| echo "✗ mysql client binary not found" | |
| echo "status=failed" >> $GITHUB_OUTPUT | |
| exit 1 | |
| fi | |
| END_TIME=$(date +%s) | |
| echo "duration=$((END_TIME - START_TIME))" >> $GITHUB_OUTPUT | |
| - name: Test 2 - Check mysqld server binary exists | |
| id: test2 | |
| run: | | |
| START_TIME=$(date +%s) | |
| if command -v mysqld &> /dev/null; then | |
| echo "✓ mysqld server binary found" | |
| echo "status=passed" >> $GITHUB_OUTPUT | |
| else | |
| echo "✗ mysqld server binary not found" | |
| echo "status=failed" >> $GITHUB_OUTPUT | |
| exit 1 | |
| fi | |
| END_TIME=$(date +%s) | |
| echo "duration=$((END_TIME - START_TIME))" >> $GITHUB_OUTPUT | |
| - name: Test 3 - Check MySQL version command | |
| id: test3 | |
| run: | | |
| START_TIME=$(date +%s) | |
| if mysql --version | grep -q "mysql"; then | |
| echo "✓ MySQL version command works" | |
| mysql --version | |
| echo "status=passed" >> $GITHUB_OUTPUT | |
| else | |
| echo "✗ MySQL version command failed" | |
| echo "status=failed" >> $GITHUB_OUTPUT | |
| exit 1 | |
| fi | |
| END_TIME=$(date +%s) | |
| echo "duration=$((END_TIME - START_TIME))" >> $GITHUB_OUTPUT | |
| - name: Test 4 - Start MySQL server | |
| id: test4 | |
| run: | | |
| START_TIME=$(date +%s) | |
| # Start MySQL service | |
| sudo systemctl start mysql | |
| sleep 3 | |
| # Check if MySQL is running | |
| if sudo systemctl is-active mysql; then | |
| echo "✓ MySQL server started successfully" | |
| echo "status=passed" >> $GITHUB_OUTPUT | |
| else | |
| echo "✗ MySQL server failed to start" | |
| sudo systemctl status mysql || true | |
| echo "status=failed" >> $GITHUB_OUTPUT | |
| exit 1 | |
| fi | |
| END_TIME=$(date +%s) | |
| echo "duration=$((END_TIME - START_TIME))" >> $GITHUB_OUTPUT | |
| - name: Test 5 - Connect to MySQL and execute query | |
| id: test5 | |
| run: | | |
| START_TIME=$(date +%s) | |
| # Try to connect and run a simple query | |
| if sudo mysql -e "SELECT VERSION();" | grep -q "[0-9]"; then | |
| echo "✓ Successfully connected to MySQL and executed query" | |
| sudo mysql -e "SELECT VERSION();" | |
| echo "status=passed" >> $GITHUB_OUTPUT | |
| else | |
| echo "✗ Failed to connect to MySQL" | |
| echo "status=failed" >> $GITHUB_OUTPUT | |
| exit 1 | |
| fi | |
| END_TIME=$(date +%s) | |
| echo "duration=$((END_TIME - START_TIME))" >> $GITHUB_OUTPUT | |
| - name: Test 6 - Create and query test database | |
| id: test6 | |
| run: | | |
| START_TIME=$(date +%s) | |
| # Create a test database | |
| sudo mysql -e "CREATE DATABASE IF NOT EXISTS test_db;" | |
| # Create a test table | |
| sudo mysql -e "USE test_db; CREATE TABLE IF NOT EXISTS test_table (id INT, name VARCHAR(50));" | |
| # Insert test data | |
| sudo mysql -e "USE test_db; INSERT INTO test_table VALUES (1, 'ARM64 Test');" | |
| # Query the data | |
| RESULT=$(sudo mysql -e "USE test_db; SELECT * FROM test_table;" | grep "ARM64 Test" || echo "") | |
| # Cleanup | |
| sudo mysql -e "DROP DATABASE test_db;" | |
| if [ -n "$RESULT" ]; then | |
| echo "✓ Successfully created database, table, and queried data" | |
| echo "status=passed" >> $GITHUB_OUTPUT | |
| else | |
| echo "✗ Failed to create/query test database" | |
| echo "status=failed" >> $GITHUB_OUTPUT | |
| exit 1 | |
| fi | |
| END_TIME=$(date +%s) | |
| echo "duration=$((END_TIME - START_TIME))" >> $GITHUB_OUTPUT | |
| # ============================================================ | |
| # Calculate summary | |
| # ============================================================ | |
| - name: Calculate test summary | |
| if: always() | |
| id: summary | |
| run: | | |
| PASSED=0 | |
| FAILED=0 | |
| TOTAL_DURATION=0 | |
| # Test 1 | |
| if [ "${{ steps.test1.outputs.status }}" == "passed" ]; then | |
| PASSED=$((PASSED + 1)) | |
| else | |
| FAILED=$((FAILED + 1)) | |
| fi | |
| TOTAL_DURATION=$((TOTAL_DURATION + ${{ steps.test1.outputs.duration || 0 }})) | |
| # Test 2 | |
| if [ "${{ steps.test2.outputs.status }}" == "passed" ]; then | |
| PASSED=$((PASSED + 1)) | |
| else | |
| FAILED=$((FAILED + 1)) | |
| fi | |
| TOTAL_DURATION=$((TOTAL_DURATION + ${{ steps.test2.outputs.duration || 0 }})) | |
| # Test 3 | |
| if [ "${{ steps.test3.outputs.status }}" == "passed" ]; then | |
| PASSED=$((PASSED + 1)) | |
| else | |
| FAILED=$((FAILED + 1)) | |
| fi | |
| TOTAL_DURATION=$((TOTAL_DURATION + ${{ steps.test3.outputs.duration || 0 }})) | |
| # Test 4 | |
| if [ "${{ steps.test4.outputs.status }}" == "passed" ]; then | |
| PASSED=$((PASSED + 1)) | |
| else | |
| FAILED=$((FAILED + 1)) | |
| fi | |
| TOTAL_DURATION=$((TOTAL_DURATION + ${{ steps.test4.outputs.duration || 0 }})) | |
| # Test 5 | |
| if [ "${{ steps.test5.outputs.status }}" == "passed" ]; then | |
| PASSED=$((PASSED + 1)) | |
| else | |
| FAILED=$((FAILED + 1)) | |
| fi | |
| TOTAL_DURATION=$((TOTAL_DURATION + ${{ steps.test5.outputs.duration || 0 }})) | |
| # Test 6 | |
| if [ "${{ steps.test6.outputs.status }}" == "passed" ]; then | |
| PASSED=$((PASSED + 1)) | |
| else | |
| FAILED=$((FAILED + 1)) | |
| fi | |
| TOTAL_DURATION=$((TOTAL_DURATION + ${{ steps.test6.outputs.duration || 0 }})) | |
| echo "passed=$PASSED" >> $GITHUB_OUTPUT | |
| echo "failed=$FAILED" >> $GITHUB_OUTPUT | |
| echo "duration=$TOTAL_DURATION" >> $GITHUB_OUTPUT | |
| if [ $FAILED -eq 0 ]; then | |
| echo "overall_status=success" >> $GITHUB_OUTPUT | |
| echo "badge_status=passing" >> $GITHUB_OUTPUT | |
| else | |
| echo "overall_status=failure" >> $GITHUB_OUTPUT | |
| echo "badge_status=failing" >> $GITHUB_OUTPUT | |
| fi | |
| # ============================================================ | |
| # Generate JSON with MySQL metadata | |
| # ============================================================ | |
| - name: Generate test results JSON | |
| if: always() | |
| run: | | |
| mkdir -p test-results | |
| cat > test-results/mysql.json << EOF | |
| { | |
| "schema_version": "1.0", | |
| "package": { | |
| "name": "MySQL", | |
| "version": "${{ steps.version.outputs.version }}", | |
| "language": "c++", | |
| "category": "Database" | |
| }, | |
| "run": { | |
| "id": "${{ github.run_id }}", | |
| "url": "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}", | |
| "timestamp": "${{ steps.metadata.outputs.timestamp }}", | |
| "status": "${{ steps.summary.outputs.overall_status }}", | |
| "runner": { | |
| "os": "ubuntu-24.04", | |
| "arch": "arm64" | |
| } | |
| }, | |
| "tests": { | |
| "passed": ${{ steps.summary.outputs.passed }}, | |
| "failed": ${{ steps.summary.outputs.failed }}, | |
| "skipped": 0, | |
| "duration_seconds": ${{ steps.summary.outputs.duration }}, | |
| "details": [ | |
| { | |
| "name": "Check mysql client binary exists", | |
| "status": "${{ steps.test1.outputs.status }}", | |
| "duration_seconds": ${{ steps.test1.outputs.duration || 0 }} | |
| }, | |
| { | |
| "name": "Check mysqld server binary exists", | |
| "status": "${{ steps.test2.outputs.status }}", | |
| "duration_seconds": ${{ steps.test2.outputs.duration || 0 }} | |
| }, | |
| { | |
| "name": "Check MySQL version command", | |
| "status": "${{ steps.test3.outputs.status }}", | |
| "duration_seconds": ${{ steps.test3.outputs.duration || 0 }} | |
| }, | |
| { | |
| "name": "Start MySQL server", | |
| "status": "${{ steps.test4.outputs.status }}", | |
| "duration_seconds": ${{ steps.test4.outputs.duration || 0 }} | |
| }, | |
| { | |
| "name": "Connect to MySQL and execute query", | |
| "status": "${{ steps.test5.outputs.status }}", | |
| "duration_seconds": ${{ steps.test5.outputs.duration || 0 }} | |
| }, | |
| { | |
| "name": "Create and query test database", | |
| "status": "${{ steps.test6.outputs.status }}", | |
| "duration_seconds": ${{ steps.test6.outputs.duration || 0 }} | |
| } | |
| ] | |
| }, | |
| "metadata": { | |
| "dashboard_link": "${{ steps.metadata.outputs.dashboard_link }}", | |
| "badge_status": "${{ steps.summary.outputs.badge_status }}" | |
| } | |
| } | |
| EOF | |
| echo "Generated test results:" | |
| cat test-results/mysql.json | |
| # ============================================================ | |
| # STANDARD STEPS - Commit results to repository | |
| # ============================================================ | |
| - name: Upload test results | |
| if: always() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: mysql-test-results | |
| path: test-results/mysql.json | |
| retention-days: 90 | |
| - name: Commit test results to repository | |
| if: always() && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/smoke_tests') | |
| run: | | |
| git config --global user.name 'github-actions[bot]' | |
| git config --global user.email 'github-actions[bot]@users.noreply.github.com' | |
| mkdir -p data/test-results | |
| cp test-results/mysql.json data/test-results/mysql.json | |
| git add data/test-results/mysql.json | |
| if ! git diff --staged --quiet; then | |
| git commit -m "Update mysql test results [skip ci]" | |
| # Pull with rebase and push, retry up to 5 times | |
| for i in {1..5}; do | |
| if git pull --rebase origin ${{ github.ref_name }}; then | |
| # Rebase succeeded, try to push | |
| if git push; then | |
| echo "Successfully pushed test results" | |
| break | |
| fi | |
| else | |
| # Rebase failed, likely due to conflict | |
| echo "Rebase failed, resolving conflicts..." | |
| # Accept our version of the file (the new test results) | |
| git checkout --ours data/test-results/mysql.json | |
| git add data/test-results/mysql.json | |
| # Continue the rebase | |
| git rebase --continue || true | |
| fi | |
| # Wait before retry | |
| sleep $((i * 2)) | |
| done | |
| else | |
| echo "No changes to commit" | |
| fi |