# Set Up GitHub Actions CI for a CodeIgniter 4 App

Yes. An agent replaces the starter's develop-only PHPUnit workflow with one for your branches, drops the auto-close workflow, wires an SQLite test database, in a PR.

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

## What the agent does

The agent reads what the starter already ships before writing a workflow, because an app made with `composer create-project codeigniter4/appstarter` inherits two. `.github/workflows/phpunit.yml` runs only on `pull_request` against a `develop` branch, with a matrix of PHP 8.2 and 8.5 on `ubuntu-24.04`, `shivammathur/setup-php` pinned by commit with the `intl, json, mbstring, mysqlnd, xdebug, xml, sqlite3` extensions and `xdebug` coverage, a Composer cache keyed on `composer.lock`, `composer install --no-progress --no-interaction` and `vendor/bin/phpunit --coverage-text`, and it skips when the pull request title contains `[ci skip]`. `.github/workflows/close-pull-request.yml` runs on `pull_request_target` and closes every pull request with `gh pr close` and a message saying the repository is a read-only split that does not accept pull requests. In the reader's own application that second workflow closes their teammates' pull requests, and the first one never runs on a repository whose branches are `main` and feature branches.

The rewrite keeps what is good and fixes the triggers. The agent renames `phpunit.yml` to `ci.yml`, sets `on` to `push` to the default branch and `pull_request` to any branch, keeps the pinned actions and the extension list, keeps the 8.2 and 8.5 matrix, since `composer.json` requires `^8.2` and `public/index.php` sets `$minPhpVersion = '8.2'`, and adds `composer validate --strict` and `php spark list` steps so a broken `composer.json` or a framework that cannot boot fails before the tests. `close-pull-request.yml` is deleted with a commit message that quotes its own text, so the history says why. `permissions` stays `contents: read`.

Tests that touch the database need a database in the runner. The starter's `tests/database/ExampleDatabaseTest.php` uses `DatabaseTestTrait` with `ExampleSeeder` and `ExampleMigration` from `tests/_support/Database/`, whose `$DBGroup` is `tests`, and `phpunit.dist.xml` leaves the `database.tests.*` variables commented out, so on a fresh checkout those tests fail for want of a connection. The agent uncomments them in a committed `phpunit.xml` that extends the dist file's intent with `database.tests.DBDriver` set to `SQLite3` and `database.tests.database` set to `:memory:`, which the `sqlite3` extension in the workflow supports and which needs no service container, and it leaves the MySQLi `tests` group in `app/Config/Database.php` alone for teams that want a real server. `tests/session/ExampleSessionTest.php` and `tests/unit/HealthTest.php`, which reads `app.baseURL` from `.env` when present, need nothing more than the `app.baseURL` the PHPUnit config already sets.

The agent checks its own work in its sandbox: `composer install`, `composer validate --strict`, `vendor/bin/phpunit --coverage-text` with the SQLite configuration, and each remaining step's command in the order the job runs them. It also adds `build/` to `.gitignore` if missing, because `phpunit.dist.xml` writes coverage, testdox and JUnit output under `build/logs/`, and attaches that JUnit file as a workflow artifact so failures are readable in the Actions summary. The README gets a Tests section with the one command CI runs.

## Start it with one API call

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

```json
{
  "agent": "claude",
  "input": "Set up GitHub Actions CI for this CodeIgniter 4 app. Read composer.json, public/index.php, phpunit.dist.xml, .github/workflows/phpunit.yml, .github/workflows/close-pull-request.yml, app/Config/Database.php, tests/README.md, tests/unit/HealthTest.php, tests/database/ExampleDatabaseTest.php, tests/session/ExampleSessionTest.php and tests/_support/Database/ first. Delete close-pull-request.yml with a commit message quoting the text it posts, because it would close every pull request on this app. Replace phpunit.yml with ci.yml that runs on push to the default branch and on every pull request, keeps the pinned setup-php action, the extension list and the Composer cache, tests on PHP 8.2 and the newest PHP the current matrix lists, runs composer validate --strict and php spark list before vendor/bin/phpunit --coverage-text, and uploads build/logs/logfile.xml as an artifact. Add a committed phpunit.xml that sets database.tests.DBDriver to SQLite3 and database.tests.database to :memory: so the database tests run without a server, leaving app/Config/Database.php unchanged. Add build/ to .gitignore if it is not there and a Tests section to the README. Run composer install, composer validate --strict and vendor/bin/phpunit --coverage-text in the sandbox, include the output, and open a pull request.",
  "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 that deletes `.github/workflows/close-pull-request.yml`, replaces `.github/workflows/phpunit.yml` with `.github/workflows/ci.yml`, adds `phpunit.xml` and changes `.gitignore` and `README.md`. The application code, `app/Config/Database.php` and `phpunit.dist.xml` are unchanged.

The description explains why each workflow was wrong for an application repository, lists the matrix and steps, and quotes the `composer validate` and `phpunit --coverage-text` output from the sandbox, including the database tests that previously had no connection. The transcript at `GET /o/{org}/sessions/{id}/messages` keeps every command and its output.

Before merging, a reviewer checks the default branch name in the trigger, decides whether to keep the `[ci skip]` title condition, and whether the `tests` group should stay SQLite or move to a MySQL service container that matches production.

## Run it on every new repository from the starter

A team that creates applications from the CodeIgniter starter runs this once per new repository from its own server: one `POST /o/{org}/sessions` per repository with that repository in `resources`, and a `request_id` that is a UUID v5 of the repository's full name so a retried call returns the run already started rather than a second pull request.

After that, an automation on the Project with a `github` trigger on `pull_request.opened` and `pull_request.synchronize` and the prompt "check that .github/workflows/ci.yml still installs every PHP extension and runs every test suite this pull request adds, and fix it on this branch if not" keeps the workflow current. The trigger puts the pull request after the prompt; only pushes by an owner, member or collaborator fire it.

## Why run it on Rush?

The starter's workflows are written for the framework's own distribution repository, and the failure they cause in an application is silent: the test job never triggers, and the close-pull-request job quietly shuts the first contribution. Reading both files and the PHPUnit configuration on a clean machine, then running the suite there with the SQLite test group, is how the agent finds that the database tests had no connection before the workflow ever runs.

The run keeps every command and its output, so the pull request shows the suite passing under the exact configuration the workflow will use, and a team with several CodeIgniter applications can fix all of them at once, each in its own sandbox with its own pull request.

## Frequently asked questions

### Why delete close-pull-request.yml rather than edit it?

Its only job is to close every pull request with a notice that the repository is a read-only split of `codeigniter4/CodeIgniter4`. That is true of the starter's distribution repository and false of your application, so there is nothing in it to keep.

### Why SQLite for the tests group and not MySQL?

The workflow already installs the `sqlite3` extension, `:memory:` needs no service container, and the starter's example migration and seeder run on it. If production is MySQL and you want the tests to match, say so and the agent adds a `mysql` service and sets the `database.tests.*` variables to it instead.

### Will my local phpunit.dist.xml stop working?

No. PHPUnit prefers a committed `phpunit.xml` over `phpunit.dist.xml`, and the new file carries the same test suite, coverage and logging settings plus the uncommented database variables, so `composer test` behaves the same locally and in CI.

### What does php spark list add?

It boots the framework through the `spark` entry point before the tests, so a broken `app/Config/` file fails the job with a clear message rather than a wall of PHPUnit errors.

### Does this run on pushes to feature branches too?

Only pull requests and pushes to the default branch, which is what most teams want to avoid double runs. Add other branches to the `push` list in `ci.yml` if your flow needs them.

## More CodeIgniter jobs

- [Add a Health Check Endpoint to a CodeIgniter 4 App](https://getrush.ai/run/add-health-checks/codeigniter/)
- [Add i18n to a CodeIgniter 4 App](https://getrush.ai/run/add-i18n/codeigniter/)
- [Add JWT Authentication to a CodeIgniter 4 API](https://getrush.ai/run/add-jwt-authentication/codeigniter/)

## The same job on other stacks

- [Set Up GitHub Actions CI for a Dagster Project](https://getrush.ai/run/add-github-actions-ci/dagster/)
- [Add a GitHub Actions CI Job That Runs dbt build on Every Pull Request](https://getrush.ai/run/add-github-actions-ci/dbt/)
- [Set Up GitHub Actions CI for an Eleventy Site](https://getrush.ai/run/add-github-actions-ci/eleventy/)

## 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/)
