|
9 | 9 | tests: |
10 | 10 | name: "Unit and E2E Tests" |
11 | 11 | runs-on: ubuntu-latest |
| 12 | + permissions: |
| 13 | + contents: read |
| 14 | + pull-requests: write |
12 | 15 | steps: |
13 | 16 | - name: Checkout code |
14 | 17 | uses: actions/checkout@v4 |
|
42 | 45 | docker compose logs |
43 | 46 | exit 1 |
44 | 47 |
|
| 48 | + - name: Collect Docker stats |
| 49 | + if: github.event_name == 'pull_request' |
| 50 | + continue-on-error: true |
| 51 | + id: docker-stats |
| 52 | + run: | |
| 53 | + # Get image size |
| 54 | + IMAGE_SIZE=$(docker images appwrite/browser:local --format "{{.Size}}") |
| 55 | +
|
| 56 | + # Get container stats |
| 57 | + CONTAINER_ID=$(docker compose ps -q appwrite-browser) |
| 58 | + MEMORY_USAGE=$(docker stats $CONTAINER_ID --no-stream --format "{{.MemUsage}}" | cut -d'/' -f1 | xargs) |
| 59 | +
|
| 60 | + # Quick screenshot benchmark (3 runs, average) |
| 61 | + TOTAL=0 |
| 62 | + for i in {1..3}; do |
| 63 | + START=$(date +%s%3N) |
| 64 | + curl -s -X POST http://localhost:3000/v1/screenshots \ |
| 65 | + -H "Content-Type: application/json" \ |
| 66 | + -d '{"url":"https://appwrite.io"}' \ |
| 67 | + -o /dev/null |
| 68 | + END=$(date +%s%3N) |
| 69 | + DURATION=$((END - START)) |
| 70 | + TOTAL=$((TOTAL + DURATION)) |
| 71 | + done |
| 72 | + SCREENSHOT_AVG_MS=$((TOTAL / 3)) |
| 73 | + SCREENSHOT_AVG=$(echo "scale=2; $SCREENSHOT_AVG_MS / 1000" | bc) |
| 74 | +
|
| 75 | + # Measure fresh startup time |
| 76 | + START_TIME=$(date +%s%3N) |
| 77 | + docker compose restart appwrite-browser |
| 78 | + for i in {1..30}; do |
| 79 | + if curl -f http://localhost:3000/v1/health > /dev/null 2>&1; then |
| 80 | + END_TIME=$(date +%s%3N) |
| 81 | + STARTUP_TIME_MS=$((END_TIME - START_TIME)) |
| 82 | + break |
| 83 | + fi |
| 84 | + sleep 0.1 |
| 85 | + done |
| 86 | + STARTUP_TIME=$(echo "scale=2; $STARTUP_TIME_MS / 1000" | bc) |
| 87 | +
|
| 88 | + # Store in GitHub output |
| 89 | + echo "image_size=$IMAGE_SIZE" >> $GITHUB_OUTPUT |
| 90 | + echo "memory_usage=$MEMORY_USAGE" >> $GITHUB_OUTPUT |
| 91 | + echo "startup_time=$STARTUP_TIME" >> $GITHUB_OUTPUT |
| 92 | + echo "screenshot_time=$SCREENSHOT_AVG" >> $GITHUB_OUTPUT |
| 93 | +
|
| 94 | + - name: Comment PR with stats |
| 95 | + if: github.event_name == 'pull_request' && steps.docker-stats.outcome == 'success' |
| 96 | + continue-on-error: true |
| 97 | + uses: marocchino/sticky-pull-request-comment@v2 |
| 98 | + with: |
| 99 | + header: docker-image-stats |
| 100 | + skip_unchanged: true |
| 101 | + message: | |
| 102 | + ## Docker Image Stats |
| 103 | +
|
| 104 | + | Metric | Value | |
| 105 | + |--------|-------| |
| 106 | + | Image Size | ${{ steps.docker-stats.outputs.image_size }} | |
| 107 | + | Memory Usage | ${{ steps.docker-stats.outputs.memory_usage }} | |
| 108 | + | Startup Time | ${{ steps.docker-stats.outputs.startup_time }}s | |
| 109 | + | Screenshot Time | ${{ steps.docker-stats.outputs.screenshot_time }}s | |
| 110 | +
|
| 111 | + <sub>Screenshot benchmark: Average of 3 runs on https://appwrite.io</sub> |
| 112 | +
|
45 | 113 | - name: Run e2e tests |
46 | 114 | run: bun test:e2e |
47 | 115 |
|
|
0 commit comments