# Move a Mongoose API from Travis CI to GitHub Actions

Yes. An agent replaces a Mongoose API's .travis.yml with a GitHub Actions workflow running the same lint and Jest commands against MongoDB, and opens a PR.

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

## What the agent does

The agent reads the Travis file first, because the job is to keep what it does and move where it runs. In a Mongoose API like hagopj13/node-express-boilerplate, `.travis.yml` runs on Node 12 with the `mongodb` service, caches Yarn, builds only `master`, exports `PORT`, `MONGODB_URL=mongodb://localhost:27017/node-boilerplate`, `JWT_SECRET`, `JWT_ACCESS_EXPIRATION_MINUTES` and `JWT_REFRESH_EXPIRATION_DAYS`, runs `yarn lint` then `yarn test`, and sends coverage to Coveralls from `after_success` with `yarn coverage:coveralls`. `package.json` defines those scripts: `lint` is `eslint .`, `test` is `jest -i --colors --verbose --detectOpenHandles`, `coverage:coveralls` pipes `jest -i --coverage --coverageReporters=text-lcov` into the `coveralls` package, and `engines` asks for Node 12 or newer. `yarn.lock` is a v1 lockfile and `prepare` runs `husky install`.

Then it reads what the tests need, because that decides the service container. `src/config/config.js` validates `MONGODB_URL` with Joi and appends `-test` to it when `NODE_ENV` is `test`, which `jest.config.js` sets, and `tests/utils/setupTestDB.js` connects with Mongoose, empties every collection before each test and disconnects after all. The three integration suites under `tests/integration` and the four unit suites under `tests/unit` therefore need a reachable MongoDB and nothing else. `docker-compose.yml` already pins `mongo:4.2.1-bionic` for local development and `docker-compose.test.yml` runs `yarn test` against it, so the agent uses the same image tag in CI rather than introducing a second version.

The workflow it writes, `.github/workflows/ci.yml`, triggers on `push` to `master` and on `pull_request`, which is wider than Travis's `branches: only: master` and is said so in the pull request. One job runs on `ubuntu-latest` with a `services` block starting `mongo:4.2.1-bionic` and publishing `27017`, so the Travis `MONGODB_URL` works unchanged. `actions/setup-node` installs Node with `cache: yarn`, which replaces Travis's `cache: yarn`, and a matrix keeps 12 from the Travis file and adds a current LTS so the pull request shows whether the suite still passes on a supported release. `yarn install --frozen-lockfile` with `HUSKY=0` skips the Git hook install, then `yarn lint` and `yarn test` run with the same five environment variables. Coverage moves from `after_success` to a step that runs `yarn coverage` and uploads `coverage/lcov.info` with the Coveralls GitHub Action using the repository's `GITHUB_TOKEN`, since the `coveralls` package's Travis-only token flow does not apply.

Finally it removes `.travis.yml` and the traces of it: the Travis badge at the top of `README.md` becomes the workflow's badge, the `CI: continuous integration with Travis CI` line in the Features list is reworded, and `travis` leaves the `keywords` array in `package.json`. The agent runs `yarn install --frozen-lockfile`, `yarn lint` and, with a MongoDB it starts in the sandbox, `yarn test`, so it has seen the same commands pass before the workflow runs them, and it checks the workflow file with `actionlint`.

## Start it with one API call

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

```json
{
  "agent": "claude",
  "input": "Move this project's CI from Travis to GitHub Actions. Read .travis.yml, package.json, yarn.lock, jest.config.js, src/config/config.js, tests/utils/setupTestDB.js, docker-compose.yml, docker-compose.test.yml, .eslintrc.json and README.md first. Write .github/workflows/ci.yml that runs on push to master and on pull_request, starts the same mongo image tag docker-compose.yml uses as a service container on 27017, installs Node with actions/setup-node and Yarn caching on a matrix of the Travis Node version and a current LTS, runs yarn install --frozen-lockfile with HUSKY=0, exports the five environment variables from .travis.yml, runs yarn lint and yarn test, and uploads coverage to Coveralls with the Coveralls GitHub Action instead of the coveralls package. Delete .travis.yml, swap the README badge for the workflow badge, reword the Travis line in the README features list and drop travis from package.json keywords. Start a MongoDB in the sandbox and run yarn lint and yarn test yourself, run actionlint on the workflow, and open a pull request that maps each Travis setting to its replacement and says what changed in trigger scope.",
  "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 adds `.github/workflows/ci.yml`, deletes `.travis.yml` and touches `README.md` and `package.json`. The description is a table from each Travis key to its replacement: `services: mongodb` to the `services` block, `cache: yarn` to `setup-node`'s cache, the `env` block to the job's `env`, `script` to two steps, and `after_success` to the Coveralls action. It says plainly that pull requests from any branch now run CI, where Travis only built `master`.

The run's record keeps the `yarn lint` and `yarn test` output from the sandbox, with the integration suites talking to the MongoDB the agent started there, and the `actionlint` result, so a reviewer knows the commands pass before the first workflow run.

Before merging, a reviewer confirms the Coveralls repository is enabled for GitHub Actions, decides whether to keep Node 12 in the matrix now that it is out of support, and checks the required status check on `master` is switched from the Travis check to the new workflow's job name, which the agent names in the description.

## Run it on every repository still carrying a .travis.yml

A team moving many repositories off Travis starts one run per repository from its own server: one `POST /o/{org}/sessions` each, 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 instead of opening a second pull request. Each run reads its own `.travis.yml`, starts its own database in its own sandbox, and the pull requests arrive independently.

The same prompt works unchanged across them because it names no Node version or image tag; each run takes those from the repository it is in. A key's `webhook_url` reports when each run finishes, with the pull request in the payload.

## Why run it on Rush?

A CI migration is judged by one thing, whether the new workflow passes on the first try, and that depends on details like the test database's name and the lockfile flag that only show up when the commands run. The agent runs them in its own sandbox, with a MongoDB it starts for the purpose, before writing the workflow that runs them again.

Every command the agent ran stays with the run, so the pull request can cite the passing suite and the lint output. Migrating a dozen repositories this way at once costs no more attention than one, because each run has its own machine and its own record.

## Frequently asked questions

### Will the Jest suite find MongoDB in GitHub Actions?

Yes. A `services` container publishes `27017` on the runner's `localhost`, which is the host in the Travis `MONGODB_URL`. `src/config/config.js` appends `-test` to the database name under `NODE_ENV=test`, so the suite gets its own database inside that container, as it does on a developer's machine.

### Why not keep sending coverage with the coveralls package?

On Travis the `coveralls` package found its token from the Travis environment. On GitHub Actions it needs a repository token the workflow would have to store as a secret. The Coveralls GitHub Action uses `GITHUB_TOKEN` instead and reads the `lcov.info` that `yarn coverage` writes, so no new secret is needed.

### Why set HUSKY=0 during install?

`package.json` runs `husky install` from the `prepare` script on every `yarn install`. It succeeds on a runner but installs Git hooks nobody will trigger. Husky 7 reads `HUSKY=0` to skip it, which keeps the install step to what CI needs.

### Does the trigger change anything about who runs CI?

Travis built only `master`. The new workflow also runs on every pull request, including ones from forks, where `GITHUB_TOKEN` is read-only and the Coveralls upload may fail; the agent marks that step `continue-on-error` so a fork's pull request still shows lint and test results.

## More Mongoose jobs

- [Upgrade Mongoose 5 to the Current Major in an Express API](https://getrush.ai/run/upgrade-mongoose/mongoose/)
- [Add Account Lockout to a Mongoose and Express App](https://getrush.ai/run/add-account-lockout/mongoose/)
- [Add an Audit Log to a Mongoose and Express API](https://getrush.ai/run/add-audit-log/mongoose/)

## The same job on other stacks

- [Migrate a Python Project from Travis CI to GitHub Actions](https://getrush.ai/run/migrate-travis-to-github-actions/travis-ci/)
- [Move a Koa Project from Travis CI to GitHub Actions](https://getrush.ai/run/migrate-travis-to-github-actions/koa/)

## More jobs like this: Hand off a long task

- [Replace ts-node With tsx in an Express and TypeDI API](https://getrush.ai/run/migrate-ts-node-to-tsx/ts-node/)

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