-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support preview from forked repositories
- Loading branch information
Showing
3 changed files
with
84 additions
and
72 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 |
---|---|---|
@@ -1,9 +1,10 @@ | ||
name: Surge.sh Preview | ||
|
||
on: | ||
pull_request_target: | ||
# when using teardown: 'true', add default event types + closed event type | ||
types: [opened, synchronize, reopened] | ||
workflow_run: | ||
workflows: [ "Publish website" ] | ||
types: | ||
- completed | ||
|
||
defaults: | ||
run: | ||
|
@@ -15,47 +16,57 @@ concurrency: | |
|
||
jobs: | ||
preview: | ||
runs-on: ubuntu-20.04 | ||
runs-on: ubuntu-latest | ||
if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' | ||
permissions: | ||
pull-requests: write # allow surge-preview to create/update PR comments | ||
pull-requests: write # Required to update PR status comment | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Download PR Artifact | ||
uses: actions/download-artifact@v4 | ||
with: | ||
ref: refs/pull/${{ github.event.pull_request.number }}/merge | ||
|
||
- name: Cache node modules | ||
id: cache-npm | ||
uses: actions/cache@v3 | ||
env: | ||
cache-name: cache-node-modules | ||
with: | ||
path: ~/.npm | ||
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} | ||
restore-keys: | | ||
${{ runner.os }}-build-${{ env.cache-name }}- | ||
${{ runner.os }}-build- | ||
${{ runner.os }}- | ||
name: site | ||
path: build/site | ||
|
||
- name: Install Node.js | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: '20' | ||
cache: 'npm' | ||
|
||
- name: Install packages | ||
run: npm i | ||
|
||
- name: Generate Site | ||
run: npm run build | ||
|
||
- uses: afc163/surge-preview@v1 | ||
id: preview_step | ||
- name: Store PR id as variable | ||
id: pr | ||
run: | | ||
echo "id=$(<pr-id.txt)" >> $GITHUB_OUTPUT | ||
rm -f pr-id.txt | ||
- name: Publishing to surge for preview | ||
id: deploy | ||
run: npx surge ./ --domain https://quarkiverse-docs-pr-${{ steps.pr.outputs.id }}-preview.surge.sh --token ${{ secrets.SURGE_TOKEN }} | ||
|
||
- name: Update PR status comment on success | ||
uses: actions-cool/[email protected] | ||
with: | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
body: | | ||
🚀 PR Preview ${{ github.sha }} has been successfully built and deployed to https://quarkiverse-docs-pr-${{ steps.pr.outputs.id }}-preview.surge.sh | ||
<!-- Sticky Pull Request Comment --> | ||
body-include: '<!-- Sticky Pull Request Comment -->' | ||
number: ${{ steps.pr.outputs.id }} | ||
|
||
- name: Update PR status comment on failure | ||
if: ${{ failure() }} | ||
uses: actions-cool/[email protected] | ||
with: | ||
surge_token: ${{ secrets.SURGE_TOKEN }} | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
dist: build/site | ||
failOnError: 'true' | ||
build: | | ||
echo Deploying to surge.sh | ||
- name: Get the preview_url | ||
run: echo "url => ${{ steps.preview_step.outputs.preview_url }}" | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
body: | | ||
😭 Deploy PR Preview failed. | ||
<img width="300" src="https://user-images.githubusercontent.com/507615/90250824-4e066700-de6f-11ea-8230-600ecc3d6a6b.png"> | ||
<!-- Sticky Pull Request Comment --> | ||
body-include: '<!-- Sticky Pull Request Comment -->' | ||
number: ${{ steps.pr.outputs.id }} |
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 |
---|---|---|
|
@@ -9,12 +9,15 @@ jobs: | |
preview: | ||
runs-on: ubuntu-20.04 | ||
steps: | ||
- uses: afc163/surge-preview@v1 | ||
id: preview_step | ||
- name: Teardown surge preview | ||
id: deploy | ||
run: npx surge teardown https://quarkiverse-docs-pr-${{ github.event.number }}-preview.surge.sh --token ${{ secrets.SURGE_TOKEN }} || true | ||
- name: Update PR status comment | ||
uses: actions-cool/[email protected] | ||
with: | ||
surge_token: ${{ secrets.SURGE_TOKEN }} | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
teardown: 'true' | ||
failOnError: 'false' | ||
build: | | ||
echo Undeploying from surge.sh | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
body: | | ||
🙈 The PR is closed and the preview is expired. | ||
<!-- Sticky Pull Request Comment --> | ||
body-include: '<!-- Sticky Pull Request Comment -->' | ||
number: ${{ github.event.number }} |
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