preview action #6
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
name: Deploy PR previews | |
concurrency: preview-${{ github.ref }} | |
on: | |
pull_request: | |
types: | |
- opened | |
- reopened | |
- synchronize | |
- closed | |
jobs: | |
deploy-preview: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
lfs: true | |
- run: npm i && npm run build-preview | |
if: github.event.action != 'closed' | |
- id: deploy_preview | |
uses: rossjrw/pr-preview-action@v1 | |
with: | |
source-dir: preview | |
preview-branch: gh-pages | |
umbrella-dir: pr-preview | |
action: auto | |
custom-url: | |
- if: github.event.action != 'closed' | |
run: | | |
git checkout gh-pages | |
git pull | |
grep ${{ steps.deploy_preview.outputs.deployment-url }} | |
if [ $? -ne 0 ]; then | |
sed -i '\|<div id="previews">|a <a href="${{ steps.deploy_preview.outputs.deployment-url }}">Preview PR#${{ github.event.pull_request.number }}</a><br>' index.html | |
git add index.html | |
git commit -m 'Added preview link' | |
git push | |
fi | |
- if: github.event.action == 'closed' | |
run: | | |
git checkout gh-pages | |
git pull | |
grep ${{ steps.deploy_preview.outputs.deployment-url }} | |
if [ $? -eq 0 ]; then | |
sed -i '\|${{ steps.deploy_preview.outputs.deployment-url }}|d' index.html | |
git add index.html | |
git commit -m 'Added preview link' | |
git push | |
fi |