-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
103 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
# Surge PR Preview | ||
|
||
A GitHub action that preview website in [surge.sh](https://surge.sh/) for your pull requests. | ||
|
||
<img width="800" alt="image" src="https://user-images.githubusercontent.com/507615/90243810-2230b480-de62-11ea-9a2c-9e869a2067dd.png"> | ||
|
||
<img width="800" alt="image" src="https://user-images.githubusercontent.com/507615/91127543-0be3ed80-e6d9-11ea-897f-977c346bbc77.png"> | ||
|
||
### Pros | ||
|
||
Compare to Netlify/Vercel? | ||
|
||
- It is **free**. | ||
- It supports multiple preview jobs. | ||
|
||
### Usage | ||
|
||
Add a workflow (`.github/workflows/preview.yml`): | ||
|
||
```yaml | ||
name: 🔂 Surge PR Preview | ||
|
||
on: [pull_request] | ||
|
||
jobs: | ||
preview: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
pull-requests: write # allow surge-preview to create/update PR comments | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- 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 | ||
build: | | ||
npm install | ||
npm run build | ||
- name: Get the preview_url | ||
run: echo "url => ${{ steps.preview_step.outputs.preview_url }}" | ||
``` | ||
The preview website url will be `https://{{repository.owner}}-{{repository.name}}-{{job.name}}-pr-{{pr.number}}.surge.sh`. | ||
|
||
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 | ||
|
||
When a pull request is closed and teardown is set to 'true', then the surge instance will be destroyed. | ||
|
||
```yaml | ||
name: 🔂 Surge PR Preview | ||
on: | ||
pull_request: | ||
# when using teardown: 'true', add default event types + closed event type | ||
types: [opened, synchronize, reopened, closed] | ||
push: | ||
jobs: | ||
preview: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
pull-requests: write # allow surge-preview to create/update PR comments | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: 18.x | ||
- uses: hunghg255/surge-preview@master | ||
with: | ||
surge_token: ${{ secrets.SURGE_TOKEN }} | ||
dist: public | ||
teardown: 'true' | ||
build: | | ||
npm install | ||
npm run build | ||
``` | ||
|
||
### 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`. | ||
- `build`: build scripts to run before deploy. | ||
- `dist`: dist folder deployed to [surge.sh](https://surge.sh/). | ||
- `failOnError`: Set `failed` if a deployment throws error, defaults to `false`. | ||
- `teardown`: Determines if the preview instance will be torn down on PR close, defaults to `false`. | ||
|
||
### Outputs | ||
|
||
- `preview_url`: The url for the related PR preview |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters