|
| 1 | +name: Build |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] # Run on every commit to main |
| 6 | + schedule: |
| 7 | + - cron: "0 8 * * *" # Every day at 08:00 UTC |
| 8 | + workflow_dispatch: # Allow manual triggering from GitHub UI |
| 9 | + |
| 10 | +jobs: |
| 11 | + daily-test: |
| 12 | + runs-on: ubuntu-latest |
| 13 | + |
| 14 | + strategy: |
| 15 | + fail-fast: false |
| 16 | + matrix: |
| 17 | + python-version: ["3.10", "3.11", "3.12", "3.13"] |
| 18 | + |
| 19 | + steps: |
| 20 | + - name: Checkout |
| 21 | + uses: actions/checkout@v4 |
| 22 | + |
| 23 | + - name: Set up Python ${{ matrix.python-version }} |
| 24 | + uses: actions/setup-python@v5 |
| 25 | + with: |
| 26 | + python-version: ${{ matrix.python-version }} |
| 27 | + |
| 28 | + - name: Install dependencies |
| 29 | + run: | |
| 30 | + python -m pip install --upgrade pip |
| 31 | + pip install -e ".[dev]" |
| 32 | +
|
| 33 | + - name: Run tests |
| 34 | + run: | |
| 35 | + pytest |
| 36 | +
|
| 37 | + docker-compose: |
| 38 | + runs-on: ubuntu-latest |
| 39 | + timeout-minutes: 20 |
| 40 | + env: |
| 41 | + COMPOSE_PROJECT_NAME: ci |
| 42 | + |
| 43 | + steps: |
| 44 | + - name: Checkout |
| 45 | + uses: actions/checkout@v4 |
| 46 | + |
| 47 | + - name: Seed demo config for container build |
| 48 | + run: | |
| 49 | + cp demo/settings/system.json deploy/docker/config/system.json |
| 50 | + cp demo/settings/system.json deploy/docker/config/system.json.template |
| 51 | +
|
| 52 | + - name: Set up Docker Buildx |
| 53 | + uses: docker/setup-buildx-action@v3 |
| 54 | + |
| 55 | + - name: Build Docker image |
| 56 | + run: | |
| 57 | + docker compose build --progress plain |
| 58 | +
|
| 59 | + - name: Start stack |
| 60 | + run: | |
| 61 | + docker compose up -d |
| 62 | +
|
| 63 | + - name: Wait for API health |
| 64 | + run: | |
| 65 | + container_id="$(docker compose ps -q pypnm-api)" |
| 66 | + if [ -z "$container_id" ]; then |
| 67 | + echo "API container was not created" |
| 68 | + docker compose ps |
| 69 | + exit 1 |
| 70 | + fi |
| 71 | +
|
| 72 | + for attempt in $(seq 1 30); do |
| 73 | + status="$(docker inspect --format '{{if .State.Health}}{{.State.Health.Status}}{{else}}{{.State.Status}}{{end}}' "$container_id")" |
| 74 | + if [ "$status" = "healthy" ]; then |
| 75 | + exit 0 |
| 76 | + fi |
| 77 | + echo "Container not healthy yet (status: $status); waiting..." |
| 78 | + sleep 5 |
| 79 | + done |
| 80 | +
|
| 81 | + echo "Container failed to become healthy" |
| 82 | + docker compose logs |
| 83 | + exit 1 |
| 84 | +
|
| 85 | + - name: Tear down |
| 86 | + if: always() |
| 87 | + run: | |
| 88 | + docker compose down --volumes |
0 commit comments