GitHub action to deploy review apps to surge

01 Jul 2022

This post explains a simple GitHub action to deploy your frontend app to surge for each pull request created.

This post assumes you already have surge installed and logged in.

Now, let’s generate a new surge token

surge token

Add the generated token to Github secrets so that GitHub actions can use it.

Next, add the following action into .github/workflows.

# .github/workflows/surge.yml
name: Deploy to surge

      - 'main'

    runs-on: ubuntu-latest
    name: Deploying to surge
      - uses: actions/checkout@v1
      - name: Install surge and fire deployment
        uses: actions/setup-node@v1
          node-version: 18
      - run: npm i -g surge
      - run: npm ci
      - run: npm run build
      - run: surge ./dist/ my-app-${{ github.event.number || 'main' }} --token ${{ secrets.SURGE_TOKEN }}  

This will action will get triggered when a pull request is created/updated and merged to the main.

We use the pull request id in the URL for each review app like for the review apps and when we merge the pull request to main it will deploy to

Hope that helped.

If you find my work helpful, You can buy me a coffee.