|
| 1 | +# Memcached Test Workflow |
| 2 | +# Tests Memcached on ARM64 architecture |
| 3 | +# Memcached is a high-performance distributed memory caching system |
| 4 | + |
| 5 | +name: Test Memcached on Arm64 |
| 6 | + |
| 7 | +on: |
| 8 | + workflow_dispatch: |
| 9 | + workflow_call: |
| 10 | + push: |
| 11 | + branches: |
| 12 | + - main |
| 13 | + - smoke_tests |
| 14 | + paths: |
| 15 | + - 'content/opensource_packages/memcached.md' |
| 16 | + - '.github/workflows/test-memcached.yml' |
| 17 | + |
| 18 | +jobs: |
| 19 | + test-memcached: |
| 20 | + runs-on: ubuntu-24.04-arm |
| 21 | + |
| 22 | + steps: |
| 23 | + - name: Checkout repository |
| 24 | + uses: actions/checkout@v4 |
| 25 | + |
| 26 | + - name: Set test metadata |
| 27 | + id: metadata |
| 28 | + run: | |
| 29 | + echo "timestamp=$(date -u +%Y-%m-%dT%H:%M:%SZ)" >> $GITHUB_OUTPUT |
| 30 | + echo "package_slug=memcached" >> $GITHUB_OUTPUT |
| 31 | + echo "dashboard_link=/opensource_packages/memcached" >> $GITHUB_OUTPUT |
| 32 | + |
| 33 | + # ============================================================ |
| 34 | + # Install Memcached |
| 35 | + # ============================================================ |
| 36 | + - name: Install Memcached |
| 37 | + id: install |
| 38 | + run: | |
| 39 | + echo "Installing Memcached..." |
| 40 | + |
| 41 | + sudo apt-get update |
| 42 | + sudo apt-get install -y memcached libmemcached-tools |
| 43 | + |
| 44 | + # Verify installation |
| 45 | + if command -v memcached &> /dev/null; then |
| 46 | + echo "Memcached installed successfully" |
| 47 | + echo "install_status=success" >> $GITHUB_OUTPUT |
| 48 | + else |
| 49 | + echo "Memcached installation failed" |
| 50 | + echo "install_status=failed" >> $GITHUB_OUTPUT |
| 51 | + exit 1 |
| 52 | + fi |
| 53 | + |
| 54 | + # ============================================================ |
| 55 | + # Get Memcached version |
| 56 | + # ============================================================ |
| 57 | + - name: Get Memcached version |
| 58 | + id: version |
| 59 | + run: | |
| 60 | + VERSION=$(memcached -h 2>&1 | grep -oP 'memcached \K[0-9.]+' | head -1 || echo "unknown") |
| 61 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 62 | + echo "Detected Memcached version: $VERSION" |
| 63 | + |
| 64 | + # ============================================================ |
| 65 | + # Memcached Tests |
| 66 | + # ============================================================ |
| 67 | + |
| 68 | + - name: Test 1 - Check memcached binary exists |
| 69 | + id: test1 |
| 70 | + run: | |
| 71 | + START_TIME=$(date +%s) |
| 72 | + |
| 73 | + if command -v memcached &> /dev/null; then |
| 74 | + echo "✓ memcached binary found" |
| 75 | + echo "status=passed" >> $GITHUB_OUTPUT |
| 76 | + else |
| 77 | + echo "✗ memcached binary not found" |
| 78 | + echo "status=failed" >> $GITHUB_OUTPUT |
| 79 | + exit 1 |
| 80 | + fi |
| 81 | + |
| 82 | + END_TIME=$(date +%s) |
| 83 | + echo "duration=$((END_TIME - START_TIME))" >> $GITHUB_OUTPUT |
| 84 | + |
| 85 | + - name: Test 2 - Check memcached help output |
| 86 | + id: test2 |
| 87 | + run: | |
| 88 | + START_TIME=$(date +%s) |
| 89 | + |
| 90 | + if memcached -h 2>&1 | grep -q "memcached"; then |
| 91 | + echo "✓ memcached help command works" |
| 92 | + echo "status=passed" >> $GITHUB_OUTPUT |
| 93 | + else |
| 94 | + echo "✗ memcached help command failed" |
| 95 | + echo "status=failed" >> $GITHUB_OUTPUT |
| 96 | + exit 1 |
| 97 | + fi |
| 98 | + |
| 99 | + END_TIME=$(date +%s) |
| 100 | + echo "duration=$((END_TIME - START_TIME))" >> $GITHUB_OUTPUT |
| 101 | + |
| 102 | + - name: Test 3 - Start memcached server (test mode) |
| 103 | + id: test3 |
| 104 | + run: | |
| 105 | + START_TIME=$(date +%s) |
| 106 | + |
| 107 | + # Start memcached in background on port 11212 (avoid default port conflicts) |
| 108 | + memcached -p 11212 -u root -d |
| 109 | + sleep 2 |
| 110 | + |
| 111 | + # Check if it's running |
| 112 | + if pgrep -x memcached > /dev/null; then |
| 113 | + echo "✓ memcached server started successfully" |
| 114 | + echo "status=passed" >> $GITHUB_OUTPUT |
| 115 | + |
| 116 | + # Stop it |
| 117 | + pkill memcached |
| 118 | + else |
| 119 | + echo "✗ memcached server failed to start" |
| 120 | + echo "status=failed" >> $GITHUB_OUTPUT |
| 121 | + exit 1 |
| 122 | + fi |
| 123 | + |
| 124 | + END_TIME=$(date +%s) |
| 125 | + echo "duration=$((END_TIME - START_TIME))" >> $GITHUB_OUTPUT |
| 126 | + |
| 127 | + - name: Test 4 - Test memcached connection with memcstat |
| 128 | + id: test4 |
| 129 | + run: | |
| 130 | + START_TIME=$(date +%s) |
| 131 | + |
| 132 | + # Start memcached for testing |
| 133 | + memcached -p 11213 -u root -d |
| 134 | + sleep 2 |
| 135 | + |
| 136 | + # Test connection using memcstat (from libmemcached-tools) |
| 137 | + if command -v memcstat &> /dev/null; then |
| 138 | + if memcstat --servers=localhost:11213 2>&1 | grep -q "Server:"; then |
| 139 | + echo "✓ memcached connection test passed" |
| 140 | + echo "status=passed" >> $GITHUB_OUTPUT |
| 141 | + else |
| 142 | + echo "✗ memcached connection test failed" |
| 143 | + echo "status=failed" >> $GITHUB_OUTPUT |
| 144 | + pkill memcached |
| 145 | + exit 1 |
| 146 | + fi |
| 147 | + else |
| 148 | + echo "✓ memcstat not available, skipping connection test" |
| 149 | + echo "status=passed" >> $GITHUB_OUTPUT |
| 150 | + fi |
| 151 | + |
| 152 | + # Cleanup |
| 153 | + pkill memcached || true |
| 154 | + |
| 155 | + END_TIME=$(date +%s) |
| 156 | + echo "duration=$((END_TIME - START_TIME))" >> $GITHUB_OUTPUT |
| 157 | + |
| 158 | + # ============================================================ |
| 159 | + # Calculate summary |
| 160 | + # ============================================================ |
| 161 | + - name: Calculate test summary |
| 162 | + if: always() |
| 163 | + id: summary |
| 164 | + run: | |
| 165 | + PASSED=0 |
| 166 | + FAILED=0 |
| 167 | + TOTAL_DURATION=0 |
| 168 | + |
| 169 | + # Test 1 |
| 170 | + if [ "${{ steps.test1.outputs.status }}" == "passed" ]; then |
| 171 | + PASSED=$((PASSED + 1)) |
| 172 | + else |
| 173 | + FAILED=$((FAILED + 1)) |
| 174 | + fi |
| 175 | + TOTAL_DURATION=$((TOTAL_DURATION + ${{ steps.test1.outputs.duration || 0 }})) |
| 176 | + |
| 177 | + # Test 2 |
| 178 | + if [ "${{ steps.test2.outputs.status }}" == "passed" ]; then |
| 179 | + PASSED=$((PASSED + 1)) |
| 180 | + else |
| 181 | + FAILED=$((FAILED + 1)) |
| 182 | + fi |
| 183 | + TOTAL_DURATION=$((TOTAL_DURATION + ${{ steps.test2.outputs.duration || 0 }})) |
| 184 | + |
| 185 | + # Test 3 |
| 186 | + if [ "${{ steps.test3.outputs.status }}" == "passed" ]; then |
| 187 | + PASSED=$((PASSED + 1)) |
| 188 | + else |
| 189 | + FAILED=$((FAILED + 1)) |
| 190 | + fi |
| 191 | + TOTAL_DURATION=$((TOTAL_DURATION + ${{ steps.test3.outputs.duration || 0 }})) |
| 192 | + |
| 193 | + # Test 4 |
| 194 | + if [ "${{ steps.test4.outputs.status }}" == "passed" ]; then |
| 195 | + PASSED=$((PASSED + 1)) |
| 196 | + else |
| 197 | + FAILED=$((FAILED + 1)) |
| 198 | + fi |
| 199 | + TOTAL_DURATION=$((TOTAL_DURATION + ${{ steps.test4.outputs.duration || 0 }})) |
| 200 | + |
| 201 | + echo "passed=$PASSED" >> $GITHUB_OUTPUT |
| 202 | + echo "failed=$FAILED" >> $GITHUB_OUTPUT |
| 203 | + echo "duration=$TOTAL_DURATION" >> $GITHUB_OUTPUT |
| 204 | + |
| 205 | + if [ $FAILED -eq 0 ]; then |
| 206 | + echo "overall_status=success" >> $GITHUB_OUTPUT |
| 207 | + echo "badge_status=passing" >> $GITHUB_OUTPUT |
| 208 | + else |
| 209 | + echo "overall_status=failure" >> $GITHUB_OUTPUT |
| 210 | + echo "badge_status=failing" >> $GITHUB_OUTPUT |
| 211 | + fi |
| 212 | + |
| 213 | + # ============================================================ |
| 214 | + # Generate JSON with Memcached metadata |
| 215 | + # ============================================================ |
| 216 | + - name: Generate test results JSON |
| 217 | + if: always() |
| 218 | + run: | |
| 219 | + mkdir -p test-results |
| 220 | + |
| 221 | + cat > test-results/memcached.json << EOF |
| 222 | + { |
| 223 | + "schema_version": "1.0", |
| 224 | + "package": { |
| 225 | + "name": "Memcached", |
| 226 | + "version": "${{ steps.version.outputs.version }}", |
| 227 | + "language": "c", |
| 228 | + "category": "Database" |
| 229 | + }, |
| 230 | + "run": { |
| 231 | + "id": "${{ github.run_id }}", |
| 232 | + "url": "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}", |
| 233 | + "timestamp": "${{ steps.metadata.outputs.timestamp }}", |
| 234 | + "status": "${{ steps.summary.outputs.overall_status }}", |
| 235 | + "runner": { |
| 236 | + "os": "ubuntu-24.04", |
| 237 | + "arch": "arm64" |
| 238 | + } |
| 239 | + }, |
| 240 | + "tests": { |
| 241 | + "passed": ${{ steps.summary.outputs.passed }}, |
| 242 | + "failed": ${{ steps.summary.outputs.failed }}, |
| 243 | + "skipped": 0, |
| 244 | + "duration_seconds": ${{ steps.summary.outputs.duration }}, |
| 245 | + "details": [ |
| 246 | + { |
| 247 | + "name": "Check memcached binary exists", |
| 248 | + "status": "${{ steps.test1.outputs.status }}", |
| 249 | + "duration_seconds": ${{ steps.test1.outputs.duration || 0 }} |
| 250 | + }, |
| 251 | + { |
| 252 | + "name": "Check memcached help output", |
| 253 | + "status": "${{ steps.test2.outputs.status }}", |
| 254 | + "duration_seconds": ${{ steps.test2.outputs.duration || 0 }} |
| 255 | + }, |
| 256 | + { |
| 257 | + "name": "Start memcached server (test mode)", |
| 258 | + "status": "${{ steps.test3.outputs.status }}", |
| 259 | + "duration_seconds": ${{ steps.test3.outputs.duration || 0 }} |
| 260 | + }, |
| 261 | + { |
| 262 | + "name": "Test memcached connection with memcstat", |
| 263 | + "status": "${{ steps.test4.outputs.status }}", |
| 264 | + "duration_seconds": ${{ steps.test4.outputs.duration || 0 }} |
| 265 | + } |
| 266 | + ] |
| 267 | + }, |
| 268 | + "metadata": { |
| 269 | + "dashboard_link": "${{ steps.metadata.outputs.dashboard_link }}", |
| 270 | + "badge_status": "${{ steps.summary.outputs.badge_status }}" |
| 271 | + } |
| 272 | + } |
| 273 | + EOF |
| 274 | + |
| 275 | + echo "Generated test results:" |
| 276 | + cat test-results/memcached.json |
| 277 | + |
| 278 | + # ============================================================ |
| 279 | + # STANDARD STEPS - Commit results to repository |
| 280 | + # ============================================================ |
| 281 | + |
| 282 | + - name: Upload test results |
| 283 | + if: always() |
| 284 | + uses: actions/upload-artifact@v4 |
| 285 | + with: |
| 286 | + name: memcached-test-results |
| 287 | + path: test-results/memcached.json |
| 288 | + retention-days: 90 |
| 289 | + |
| 290 | + - name: Commit test results to repository |
| 291 | + if: always() && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/smoke_tests') |
| 292 | + run: | |
| 293 | + git config --global user.name 'github-actions[bot]' |
| 294 | + git config --global user.email 'github-actions[bot]@users.noreply.github.com' |
| 295 | + |
| 296 | + mkdir -p data/test-results |
| 297 | + cp test-results/memcached.json data/test-results/memcached.json |
| 298 | + |
| 299 | + git add data/test-results/memcached.json |
| 300 | + |
| 301 | + if ! git diff --staged --quiet; then |
| 302 | + git commit -m "Update memcached test results [skip ci]" |
| 303 | + |
| 304 | + # Pull with rebase and push, retry up to 5 times |
| 305 | + for i in {1..5}; do |
| 306 | + if git pull --rebase origin ${{ github.ref_name }}; then |
| 307 | + # Rebase succeeded, try to push |
| 308 | + if git push; then |
| 309 | + echo "Successfully pushed test results" |
| 310 | + break |
| 311 | + fi |
| 312 | + else |
| 313 | + # Rebase failed, likely due to conflict |
| 314 | + echo "Rebase failed, resolving conflicts..." |
| 315 | + |
| 316 | + # Accept our version of the file (the new test results) |
| 317 | + git checkout --ours data/test-results/memcached.json |
| 318 | + git add data/test-results/memcached.json |
| 319 | + |
| 320 | + # Continue the rebase |
| 321 | + git rebase --continue || true |
| 322 | + fi |
| 323 | + |
| 324 | + # Wait before retry |
| 325 | + sleep $((i * 2)) |
| 326 | + done |
| 327 | + else |
| 328 | + echo "No changes to commit" |
| 329 | + fi |
0 commit comments