|
| 1 | +name: Test Cassandra on Arm64 |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + workflow_dispatch: |
| 6 | + push: |
| 7 | + branches: |
| 8 | + - main |
| 9 | + - smoke_tests |
| 10 | + paths: |
| 11 | + - 'content/opensource_packages/cassandra.md' |
| 12 | + - '.github/workflows/test-cassandra.yml' |
| 13 | + |
| 14 | +jobs: |
| 15 | + test-cassandra: |
| 16 | + runs-on: ubuntu-24.04-arm |
| 17 | + |
| 18 | + steps: |
| 19 | + - name: Checkout repository |
| 20 | + uses: actions/checkout@v4 |
| 21 | + |
| 22 | + - name: Set test metadata |
| 23 | + id: metadata |
| 24 | + run: | |
| 25 | + echo "timestamp=$(date -u +%Y-%m-%dT%H:%M:%SZ)" >> $GITHUB_OUTPUT |
| 26 | + echo "package_slug=cassandra" >> $GITHUB_OUTPUT |
| 27 | + echo "dashboard_link=/opensource_packages/cassandra" >> $GITHUB_OUTPUT |
| 28 | + |
| 29 | + # ============================================================ |
| 30 | + # Install Apache Cassandra and dependencies |
| 31 | + # ============================================================ |
| 32 | + - name: Install Java (Cassandra dependency) |
| 33 | + id: install_java |
| 34 | + run: | |
| 35 | + echo "Installing Java 17..." |
| 36 | + sudo apt-get update |
| 37 | + sudo apt-get install -y openjdk-17-jdk |
| 38 | + |
| 39 | + java -version |
| 40 | + echo "JAVA_HOME=$(dirname $(dirname $(readlink -f $(which java))))" >> $GITHUB_ENV |
| 41 | + |
| 42 | + - name: Install Apache Cassandra |
| 43 | + id: install |
| 44 | + run: | |
| 45 | + echo "Installing Apache Cassandra..." |
| 46 | + |
| 47 | + # Add Apache Cassandra repository |
| 48 | + wget -q https://downloads.apache.org/cassandra/KEYS |
| 49 | + sudo gpg --no-default-keyring --keyring /usr/share/keyrings/cassandra-archive-keyring.gpg --import KEYS || true |
| 50 | + |
| 51 | + 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 |
| 52 | + |
| 53 | + # Install Cassandra |
| 54 | + sudo apt-get update |
| 55 | + sudo apt-get install -y cassandra |
| 56 | + |
| 57 | + # Verify installation |
| 58 | + if command -v cassandra &> /dev/null; then |
| 59 | + echo "Cassandra installed successfully" |
| 60 | + echo "install_status=success" >> $GITHUB_OUTPUT |
| 61 | + else |
| 62 | + echo "Cassandra installation failed" |
| 63 | + echo "install_status=failed" >> $GITHUB_OUTPUT |
| 64 | + exit 1 |
| 65 | + fi |
| 66 | + |
| 67 | + # ============================================================ |
| 68 | + # Detect version |
| 69 | + # ============================================================ |
| 70 | + - name: Detect Cassandra version |
| 71 | + id: version |
| 72 | + run: | |
| 73 | + VERSION=$(cassandra -v 2>&1 | grep -oP '(?<=Apache Cassandra )[0-9.]+' || echo "unknown") |
| 74 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 75 | + echo "Detected Cassandra version: $VERSION" |
| 76 | + cassandra -v 2>&1 || true |
| 77 | + |
| 78 | + # ============================================================ |
| 79 | + # Run tests |
| 80 | + # ============================================================ |
| 81 | + - name: Test 1 - Check cassandra binary exists |
| 82 | + id: test1 |
| 83 | + run: | |
| 84 | + START_TIME=$(date +%s) |
| 85 | + |
| 86 | + if command -v cassandra &> /dev/null; then |
| 87 | + echo "✓ cassandra command found" |
| 88 | + which cassandra |
| 89 | + echo "status=passed" >> $GITHUB_OUTPUT |
| 90 | + else |
| 91 | + echo "✗ cassandra command not found" |
| 92 | + echo "status=failed" >> $GITHUB_OUTPUT |
| 93 | + exit 1 |
| 94 | + fi |
| 95 | + |
| 96 | + END_TIME=$(date +%s) |
| 97 | + echo "duration=$((END_TIME - START_TIME))" >> $GITHUB_OUTPUT |
| 98 | + |
| 99 | + - name: Test 2 - Check cqlsh binary exists |
| 100 | + id: test2 |
| 101 | + run: | |
| 102 | + START_TIME=$(date +%s) |
| 103 | + |
| 104 | + if command -v cqlsh &> /dev/null; then |
| 105 | + echo "✓ cqlsh command found" |
| 106 | + which cqlsh |
| 107 | + echo "status=passed" >> $GITHUB_OUTPUT |
| 108 | + else |
| 109 | + echo "✗ cqlsh command not found" |
| 110 | + echo "status=failed" >> $GITHUB_OUTPUT |
| 111 | + exit 1 |
| 112 | + fi |
| 113 | + |
| 114 | + END_TIME=$(date +%s) |
| 115 | + echo "duration=$((END_TIME - START_TIME))" >> $GITHUB_OUTPUT |
| 116 | + |
| 117 | + - name: Test 3 - Check Cassandra version command |
| 118 | + id: test3 |
| 119 | + run: | |
| 120 | + START_TIME=$(date +%s) |
| 121 | + |
| 122 | + if cassandra -v 2>&1 | grep -q "Apache Cassandra"; then |
| 123 | + echo "✓ Cassandra version check passed" |
| 124 | + cassandra -v 2>&1 |
| 125 | + echo "status=passed" >> $GITHUB_OUTPUT |
| 126 | + else |
| 127 | + echo "✗ Cassandra version check failed" |
| 128 | + echo "status=failed" >> $GITHUB_OUTPUT |
| 129 | + exit 1 |
| 130 | + fi |
| 131 | + |
| 132 | + END_TIME=$(date +%s) |
| 133 | + echo "duration=$((END_TIME - START_TIME))" >> $GITHUB_OUTPUT |
| 134 | + |
| 135 | + - name: Test 4 - Verify Java dependency |
| 136 | + id: test4 |
| 137 | + run: | |
| 138 | + START_TIME=$(date +%s) |
| 139 | + |
| 140 | + if java -version 2>&1 | grep -q "openjdk"; then |
| 141 | + echo "✓ Java is installed and accessible" |
| 142 | + java -version |
| 143 | + echo "status=passed" >> $GITHUB_OUTPUT |
| 144 | + else |
| 145 | + echo "✗ Java check failed" |
| 146 | + echo "status=failed" >> $GITHUB_OUTPUT |
| 147 | + exit 1 |
| 148 | + fi |
| 149 | + |
| 150 | + END_TIME=$(date +%s) |
| 151 | + echo "duration=$((END_TIME - START_TIME))" >> $GITHUB_OUTPUT |
| 152 | + |
| 153 | + - name: Test 5 - Check nodetool binary (cluster management) |
| 154 | + id: test5 |
| 155 | + run: | |
| 156 | + START_TIME=$(date +%s) |
| 157 | + |
| 158 | + if command -v nodetool &> /dev/null; then |
| 159 | + echo "✓ nodetool command found" |
| 160 | + which nodetool |
| 161 | + nodetool version 2>&1 || echo "nodetool binary exists" |
| 162 | + echo "status=passed" >> $GITHUB_OUTPUT |
| 163 | + else |
| 164 | + echo "✗ nodetool command not found" |
| 165 | + echo "status=failed" >> $GITHUB_OUTPUT |
| 166 | + exit 1 |
| 167 | + fi |
| 168 | + |
| 169 | + END_TIME=$(date +%s) |
| 170 | + echo "duration=$((END_TIME - START_TIME))" >> $GITHUB_OUTPUT |
| 171 | + |
| 172 | + # ============================================================ |
| 173 | + # Calculate summary |
| 174 | + # ============================================================ |
| 175 | + - name: Calculate test summary |
| 176 | + if: always() |
| 177 | + id: summary |
| 178 | + run: | |
| 179 | + PASSED=0 |
| 180 | + FAILED=0 |
| 181 | + TOTAL_DURATION=0 |
| 182 | + |
| 183 | + # Test 1 |
| 184 | + if [ "${{ steps.test1.outputs.status }}" == "passed" ]; then |
| 185 | + PASSED=$((PASSED + 1)) |
| 186 | + else |
| 187 | + FAILED=$((FAILED + 1)) |
| 188 | + fi |
| 189 | + TOTAL_DURATION=$((TOTAL_DURATION + ${{ steps.test1.outputs.duration || 0 }})) |
| 190 | + |
| 191 | + # Test 2 |
| 192 | + if [ "${{ steps.test2.outputs.status }}" == "passed" ]; then |
| 193 | + PASSED=$((PASSED + 1)) |
| 194 | + else |
| 195 | + FAILED=$((FAILED + 1)) |
| 196 | + fi |
| 197 | + TOTAL_DURATION=$((TOTAL_DURATION + ${{ steps.test2.outputs.duration || 0 }})) |
| 198 | + |
| 199 | + # Test 3 |
| 200 | + if [ "${{ steps.test3.outputs.status }}" == "passed" ]; then |
| 201 | + PASSED=$((PASSED + 1)) |
| 202 | + else |
| 203 | + FAILED=$((FAILED + 1)) |
| 204 | + fi |
| 205 | + TOTAL_DURATION=$((TOTAL_DURATION + ${{ steps.test3.outputs.duration || 0 }})) |
| 206 | + |
| 207 | + # Test 4 |
| 208 | + if [ "${{ steps.test4.outputs.status }}" == "passed" ]; then |
| 209 | + PASSED=$((PASSED + 1)) |
| 210 | + else |
| 211 | + FAILED=$((FAILED + 1)) |
| 212 | + fi |
| 213 | + TOTAL_DURATION=$((TOTAL_DURATION + ${{ steps.test4.outputs.duration || 0 }})) |
| 214 | + |
| 215 | + # Test 5 |
| 216 | + if [ "${{ steps.test5.outputs.status }}" == "passed" ]; then |
| 217 | + PASSED=$((PASSED + 1)) |
| 218 | + else |
| 219 | + FAILED=$((FAILED + 1)) |
| 220 | + fi |
| 221 | + TOTAL_DURATION=$((TOTAL_DURATION + ${{ steps.test5.outputs.duration || 0 }})) |
| 222 | + |
| 223 | + echo "passed=$PASSED" >> $GITHUB_OUTPUT |
| 224 | + echo "failed=$FAILED" >> $GITHUB_OUTPUT |
| 225 | + echo "duration=$TOTAL_DURATION" >> $GITHUB_OUTPUT |
| 226 | + |
| 227 | + if [ $FAILED -eq 0 ]; then |
| 228 | + echo "overall_status=success" >> $GITHUB_OUTPUT |
| 229 | + echo "badge_status=passing" >> $GITHUB_OUTPUT |
| 230 | + else |
| 231 | + echo "overall_status=failure" >> $GITHUB_OUTPUT |
| 232 | + echo "badge_status=failing" >> $GITHUB_OUTPUT |
| 233 | + fi |
| 234 | + |
| 235 | + # ============================================================ |
| 236 | + # Generate JSON with Cassandra metadata |
| 237 | + # ============================================================ |
| 238 | + - name: Generate test results JSON |
| 239 | + if: always() |
| 240 | + run: | |
| 241 | + mkdir -p test-results |
| 242 | + |
| 243 | + cat > test-results/cassandra.json << EOF |
| 244 | + { |
| 245 | + "schema_version": "1.0", |
| 246 | + "package": { |
| 247 | + "name": "Apache Cassandra", |
| 248 | + "version": "${{ steps.version.outputs.version }}", |
| 249 | + "language": "java", |
| 250 | + "category": "Databases - noSQL" |
| 251 | + }, |
| 252 | + "run": { |
| 253 | + "id": "${{ github.run_id }}", |
| 254 | + "url": "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}", |
| 255 | + "timestamp": "${{ steps.metadata.outputs.timestamp }}", |
| 256 | + "status": "${{ steps.summary.outputs.overall_status }}", |
| 257 | + "runner": { |
| 258 | + "os": "ubuntu-24.04", |
| 259 | + "arch": "arm64" |
| 260 | + } |
| 261 | + }, |
| 262 | + "tests": { |
| 263 | + "passed": ${{ steps.summary.outputs.passed }}, |
| 264 | + "failed": ${{ steps.summary.outputs.failed }}, |
| 265 | + "skipped": 0, |
| 266 | + "duration_seconds": ${{ steps.summary.outputs.duration }}, |
| 267 | + "details": [ |
| 268 | + { |
| 269 | + "name": "Check cassandra binary exists", |
| 270 | + "status": "${{ steps.test1.outputs.status }}", |
| 271 | + "duration_seconds": ${{ steps.test1.outputs.duration || 0 }} |
| 272 | + }, |
| 273 | + { |
| 274 | + "name": "Check cqlsh binary exists", |
| 275 | + "status": "${{ steps.test2.outputs.status }}", |
| 276 | + "duration_seconds": ${{ steps.test2.outputs.duration || 0 }} |
| 277 | + }, |
| 278 | + { |
| 279 | + "name": "Check Cassandra version command", |
| 280 | + "status": "${{ steps.test3.outputs.status }}", |
| 281 | + "duration_seconds": ${{ steps.test3.outputs.duration || 0 }} |
| 282 | + }, |
| 283 | + { |
| 284 | + "name": "Verify Java dependency", |
| 285 | + "status": "${{ steps.test4.outputs.status }}", |
| 286 | + "duration_seconds": ${{ steps.test4.outputs.duration || 0 }} |
| 287 | + }, |
| 288 | + { |
| 289 | + "name": "Check nodetool binary (cluster management)", |
| 290 | + "status": "${{ steps.test5.outputs.status }}", |
| 291 | + "duration_seconds": ${{ steps.test5.outputs.duration || 0 }} |
| 292 | + } |
| 293 | + ] |
| 294 | + }, |
| 295 | + "metadata": { |
| 296 | + "dashboard_link": "${{ steps.metadata.outputs.dashboard_link }}", |
| 297 | + "badge_status": "${{ steps.summary.outputs.badge_status }}" |
| 298 | + } |
| 299 | + } |
| 300 | + EOF |
| 301 | + |
| 302 | + echo "Generated test results:" |
| 303 | + cat test-results/cassandra.json |
| 304 | + |
| 305 | + # ============================================================ |
| 306 | + # STANDARD STEPS - Commit results to repository |
| 307 | + # ============================================================ |
| 308 | + |
| 309 | + - name: Upload test results |
| 310 | + if: always() |
| 311 | + uses: actions/upload-artifact@v4 |
| 312 | + with: |
| 313 | + name: cassandra-test-results |
| 314 | + path: test-results/cassandra.json |
| 315 | + retention-days: 90 |
| 316 | + |
| 317 | + - name: Commit test results to repository |
| 318 | + if: always() && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/smoke_tests') |
| 319 | + run: | |
| 320 | + git config --global user.name 'github-actions[bot]' |
| 321 | + git config --global user.email 'github-actions[bot]@users.noreply.github.com' |
| 322 | + |
| 323 | + mkdir -p data/test-results |
| 324 | + cp test-results/cassandra.json data/test-results/cassandra.json |
| 325 | + |
| 326 | + git add data/test-results/cassandra.json |
| 327 | + |
| 328 | + if ! git diff --staged --quiet; then |
| 329 | + git commit -m "Update cassandra test results [skip ci]" |
| 330 | + |
| 331 | + # Retry logic for push |
| 332 | + MAX_RETRIES=5 |
| 333 | + RETRY_COUNT=0 |
| 334 | + |
| 335 | + while [ $RETRY_COUNT -lt $MAX_RETRIES ]; do |
| 336 | + if git push origin ${{ github.ref_name }}; then |
| 337 | + echo "Successfully pushed test results" |
| 338 | + break |
| 339 | + else |
| 340 | + RETRY_COUNT=$((RETRY_COUNT + 1)) |
| 341 | + if [ $RETRY_COUNT -lt $MAX_RETRIES ]; then |
| 342 | + echo "Push failed, attempt $RETRY_COUNT of $MAX_RETRIES. Retrying in 5 seconds..." |
| 343 | + sleep 5 |
| 344 | + git pull --rebase origin ${{ github.ref_name }} |
| 345 | + else |
| 346 | + echo "Failed to push after $MAX_RETRIES attempts" |
| 347 | + exit 1 |
| 348 | + fi |
| 349 | + fi |
| 350 | + done |
| 351 | + else |
| 352 | + echo "No changes to commit" |
| 353 | + fi |
0 commit comments