Skip to content

Merge pull request #11 from appwrite/aggressive-improvements #34

Merge pull request #11 from appwrite/aggressive-improvements

Merge pull request #11 from appwrite/aggressive-improvements #34

Workflow file for this run

name: "Test"
on:
pull_request:
push:
branches: [ main ]
jobs:
tests:
name: "Unit and E2E Tests"
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Bun
uses: oven-sh/setup-bun@v1
with:
bun-version: 'latest'
- name: Install dependencies
run: bun install --frozen-lockfile
- name: Run unit tests
run: bun test:unit
- name: Start container
run: docker compose up -d
- name: Wait for container to be ready
id: container-startup
run: |
START_TIME=$(date +%s%3N)
for i in {1..30}; do
if curl -f http://localhost:3000/v1/health > /dev/null 2>&1; then
END_TIME=$(date +%s%3N)
STARTUP_TIME_MS=$((END_TIME - START_TIME))
STARTUP_TIME=$(echo "scale=2; $STARTUP_TIME_MS / 1000" | bc)
echo "startup_time=$STARTUP_TIME" >> $GITHUB_OUTPUT
echo "Container is ready in ${STARTUP_TIME}s!"
exit 0
fi
echo "Waiting for container... ($i/30)"
sleep 1
done
echo "Container failed to start"
echo "Container logs:"
docker compose logs
exit 1
- name: Collect Docker stats
if: github.event_name == 'pull_request'
continue-on-error: true
id: docker-stats
run: |
# Get image size
IMAGE_SIZE=$(docker images appwrite/browser:local --format "{{.Size}}")
# Get container stats
CONTAINER_ID=$(docker compose ps -q appwrite-browser)
MEMORY_USAGE=$(docker stats $CONTAINER_ID --no-stream --format "{{.MemUsage}}" | cut -d'/' -f1 | xargs)
# Quick screenshot benchmark (3 runs, average)
TOTAL=0
for i in {1..3}; do
START=$(date +%s%3N)
curl -s -X POST http://localhost:3000/v1/screenshots \
-H "Content-Type: application/json" \
-d '{"url":"https://appwrite.io"}' \
-o /dev/null
END=$(date +%s%3N)
DURATION=$((END - START))
TOTAL=$((TOTAL + DURATION))
done
SCREENSHOT_AVG_MS=$((TOTAL / 3))
SCREENSHOT_AVG=$(echo "scale=2; $SCREENSHOT_AVG_MS / 1000" | bc)
# Store in GitHub output
echo "image_size=$IMAGE_SIZE" >> $GITHUB_OUTPUT
echo "memory_usage=$MEMORY_USAGE" >> $GITHUB_OUTPUT
echo "screenshot_time=$SCREENSHOT_AVG" >> $GITHUB_OUTPUT
- name: Comment PR with stats
if: github.event_name == 'pull_request' && steps.docker-stats.outcome == 'success'
continue-on-error: true
uses: marocchino/sticky-pull-request-comment@v2
with:
header: docker-image-stats
skip_unchanged: true
message: |
## Docker Image Stats
| Metric | Value |
|--------|-------|
| Image Size | ${{ steps.docker-stats.outputs.image_size }} |
| Memory Usage | ${{ steps.docker-stats.outputs.memory_usage }} |
| Cold Start Time | ${{ steps.container-startup.outputs.startup_time }}s |
| Screenshot Time | ${{ steps.docker-stats.outputs.screenshot_time }}s |
<sub>Screenshot benchmark: Average of 3 runs on https://appwrite.io</sub>
- name: Run e2e tests
run: bun test:e2e
- name: Print logs
if: failure()
run: docker compose logs