Add Apache Cassandra test workflow with 5 tests for NoSQL database #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
| name: Test Cassandra on Arm64 | |
| on: | |
| workflow_call: | |
| workflow_dispatch: | |
| push: | |
| branches: | |
| - main | |
| - smoke_tests | |
| paths: | |
| - 'content/opensource_packages/cassandra.md' | |
| - '.github/workflows/test-cassandra.yml' | |
| jobs: | |
| test-cassandra: | |
| 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=cassandra" >> $GITHUB_OUTPUT | |
| echo "dashboard_link=/opensource_packages/cassandra" >> $GITHUB_OUTPUT | |
| # ============================================================ | |
| # Install Apache Cassandra and dependencies | |
| # ============================================================ | |
| - name: Install Java (Cassandra dependency) | |
| id: install_java | |
| run: | | |
| echo "Installing Java 17..." | |
| sudo apt-get update | |
| sudo apt-get install -y openjdk-17-jdk | |
| java -version | |
| echo "JAVA_HOME=$(dirname $(dirname $(readlink -f $(which java))))" >> $GITHUB_ENV | |
| - name: Install Apache Cassandra | |
| id: install | |
| run: | | |
| echo "Installing Apache Cassandra..." | |
| # Add Apache Cassandra repository | |
| wget -q https://downloads.apache.org/cassandra/KEYS | |
| sudo gpg --no-default-keyring --keyring /usr/share/keyrings/cassandra-archive-keyring.gpg --import KEYS || true | |
| echo "deb [signed-by=/usr/share/keyrings/cassandra-archive-keyring.gpg] https://debian.cassandra.apache.org 41x main" | sudo tee /etc/apt/sources.list.d/cassandra.list | |
| # Install Cassandra | |
| sudo apt-get update | |
| sudo apt-get install -y cassandra | |
| # Verify installation | |
| if command -v cassandra &> /dev/null; then | |
| echo "Cassandra installed successfully" | |
| echo "install_status=success" >> $GITHUB_OUTPUT | |
| else | |
| echo "Cassandra installation failed" | |
| echo "install_status=failed" >> $GITHUB_OUTPUT | |
| exit 1 | |
| fi | |
| # ============================================================ | |
| # Detect version | |
| # ============================================================ | |
| - name: Detect Cassandra version | |
| id: version | |
| run: | | |
| VERSION=$(cassandra -v 2>&1 | grep -oP '(?<=Apache Cassandra )[0-9.]+' || echo "unknown") | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| echo "Detected Cassandra version: $VERSION" | |
| cassandra -v 2>&1 || true | |
| # ============================================================ | |
| # Run tests | |
| # ============================================================ | |
| - name: Test 1 - Check cassandra binary exists | |
| id: test1 | |
| run: | | |
| START_TIME=$(date +%s) | |
| if command -v cassandra &> /dev/null; then | |
| echo "✓ cassandra command found" | |
| which cassandra | |
| echo "status=passed" >> $GITHUB_OUTPUT | |
| else | |
| echo "✗ cassandra command 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 cqlsh binary exists | |
| id: test2 | |
| run: | | |
| START_TIME=$(date +%s) | |
| if command -v cqlsh &> /dev/null; then | |
| echo "✓ cqlsh command found" | |
| which cqlsh | |
| echo "status=passed" >> $GITHUB_OUTPUT | |
| else | |
| echo "✗ cqlsh command 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 Cassandra version command | |
| id: test3 | |
| run: | | |
| START_TIME=$(date +%s) | |
| if cassandra -v 2>&1 | grep -q "Apache Cassandra"; then | |
| echo "✓ Cassandra version check passed" | |
| cassandra -v 2>&1 | |
| echo "status=passed" >> $GITHUB_OUTPUT | |
| else | |
| echo "✗ Cassandra version check failed" | |
| echo "status=failed" >> $GITHUB_OUTPUT | |
| exit 1 | |
| fi | |
| END_TIME=$(date +%s) | |
| echo "duration=$((END_TIME - START_TIME))" >> $GITHUB_OUTPUT | |
| - name: Test 4 - Verify Java dependency | |
| id: test4 | |
| run: | | |
| START_TIME=$(date +%s) | |
| if java -version 2>&1 | grep -q "openjdk"; then | |
| echo "✓ Java is installed and accessible" | |
| java -version | |
| echo "status=passed" >> $GITHUB_OUTPUT | |
| else | |
| echo "✗ Java check failed" | |
| echo "status=failed" >> $GITHUB_OUTPUT | |
| exit 1 | |
| fi | |
| END_TIME=$(date +%s) | |
| echo "duration=$((END_TIME - START_TIME))" >> $GITHUB_OUTPUT | |
| - name: Test 5 - Check nodetool binary (cluster management) | |
| id: test5 | |
| run: | | |
| START_TIME=$(date +%s) | |
| if command -v nodetool &> /dev/null; then | |
| echo "✓ nodetool command found" | |
| which nodetool | |
| nodetool version 2>&1 || echo "nodetool binary exists" | |
| echo "status=passed" >> $GITHUB_OUTPUT | |
| else | |
| echo "✗ nodetool command not found" | |
| 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 }})) | |
| 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 Cassandra metadata | |
| # ============================================================ | |
| - name: Generate test results JSON | |
| if: always() | |
| run: | | |
| mkdir -p test-results | |
| cat > test-results/cassandra.json << EOF | |
| { | |
| "schema_version": "1.0", | |
| "package": { | |
| "name": "Apache Cassandra", | |
| "version": "${{ steps.version.outputs.version }}", | |
| "language": "java", | |
| "category": "Databases - noSQL" | |
| }, | |
| "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 cassandra binary exists", | |
| "status": "${{ steps.test1.outputs.status }}", | |
| "duration_seconds": ${{ steps.test1.outputs.duration || 0 }} | |
| }, | |
| { | |
| "name": "Check cqlsh binary exists", | |
| "status": "${{ steps.test2.outputs.status }}", | |
| "duration_seconds": ${{ steps.test2.outputs.duration || 0 }} | |
| }, | |
| { | |
| "name": "Check Cassandra version command", | |
| "status": "${{ steps.test3.outputs.status }}", | |
| "duration_seconds": ${{ steps.test3.outputs.duration || 0 }} | |
| }, | |
| { | |
| "name": "Verify Java dependency", | |
| "status": "${{ steps.test4.outputs.status }}", | |
| "duration_seconds": ${{ steps.test4.outputs.duration || 0 }} | |
| }, | |
| { | |
| "name": "Check nodetool binary (cluster management)", | |
| "status": "${{ steps.test5.outputs.status }}", | |
| "duration_seconds": ${{ steps.test5.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/cassandra.json | |
| # ============================================================ | |
| # STANDARD STEPS - Commit results to repository | |
| # ============================================================ | |
| - name: Upload test results | |
| if: always() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: cassandra-test-results | |
| path: test-results/cassandra.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/cassandra.json data/test-results/cassandra.json | |
| git add data/test-results/cassandra.json | |
| if ! git diff --staged --quiet; then | |
| git commit -m "Update cassandra test results [skip ci]" | |
| # Retry logic for push | |
| MAX_RETRIES=5 | |
| RETRY_COUNT=0 | |
| while [ $RETRY_COUNT -lt $MAX_RETRIES ]; do | |
| if git push origin ${{ github.ref_name }}; then | |
| echo "Successfully pushed test results" | |
| break | |
| else | |
| RETRY_COUNT=$((RETRY_COUNT + 1)) | |
| if [ $RETRY_COUNT -lt $MAX_RETRIES ]; then | |
| echo "Push failed, attempt $RETRY_COUNT of $MAX_RETRIES. Retrying in 5 seconds..." | |
| sleep 5 | |
| git pull --rebase origin ${{ github.ref_name }} | |
| else | |
| echo "Failed to push after $MAX_RETRIES attempts" | |
| exit 1 | |
| fi | |
| fi | |
| done | |
| else | |
| echo "No changes to commit" | |
| fi |