Preview environments
Every pull request gets a live copy of your app with logins ready, linked from the pull request and kept current as you push.
Cofactor builds a sandbox (a live copy of your app, also called a test environment) with each pull request's change and links it from the pull request's Deployments. Reviewers click through the change on a running app, and tests can run against it.
Previews need an app connected through GitHub. An app delivered as a pushed image doesn't get one.
Get a preview on a pull request
-
Connect your repository. Follow Build from GitHub until
cofactor sandbox connectsucceeds. -
Open a pull request. Every pull request whose head has your
cofactor.sandbox.yamlgets a preview of thedefaultenvironment. Cofactor updates it on each push and destroys it when the pull request closes. -
Open the preview. Cofactor adds a deployment to the pull request, in an environment named
Cofactor preview <repo>#<number>. While the preview builds, the deployment has no links. When it is ready, its status link opens the web URL and its log link opens the preview's Cofactor page. A failed build links only the Cofactor page. -
Get the logins. GitHub never gets the logins. Signed-in members of your organization read them on the preview's Cofactor page or from the CLI.
bashcofactor sandbox preview --application "Project Tracker" --pr 123
-
Run a test against it. This needs the Scale plan. The test runs on a private copy of the preview, never on the preview itself.
bashcofactor workflow run <workflow id> --preview 123 --application "Project Tracker"
A passing result can go on the pull request as proof. See Release gates.
Check it worked
cofactor sandbox preview --application "Project Tracker" --pr 123
The status reads ready and the commit matches the pull request's latest commit. Each URL serves your app and each login signs in. Push another commit and run the command again. The commit changes. The URLs normally stay the same.
Go deeper
Limit previews to some files, lifetimes and common errors.
Limit previews to some files. Add previews.paths to cofactor.sandbox.yaml. It is a list of git glob pathspecs relative to the definition directory, matched against the pull request's changed files. Prefix a path with :(exclude) to skip it. Only GitHub definitions can set it.
previews:
paths:
- web/**
- ":(exclude)web/docs/**"
Lifetime. A preview expires 24 hours after the last push to the pull request, and never lives past two weeks. It is destroyed when the pull request closes.
Plan. Previews are on every plan. Running tests on a pull request needs Scale.
Errors. No deployment on the pull request, but a preview in the CLI, means the Cofactor GitHub App lacks the Deployments read and write permission. Approve it in the app's installation settings on GitHub. No preview means the head has no cofactor.sandbox.yaml, no changed file matches previews.paths, the app isn't connected to GitHub, the pull request comes from a fork, or the Preview environments setting on the Test environments page is off for your organization (contact us). A failed preview means a build step, prepare or a seed failed. Fix it and push again.