A Preview URL for Every Branch, Posted on Your Pull Request

Push a branch, open a pull request, and a bot comments with a live link 16 seconds later. Merge it and the preview cleans itself up.

A Preview URL for Every Branch, Posted on Your Pull Request
On this pageShow
  1. What you will build
  2. Before you start
  3. Step 1: Check the branch settings
  4. Step 2: Push a branch and open a pull request
  5. Step 3: Open the preview
  6. Step 4: Read the check
  7. Step 5: Merge and let it clean up

To get a preview URL for every branch on Light Cloud, push the branch and open a pull request. With the default settings Light Cloud deploys the branch to its own address, reports it as a GitHub check, and the light-cloud-ci bot comments on the pull request with the link. When you merge and delete the branch, the preview is removed. There is no workflow file to write.

In my run the preview was live 16 seconds after git push.

What you will build

A pull request with a live preview link that reviewers can click, a passing check, and automatic cleanup after the merge:

The light-cloud-ci bot comment on the pull request: status Ready and the preview link friendlier-counter-tutorial-react-website-examples.light-cloud.io

The pull request from this guide is light-cloud-com/tutorial-react-website#1.

Before you start

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:

The Branch Automation and GitHub sections of the app settings, with Auto-create environment per branch and Comment preview links on pull requests highlighted

  • Auto-create environment per branch: every new branch gets its own environment and address.
  • Auto-cleanup when branch is deleted: the environment goes away with the branch.
  • Report deployments as GitHub checks: each commit gets a check with the build steps and the preview link.
  • Comment preview links on pull requests: one comment per environment, updated in place on every deploy.

The GitHub options need the Light Cloud GitHub App to have the checks, deployments and pull request permissions; the console says so if they are missing.

Step 2: Push a branch and open a pull request

Make a change on a new branch. Here the counter button in src/App.jsx gets a friendlier label:

src/App.jsx
jsx
Clicked {count} times
terminal
$ git checkout -b friendlier-counter
$ git commit -am "Friendlier counter label"
$ git push -u origin friendlier-counter

Now open your repository on GitHub. It shows a banner for the new branch: click Compare & pull request, then Create pull request.

Step 3: Open the preview

Within seconds the bot comments on the pull request with Building, then edits the same comment to Ready with the link (the screenshot at the top). In my run that took 16 seconds from the push.

The address follows https://<branch>-<app>-<workspace>.light-cloud.io. The preview has the change; production does not have it yet:

The preview site with the counter button reading Clicked 0 times

Every new commit on the branch redeploys the preview, and the bot updates its comment instead of adding a new one.

Step 4: Read the check

The Checks tab of the pull request has a Light Cloud CI check for each environment. It shows the preview address, the commit, the build time and each build step:

The Light Cloud CI check on GitHub: Deployed in 13s, the preview link, the commit, and the steps from Preparing R2 deployment to Finalizing R2 deployment

Open in Light Cloud leads to the deployment and its build log in the console.

Step 5: Merge and let it clean up

Merge the branch into main and delete it, with Git:

terminal
$ git switch main
$ git pull
$ git merge friendlier-counter
$ git push
$ git push origin --delete friendlier-counter

GitHub marks the pull request as merged as soon as its commit reaches main. (The Merge pull request and Delete branch buttons on GitHub do the same.)

Two things follow by themselves:

  1. The merge is a push to main, so production redeploys. In my run the change was live in production about 70 seconds after the merge.
  2. Deleting the branch removes its environment. My preview address answered 404 within seconds, and the bot changed its comment to Preview removed:

The bot comment updated to Preview removed after the branch was deleted

More tutorials