Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ajithlal's avatar

Create disposable sites

I have a requirement to create a disposable site to test the individual features. Is there any way to create a disposable site from GitHub actions and deploy the specific branch?

0 likes
6 replies
LaryAI's avatar
Level 58

Creating a disposable site for testing individual features can be achieved using GitHub Actions by setting up a workflow that deploys your application to a temporary environment whenever a new branch is pushed. Below is a step-by-step solution to create a disposable site using GitHub Actions:

  1. Set up a Hosting Service: Before you start, you need a hosting service that allows you to create and destroy environments programmatically. Services like Heroku, Vercel, Netlify, or any cloud provider with an API can be used for this purpose.

  2. GitHub Repository: Ensure your code is in a GitHub repository and you have the necessary permissions to add GitHub Actions workflows.

  3. GitHub Actions Workflow: Create a new workflow file in your repository under .github/workflows/ directory. You can name it deploy-disposable-site.yml.

  4. Workflow Configuration: Configure the workflow to trigger on push events for any branch except the main branch (assuming the main branch is your production branch).

  5. Deployment Steps: Add steps to your workflow to install dependencies, build your application, and deploy it to the hosting service. If your hosting service supports it, create a new environment for each branch.

  6. Cleanup: Optionally, you can add a step to clean up the environment when the branch is deleted.

Here's an example of what the GitHub Actions workflow file might look like for deploying to Heroku:

name: Deploy Disposable Site

on:
  push:
    branches-ignore:
      - main

jobs:
  build-and-deploy:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2

    - name: Setup Node.js
      uses: actions/setup-node@v1
      with:
        node-version: '14'

    - name: Install Dependencies
      run: npm install

    - name: Build
      run: npm run build

    - name: Deploy to Heroku
      env:
        HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }}
        HEROKU_APP_NAME: ${{ github.ref_name }}-test
      run: |
        git config --global user.email "[email protected]"
        git config --global user.name "Your Name"
        heroku create $HEROKU_APP_NAME --no-remote
        git push https://heroku:[email protected]/$HEROKU_APP_NAME.git HEAD:master

    - name: Cleanup
      if: github.event_name == 'delete'
      run: |
        heroku apps:destroy $HEROKU_APP_NAME --confirm $HEROKU_APP_NAME
      env:
        HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }}
        HEROKU_APP_NAME: ${{ github.ref_name }}-test

In this example, replace npm install and npm run build with the commands that are appropriate for your project. Also, make sure to replace the HEROKU_API_KEY with your actual Heroku API key stored as a secret in your GitHub repository settings.

This workflow will create a new Heroku app for each branch pushed to the repository (except the main branch), allowing you to have a disposable site for testing. When the branch is deleted, the associated Heroku app will be destroyed if you include the cleanup step.

Remember to tailor the workflow to your specific use case and hosting provider. The above example is a starting point and may require adjustments based on your project's needs.

martinbean's avatar

@ajithlal You’re describing “review apps”. Yes, it’s possible to create and deploy from GitHub Actions.

ajithlal's avatar

@martinbean If possible could you please provide a guide or instructions on how to implement it?

martinbean's avatar

@ajithlal Not really, as it differs wildly between how your application is build, where you’re deploying it to, etc.

You’d have a GitHub Actions workflow that runs on PRs or whatever, that creates the infrastructure for your review app and deploys that branch there. When the PR is closed, you spin down the review app’s infrastructure.

1 like
ajithlal's avatar

@martinbean I Agree. But, when I googled I couldn't find relevant information about how to set a runner for spinning up a review app on the forge while creating a PR and spin down when the PR is closed. So I'm a bit confused about how I will set up the same.

Please or to participate in this conversation.