Skip to content
This repository has been archived by the owner on Aug 7, 2021. It is now read-only.

πŸš€πŸŽ¬ GitHub Action to deploy every pull request to a static URL on Surge.sh

License

Notifications You must be signed in to change notification settings

AnandChowdhary/deploy-pr-action

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Repository files navigation

πŸš€πŸŽ¬ Deploy PR Action

This is a GitHub Action that automatically deploys all pull requests and branches as a static site using Surge.sh.

Test CI Release CI Node CI

⭐ Features

  • Auto-deploy every PR and branch to its unique environment
  • Unlimited free static site deployments, thanks to Surge.sh
  • No search engine indexing for branch sites (robots.txt injection)
  • Label and comment on PRs with the deployment and log URLs
  • Update your staging GitHub environment status

βš™οΈ Usage

Inputs

distDir (required)

The directory to deploy, for example dist or public

prefix

Prefix for deployment URL, e.g., example will translate to https://example-PR_NAME.surge.sh

robotsTxtPath

Generate a robots.txt file to prevent search engines from indexing the deployment

robotsContent

Content for robots.txt file, defaults to:

User-agent: *
Disallow: /

environmentName

Name of the deployment environment on GitHub, defaults to "Preview"

skipComment

Skip adding the deployment details comment, defaults to false

skipLabels

Skip adding the labels to pull requests, defaults to false

labels

Labels to add to pull requests as a comma-separated list, defaults to deployed

failOnDeployError

Set the status check to "failed" if a deployment error occurs, defaults to false

Environment variables

GITHUB_TOKEN (required)

The GitHub token is required to add labels, comments, etc., on the PR: GITHUB_TOKEN: ${{ secrets.GH_PAT }}

SURGE_LOGIN (required)

Your Surge.sh email address, required to deploy site to Surge.sh

SURGE_TOKEN (required)

Your Surge.sh login token, required to deploy site to Surge.sh (get it by doing surge token)

Example

name: Deploy CI
on:
  issue_comment:
    types: [created]
  push:
    branches-ignore:
      - master
  pull_request:
    types:
      - opened
      - edited
      - synchronize
jobs:
  release:
    name: Deploy website
    runs-on: ubuntu-18.04
    if: "!contains(github.event.head_commit.message, '[skip ci]') && (contains(github.event.comment.body, 'Deploy') || contains(github.event.comment.body, 'deploy') || github.event_name == 'push' || github.event_name == 'pull_request')"
    steps:
      - name: Checkout
        uses: actions/checkout@v1
      - name: Setup Node.js
        uses: actions/setup-node@v1
        with:
          node-version: 12
      - name: Install dependencies
        run: npm ci
      - name: Build static site
        run: npm run build # Build your website
      - name: Deploy
        uses: koj-co/deploy-pr-action@v1.0.1
        with:
          prefix: example # Prefix for deployment URL
          robotsTxtPath: dist/robots.txt # Add robots.txt file
          distDir: dist # Path to dist directory
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # GitHub token
          SURGE_LOGIN: ${{ secrets.SURGE_LOGIN }} # Surge.sh email
          SURGE_TOKEN: ${{ secrets.SURGE_TOKEN }} # Surge.sh token

πŸ“„ License

  • Code: MIT Β© Koj
  • "GitHub" is a trademark of GitHub, Inc.

Koj

An open source project by Koj.
Furnish your home in style, for as low as CHF175/month β†’