|
| 1 | +name: CI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + pull_request: |
| 7 | + branches: [main] |
| 8 | + |
| 9 | +concurrency: |
| 10 | + group: ci-${{ github.ref }} |
| 11 | + cancel-in-progress: true |
| 12 | + |
| 13 | +jobs: |
| 14 | + quality: |
| 15 | + runs-on: ubuntu-latest |
| 16 | + services: |
| 17 | + postgres: |
| 18 | + image: postgres:16-alpine |
| 19 | + env: |
| 20 | + POSTGRES_USER: uplotr |
| 21 | + POSTGRES_PASSWORD: uplotr_test |
| 22 | + POSTGRES_DB: uplotr_test |
| 23 | + ports: ['5432:5432'] |
| 24 | + options: >- |
| 25 | + --health-cmd "pg_isready -U uplotr -d uplotr_test" |
| 26 | + --health-interval 5s --health-timeout 5s --health-retries 10 |
| 27 | + env: |
| 28 | + DATABASE_URL: postgresql://uplotr:uplotr_test@localhost:5432/uplotr_test?schema=public |
| 29 | + INTEGRATION_DATABASE_URL: postgresql://uplotr:uplotr_test@localhost:5432/uplotr_test?schema=public |
| 30 | + AUTH_SECRET: ci-only-session-secret-with-at-least-32-characters |
| 31 | + AUTH_MODE: REQUIRED |
| 32 | + CRON_SECRET: ci-only-cron-secret-with-at-least-32-characters |
| 33 | + steps: |
| 34 | + - uses: actions/checkout@v7 |
| 35 | + - uses: pnpm/action-setup@v6 |
| 36 | + - uses: actions/setup-node@v7 |
| 37 | + with: |
| 38 | + node-version: 22 |
| 39 | + cache: pnpm |
| 40 | + - run: pnpm install --frozen-lockfile |
| 41 | + - run: pnpm exec prisma migrate deploy |
| 42 | + - run: pnpm lint |
| 43 | + - run: pnpm typecheck |
| 44 | + - run: pnpm test |
| 45 | + - run: pnpm test:integration |
| 46 | + - run: pnpm audit --audit-level=high |
| 47 | + - run: pnpm build |
| 48 | + - run: pnpm exec playwright install --with-deps chromium |
| 49 | + - run: pnpm test:e2e --project=desktop-chromium |
| 50 | + |
| 51 | + docker: |
| 52 | + runs-on: ubuntu-latest |
| 53 | + needs: quality |
| 54 | + env: |
| 55 | + AUTH_SECRET: ci-only-session-secret-with-at-least-32-characters |
| 56 | + AUTH_MODE: REQUIRED |
| 57 | + CRON_SECRET: ci-only-cron-secret-with-at-least-32-characters |
| 58 | + DB_PASSWORD: uplotr_compose_test |
| 59 | + steps: |
| 60 | + - uses: actions/checkout@v7 |
| 61 | + - uses: docker/setup-buildx-action@v4 |
| 62 | + - uses: docker/build-push-action@v7 |
| 63 | + with: |
| 64 | + context: . |
| 65 | + push: false |
| 66 | + load: true |
| 67 | + tags: ghcr.io/iblh/uplotr:latest |
| 68 | + cache-from: type=gha |
| 69 | + cache-to: type=gha,mode=max |
| 70 | + - name: Smoke test Docker Compose from an empty database |
| 71 | + run: | |
| 72 | + docker compose up -d --wait --wait-timeout 120 |
| 73 | +
|
| 74 | + cookie_jar="${RUNNER_TEMP}/uplotr-ci-cookies.txt" |
| 75 | + curl --fail --silent --show-error \ |
| 76 | + --cookie-jar "${cookie_jar}" \ |
| 77 | + --header 'Content-Type: application/json' \ |
| 78 | + --data '{"username":"compose-admin","password":"correct-horse-battery-staple","mapProvider":"OPENFREEMAP"}' \ |
| 79 | + http://127.0.0.1:3000/api/auth/setup >/dev/null |
| 80 | +
|
| 81 | + api_key="$(curl --fail --silent --show-error \ |
| 82 | + --cookie "${cookie_jar}" \ |
| 83 | + --header 'Content-Type: application/json' \ |
| 84 | + --data '{"name":"Compose smoke test"}' \ |
| 85 | + http://127.0.0.1:3000/api/keys | jq -er '.key')" |
| 86 | +
|
| 87 | + curl --fail --silent --show-error \ |
| 88 | + --header "Authorization: Bearer ${api_key}" \ |
| 89 | + --header 'Content-Type: application/json' \ |
| 90 | + --data '{"device_id":"compose-smoke-device","lat":37.7749,"lon":-122.4194,"battery":88}' \ |
| 91 | + http://127.0.0.1:3000/api/v1/ingest >/dev/null |
| 92 | +
|
| 93 | + curl --fail --silent --show-error \ |
| 94 | + --cookie "${cookie_jar}" \ |
| 95 | + http://127.0.0.1:3000/api/devices | \ |
| 96 | + jq -e 'any(.[]; .externalId == "compose-smoke-device")' >/dev/null |
| 97 | + - name: Show Compose logs on failure |
| 98 | + if: failure() |
| 99 | + run: docker compose logs --no-color |
| 100 | + - name: Stop Docker Compose |
| 101 | + if: always() |
| 102 | + run: docker compose down --volumes |
0 commit comments