| 1 | # Type-checks and tests the API and the delivery service on every pull request, stacked ones included, and on every push to main. |
| 2 | name: CI |
| 3 | |
| 4 | on: |
| 5 | pull_request: |
| 6 | push: |
| 7 | branches: [main] |
| 8 | |
| 9 | concurrency: |
| 10 | group: api-${{ github.ref }} |
| 11 | cancel-in-progress: true |
| 12 | |
| 13 | jobs: |
| 14 | test: |
| 15 | runs-on: ubuntu-latest |
| 16 | timeout-minutes: 30 |
| 17 | services: |
| 18 | postgres: |
| 19 | image: postgres:16-alpine |
| 20 | env: |
| 21 | POSTGRES_PASSWORD: test |
| 22 | ports: ['5432:5432'] |
| 23 | options: >- |
| 24 | --health-cmd "pg_isready -U postgres" |
| 25 | --health-interval 5s |
| 26 | --health-timeout 5s |
| 27 | --health-retries 10 |
| 28 | rustfs: |
| 29 | image: rustfs/rustfs:latest |
| 30 | env: |
| 31 | RUSTFS_ACCESS_KEY: ghost |
| 32 | RUSTFS_SECRET_KEY: ghostsecret |
| 33 | RUSTFS_VOLUMES: /data |
| 34 | RUSTFS_ADDRESS: 0.0.0.0:9000 |
| 35 | ports: ['9000:9000'] |
| 36 | env: |
| 37 | TEST_DATABASE_URL: postgres://postgres:test@localhost:5432/postgres |
| 38 | TEST_S3_ENDPOINT: http://localhost:9000 |
| 39 | GH_E2E_HOST: ghost.test |
| 40 | steps: |
| 41 | - uses: actions/checkout@v4 |
| 42 | |
| 43 | - uses: oven-sh/setup-bun@v2 |
| 44 | with: |
| 45 | bun-version: 1.3.14 |
| 46 | |
| 47 | - run: bun install --frozen-lockfile |
| 48 | |
| 49 | # gh refuses a port in GH_HOST, so the gh suite serves HTTPS on 443 for a name only this runner resolves. |
| 50 | - name: Serve ghost.test on 443 without root |
| 51 | run: | |
| 52 | echo "127.0.0.1 ghost.test" | sudo tee -a /etc/hosts |
| 53 | sudo sysctl -w net.ipv4.ip_unprivileged_port_start=443 |
| 54 | |
| 55 | - run: gh --version |
| 56 | |
| 57 | # Builds the workspace packages the API imports from dist, then type-checks it. |
| 58 | - run: bunx turbo run check-types --filter=@ghost/api |
| 59 | |
| 60 | # Integration specs among them migrate the same database, and racing migrators collide on the journal table. |
| 61 | - name: Unit tests |
| 62 | working-directory: apps/api |
| 63 | run: bunx vitest run --no-file-parallelism |
| 64 | |
| 65 | - name: End-to-end tests |
| 66 | working-directory: apps/api |
| 67 | run: bunx vitest run --config ./vitest.config.e2e.ts --no-file-parallelism |
| 68 | env: |
| 69 | GH_CAPTURE_DIR: ${{ runner.temp }}/gh-capture |
| 70 | |
| 71 | # What real gh sent, to refresh apps/api/test/fixtures/gh-capture with `gh run download -n gh-capture`. |
| 72 | - uses: actions/upload-artifact@v4 |
| 73 | if: always() |
| 74 | with: |
| 75 | name: gh-capture |
| 76 | path: ${{ runner.temp }}/gh-capture |
| 77 | if-no-files-found: ignore |
| 78 | |
| 79 | - name: Committed GraphQL schema is current |
| 80 | run: git diff --exit-code -- apps/api/github.schema.gql |
| 81 | |
| 82 | delivery: |
| 83 | runs-on: ubuntu-latest |
| 84 | timeout-minutes: 15 |
| 85 | services: |
| 86 | postgres: |
| 87 | image: postgres:16-alpine |
| 88 | env: |
| 89 | POSTGRES_PASSWORD: test |
| 90 | ports: ['5432:5432'] |
| 91 | options: >- |
| 92 | --health-cmd "pg_isready -U postgres" |
| 93 | --health-interval 5s |
| 94 | --health-timeout 5s |
| 95 | --health-retries 10 |
| 96 | env: |
| 97 | DATABASE_URL: postgres://postgres:test@localhost:5432/postgres |
| 98 | TEST_DATABASE_URL: postgres://postgres:test@localhost:5432/postgres |
| 99 | steps: |
| 100 | - uses: actions/checkout@v4 |
| 101 | |
| 102 | - uses: oven-sh/setup-bun@v2 |
| 103 | with: |
| 104 | bun-version: 1.3.14 |
| 105 | |
| 106 | - uses: actions/setup-go@v5 |
| 107 | with: |
| 108 | go-version-file: apps/delivery/go.mod |
| 109 | cache-dependency-path: apps/delivery/go.sum |
| 110 | |
| 111 | - run: bun install --frozen-lockfile |
| 112 | |
| 113 | # The queue tests read and write delivery_job, which the API's migrations create. |
| 114 | - name: Migrate the database |
| 115 | run: | |
| 116 | bunx turbo run build --filter=@ghost/db |
| 117 | bun packages/db/dist/migrate.js |
| 118 | |
| 119 | - name: go vet |
| 120 | working-directory: apps/delivery |
| 121 | run: go vet ./... |
| 122 | |
| 123 | - name: go test |
| 124 | working-directory: apps/delivery |
| 125 | run: go test ./... |