To preview every pull request of a SaaS on Light Cloud, push a branch and open a pull request. Light Cloud builds the branch into its own environment, comments the live link on the pull request, reports a GitHub check, and removes the environment when the branch is deleted. The work for a SaaS is making sure previews start with safe variables: a test database, a separate AUTH_SECRET, and no live Stripe keys.
In my run the preview environment and the pull request comment were both there 2 seconds after I opened the pull request, and the preview was live 5 minutes later.
What you will build
A pull request on your fork with:
- a comment from Light Cloud with the preview's address;
- a Light Cloud check with the build steps;
- a preview of the branch on its own address;
-
automatic cleanup when the branch is deleted.
Before you start
The app from part 5, with its staging database.
Your fork cloned on your laptop, as in part 5.
Step 1: Check the branch settings
Open the app (not an environment) and its Settings tab. Four switches control previews, and all four are on by default:
A preview URL for every branch explains each one.
Step 2: Know what a preview starts with
A preview environment starts with the app's defaults: the variables you set when you created the app in part 1. For this app that's APP_NAME, EMAIL_FROM, AUTH_SECRET and DATABASE_URL, so a preview runs on the production database with production's secret. The Stripe keys and APP_URL you added later on Production stay there, so a preview can't take payments.
Step 3: Open a pull request
Make a change on a new branch. In src/lib/plans.ts, change the Free plan's description:
description: "For trying it out on your own. No card needed.",
$ git switch main
$ git pull
$ git switch -c free-plan-5-projects
$ git commit -am "Free plan: say no card is needed"
$ git push -u origin free-plan-5-projects
PS> git switch main
PS> git pull
PS> git switch -c free-plan-5-projects
PS> git commit -am "Free plan: say no card is needed"
PS> git push -u origin free-plan-5-projects
On GitHub, click Compare & pull request on the banner, then Create pull request.
The app's Environments tab gets a third environment, named after the branch:
Its Settings show the variables it inherited, production's DATABASE_URL and AUTH_SECRET among them:
Step 4: Open the preview
Light Cloud comments on the pull request with a table: Status , Preview and Updated. While the branch builds it says Building , and then Ready with the address, https://free-plan-5-projects-tutorial-saas-starter-yourworkspace.light-cloud.io. The Light Cloud check on the pull request turns green at the same time.
Open the address. The pricing page shows the new Free plan text, while production still shows the old one:
Billing on the preview isn't available, because the Stripe variables live on Production only. A preview should never be able to charge a card.
Step 5: Merge and clean up
Merge the pull request on GitHub with Merge pull request , then click Delete branch. Two things follow:
- The merge reaches
main, so production redeploys with the new text. - Deleting the branch removes its environment. The comment on the pull request changes to Preview removed , and the preview's address stops answering. In my run both happened within seconds. <!-- IMAGE: s6-06-preview-removed.webp, the comment updated to Preview removed. Needs a GitHub sign-in in the capture browser. --> ## Troubleshooting
The preview shows production's users
That's the inherited DATABASE_URL from step 2. Set DATABASE_URL on the preview environment itself to a test database and push a new commit to the branch, so the preview redeploys.
No comment appears on the pull request
The Light Cloud GitHub App needs the pull request, checks and deployments permissions. The app's Settings tab says so if one is missing.
The pull request's CI check fails
The repository's own tests run on every pull request too. They check the plan limits, so a change to the number of projects needs the tests in test/plans.test.ts changed with it.





Top comments (0)