Skip to content

Commit

Permalink
docs: update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
hunghg255 committed Nov 16, 2023
1 parent b7a39d5 commit 22a9756
Showing 1 changed file with 49 additions and 16 deletions.
65 changes: 49 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,54 @@ A GitHub action that preview website in [surge.sh](https://surge.sh/) for your p

<img width="800" alt="image" src="./assets/success.png">

### Pros
## Pros

Compare to Netlify/Vercel?

- It is **free**.
- It supports multiple preview jobs.

### Usage
## Usage

Add a workflow (`.github/workflows/preview.yml`):

```yaml
name: 🔂 Surge PR Preview
name: 🔂 Preview Pull Request

on: [pull_request]
on:
pull_request:
types:
- opened
- synchronize
- closed
branches:
- dev

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
preview:
runs-on: ubuntu-latest
permissions:
pull-requests: write # allow surge-preview to create/update PR comments
pull-requests: write
contents: read
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- uses: actions/setup-node@v3
with:
node-version: 18.x
- uses: hunghg255/surge-preview@master
id: preview_step
with:
surge_token: ${{ secrets.SURGE_TOKEN }}
dist: public
github_token: ${{ secrets.GH_TOKEN }}
dist: dist
failOnError: true
build: |
npm install
npm run build
Expand All @@ -51,40 +68,56 @@ The preview website urls will be:
- `https://{{repository.owner}}-{{repository.name}}-preview-job-1-pr-{{pr.number}}.surge.sh`
- `https://{{repository.owner}}-{{repository.name}}-preview-job-2-pr-{{pr.number}}.surge.sh`

### Teardown
## Teardown

When a pull request is closed and teardown is set to 'true', then the surge instance will be destroyed.

```yaml
name: 🔂 Surge PR Preview
name: 🔂 Preview Pull Request
on:
pull_request:
# when using teardown: 'true', add default event types + closed event type
types: [opened, synchronize, reopened, closed]
push:
types:
- opened
- synchronize
- closed
branches:
- dev
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
preview:
runs-on: ubuntu-latest
permissions:
pull-requests: write # allow surge-preview to create/update PR comments
pull-requests: write
contents: read
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-node@v3
with:
node-version: 18.x
- uses: hunghg255/surge-preview@master
id: preview_step
with:
surge_token: ${{ secrets.SURGE_TOKEN }}
dist: public
github_token: ${{ secrets.GH_TOKEN }}
dist: dist
failOnError: true
teardown: 'true'
build: |
npm install
npm run build
- name: Get the preview_url
run: echo "url => ${{ steps.preview_step.outputs.preview_url }}"
```

### Inputs
## Inputs

- `surge_token`: [Getting your Surge token](https://surge.sh/help/integrating-with-circleci).
- `github_token`: Defaults: [`github.token`](https://docs.github.com/en/actions/security-guides/automatic-token-authentication#using-the-github_token-in-a-workflow). It is used to create Pull Request comment, so it requires the `pull-requests` permission set to `write` permission. Possible value: `secrets.GITHUB_TOKEN`.
Expand All @@ -94,6 +127,6 @@ jobs:
- `teardown`: Determines if the preview instance will be torn down on PR close, defaults to `false`.
- `preview_branch`: deploy to a branch, defaults to `false`.

### Outputs
## Outputs

- `preview_url`: The url for the related PR preview

0 comments on commit 22a9756

Please sign in to comment.