Skip to main content

Live Preview App in Pull Request

This tutorial explains how to set up pull request to launch live preview of your application and tear it down after pull request is closed.

For demonstration purpose, I set up a Heroku starter application in OneDev, when a pull request is created, the application will be deployed to Heroku, and a link of the deployment will be displayed for reviewers to check like below:

When there are new commits made into the pull request, the application will be re-deployed to reflect current change. After pull request is merged or discarded, the deployment will be removed from Heroku to save resource.

Now let’s check how to achieve this:

  1. Check build job Set Up Live Preview, the deploy step deploys current commit of the application to Heroku, and generates a markdown file containing deployed application link. This file then gets published via step publish pull request markdown report. The job is set to run automatically when pull request is opened or updated via job triggers.
  2. Check build job Tear Down Live Preview, the undeploy step deletes the deployed application if it exists. The job is set to run automatically when pull request is merged or discarded via job triggers.
  3. Navigate into menu Setting/Build Setting/Job Secrets of the project, define job secret named heroku_email to hold Heroku account email, and heroku_api_key to hold Heroku api key

That is it. Thanks for reading!