|
| 1 | +# .github/workflows/main.yml |
| 2 | +name: Main |
| 3 | + |
| 4 | +on: |
| 5 | + push: |
| 6 | + pull_request: |
| 7 | + |
| 8 | +jobs: |
| 9 | + tests: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + timeout-minutes: 45 |
| 12 | + env: |
| 13 | + OLLAMA_HOST: http://localhost:11434 |
| 14 | + OLLAMA_MODEL: mistral |
| 15 | + REDIS_HOST: redis |
| 16 | + POSTGRES_HOST: postgres |
| 17 | + POSTGRES_DB: dendrite |
| 18 | + POSTGRES_USER: dendrite |
| 19 | + POSTGRES_PASSWORD: dendrite_pass |
| 20 | + |
| 21 | + steps: |
| 22 | + - name: Checkout |
| 23 | + uses: actions/checkout@v4 |
| 24 | + |
| 25 | + # Optional: speed up your tests image pip installs (host cache). |
| 26 | + - name: Cache pip |
| 27 | + uses: actions/cache@v4 |
| 28 | + with: |
| 29 | + path: ~/.cache/pip |
| 30 | + key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements*.txt') }} |
| 31 | + restore-keys: | |
| 32 | + ${{ runner.os }}-pip- |
| 33 | +
|
| 34 | + - name: Start services (Compose) |
| 35 | + run: | |
| 36 | + docker compose up -d redis postgres ollama |
| 37 | + echo "Waiting for Redis..." |
| 38 | + for i in {1..30}; do |
| 39 | + if docker compose exec -T redis redis-cli ping | grep -q PONG; then |
| 40 | + echo "Redis ready"; break |
| 41 | + fi |
| 42 | + if [ $i -eq 30 ]; then echo "Redis failed to start"; exit 1; fi |
| 43 | + sleep 1 |
| 44 | + done |
| 45 | +
|
| 46 | + echo "Waiting for Postgres..." |
| 47 | + for i in {1..60}; do |
| 48 | + if docker compose exec -T postgres pg_isready -U "$POSTGRES_USER" >/dev/null 2>&1; then |
| 49 | + echo "Postgres ready"; break |
| 50 | + fi |
| 51 | + if [ $i -eq 60 ]; then echo "Postgres failed to start"; exit 1; fi |
| 52 | + sleep 1 |
| 53 | + done |
| 54 | +
|
| 55 | + echo "Waiting for Ollama API..." |
| 56 | + for i in {1..120}; do |
| 57 | + if curl -sSf http://localhost:11434/api/tags >/dev/null; then |
| 58 | + echo "Ollama up"; break |
| 59 | + fi |
| 60 | + if [ $i -eq 120 ]; then |
| 61 | + echo "Ollama failed to start"; docker compose logs ollama; exit 1 |
| 62 | + fi |
| 63 | + sleep 1 |
| 64 | + done |
| 65 | +
|
| 66 | + - name: Pull a tiny model for CI |
| 67 | + run: | |
| 68 | + set -e |
| 69 | + curl -sS -X POST "$OLLAMA_HOST/api/pull" -d "{\"name\":\"$OLLAMA_MODEL\"}" |
| 70 | + # wait until it appears in /api/tags |
| 71 | + for i in {1..600}; do |
| 72 | + curl -s "$OLLAMA_HOST/api/tags" | grep -q "$OLLAMA_MODEL" && break || sleep 1 |
| 73 | + done |
| 74 | +
|
| 75 | + - name: Build tests image |
| 76 | + run: docker compose build tests |
| 77 | + |
| 78 | + - name: Run pytest in tests service |
| 79 | + run: docker compose run --rm tests pytest -v |
| 80 | + |
| 81 | + - name: Teardown |
| 82 | + if: always() |
| 83 | + run: docker compose down -v |
0 commit comments