# Set Up GitHub Actions CI for a Vapor App

Yes. An agent reads your Vapor app's Package.swift, Dockerfile and tests, adds a workflow that builds and tests it against Postgres on every PR, and opens one.

[Run this on Rush](https://cloud.getrush.ai/run/add-github-actions-ci/vapor/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The agent reads what has to run before it writes a workflow. In a project generated from vapor/template with Fluent and Postgres, `Package.swift` is `swift-tools-version:6.3`, depends on `vapor` from 4.121.4, `fluent` from 4.13.0, `fluent-postgres-driver` from 2.12.0 and `swift-nio` from 2.101.0, and turns on upcoming features such as `ExistentialAny` and `MemberImportVisibility` for both the app target and the test target. `Tests/AppTests/AppTests.swift` uses Swift Testing with `VaporTesting`: a `withApp` helper calls `configure`, `autoMigrate`, the test body and `autoRevert`, and the four cases hit `GET /hello`, `GET /todos`, `POST /todos` and `DELETE /todos/:id`. Three of them need a database.

`Sources/App/configure.swift` says which one: it reads `DATABASE_HOST`, `DATABASE_PORT`, `DATABASE_USERNAME`, `DATABASE_PASSWORD` and `DATABASE_NAME` with defaults of `localhost`, the IANA port, `vapor_username`, `vapor_password` and `vapor_database`, with TLS set to `.prefer`. `docker-compose.yml` runs the same credentials against `postgres:18-alpine`, and `Dockerfile` builds in `swift:6.3-noble` with `swift package resolve` and then `swift build -c release --static-swift-stdlib`. A generated app has no `.github/` at all: the template's `manifest.yml` lists every file `vapor new` writes, and no workflow is among them. The template repository's own `test-template.yml` is the closest pattern, running `swift test` inside a `swift:6.3-noble` container against a `psql` service with `DATABASE_HOST` pointing at it.

The agent writes `.github/workflows/ci.yml` on `pull_request` and `push` to `main`, with one job that runs in the `swift:6.3-noble` container the Dockerfile already uses and a `postgres:18-alpine` service with the compose file's user, password and database. It caches `.build` keyed on the hash of `Package.swift`, installs `zstd` first because the cache action needs it inside that container, runs `swift build`, then `swift test` with `DATABASE_HOST` set to the service name, and sets `timeout-minutes` so a hung test does not hold a runner. The SQLite and MySQL variants of the template get the matching service or none, read from `configure.swift` rather than assumed.

Before pushing, the agent runs the same two commands in the sandbox with a Postgres it starts on the compose file's credentials, and pastes `swift test`'s summary. It does not add a `docker compose build` job by default, because the release build with a static standard library is slow and the Dockerfile is already checked by whoever deploys it; the pull request says so and shows the two lines that would add it.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "Add a GitHub Actions workflow to this Vapor app and open a pull request. Read Package.swift, Sources/App/configure.swift, Sources/App/entrypoint.swift, Tests/AppTests/AppTests.swift, Dockerfile and docker-compose.yml first. Write .github/workflows/ci.yml that runs on pull_request and on push to main, in a container of the same swift image the Dockerfile builds with, with a Postgres service that uses the user, password and database from docker-compose.yml. Cache .build keyed on Package.swift, install zstd before the cache step, run swift build and then swift test with DATABASE_HOST set to the service name, and set timeout-minutes on the job. If the app uses SQLite or MySQL instead, use the matching service or none, based on what configure.swift reads. Run swift build and swift test in the sandbox against a Postgres you start with the same credentials and paste the test summary in the pull request. Do not change Package.swift, the Dockerfile or any Swift source.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

What comes back is a pull request with one new file, `.github/workflows/ci.yml`, and a description that quotes the `swift test` summary from the sandbox: the suite name from `AppTests.swift` and each `@Test` by its label. Nothing under `Sources/` or `Tests/` changes, and `Package.swift` is untouched.

The workflow runs on the pull request that adds it, so the first check is the workflow checking itself: the job pulls the container, restores or seeds the `.build` cache, waits for Postgres, builds and tests. A green check on that pull request is the proof that the service wiring and `DATABASE_HOST` are right.

A reviewer compares the service block against `configure.swift`, confirms the image tag matches the Dockerfile so CI and the deployed binary use the same toolchain, and checks that the cache key changes when `Package.swift` does. Then they merge and make the check required on `main`.

## Run it on every new Vapor repository

A team that starts each service from `vapor new` sends one `POST /o/{org}/sessions` per new repository with this prompt and the repository in `resources`. Each run reads its own `configure.swift`, so a SQLite service gets no database container and a MySQL one gets `mysql` with the compose credentials, and each opens its own pull request.

Send a `request_id` with each call so a retried request returns the run it already started instead of a second one. Give the key a `webhook_url` and Rush POSTs `run.completed` when the turn ends, with `session_url` to read the pull request from.

## Why run it on Rush?

The slow part of a Swift workflow is finding out whether it works: a wrong image tag, a missing `zstd`, or a database the tests cannot reach shows up only after a full build on a runner. In a Rush sandbox the agent builds and tests against a real Postgres first, and the commands and their output stay in the run's record, so the pull request arrives with the evidence already attached.

The change is one file, but reading `configure.swift`, the Dockerfile and the test helper to get it right is the work. The agent does that in one pass, and the same request works unchanged on the next service generated from the template.

## Frequently asked questions

### Why run the job in a container instead of installing Swift on the runner?

Because the Dockerfile already pins `swift:6.3-noble`, and the template's own workflow tests inside the same image. Using it keeps CI on the toolchain the deployed binary is built with, and avoids a separate install step that can drift.

### Does it work for the SQLite variant of the template?

Yes. `configure.swift` then calls `DatabaseConfigurationFactory.sqlite(.file("db.sqlite"))` and reads no `DATABASE_*` variables, so the agent writes the job with no service and no `DATABASE_HOST`.

### Will it cache the build?

It caches `.build` keyed on the hash of `Package.swift`, which is what changes when a dependency does. A generated app has no `Package.resolved` committed, so the key cannot use it; the pull request notes that committing one would make the key stricter.

### What about the Docker image build?

Left out by default. The release build with `--static-swift-stdlib` is the slowest step in the repository, and the Dockerfile is exercised wherever the app is deployed. The pull request shows the job to add if the team wants it checked on every pull request too.

## More Vapor jobs

- [Add Health Checks to a Vapor App](https://getrush.ai/run/add-health-checks/vapor/)
- [Add Request Validation to a Vapor API](https://getrush.ai/run/add-input-validation/vapor/)
- [Add JWT Authentication to a Vapor App from a Linear Issue](https://getrush.ai/run/add-jwt-auth/vapor/)

## The same job on other stacks

- [Set Up GitHub Actions CI for a VS Code Extension](https://getrush.ai/run/add-github-actions-ci/vscode-extension/)
- [Set Up GitHub Actions CI for an AdonisJS App](https://getrush.ai/run/add-github-actions-ci/adonisjs/)
- [Add GitHub Actions CI to an Airflow Project](https://getrush.ai/run/add-github-actions-ci/airflow/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
