Add action to deploy website previews for PRs #8
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
# Deploy preview of the website for PRs | |
name: Deploy PR Previews | |
on: | |
pull_request: | |
types: | |
- opened | |
- reopened | |
- synchronize | |
- closed | |
workflow_dispatch: | |
concurrency: preview-${{ github.ref }} | |
permissions: | |
contents: read | |
pages: write | |
actions: write | |
jobs: | |
deploy-preview: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Install Hugo CLI | |
run: | | |
wget -O hugo.deb https://github.com/gohugoio/hugo/releases/download/v0.128.0/hugo_extended_0.128.0_linux-amd64.deb \ | |
&& sudo dpkg -i hugo.deb | |
- name: Install Node.js dependencies | |
run: | | |
if [ -f package-lock.json ] || [ -f npm-shrinkwrap.json ]; then npm ci; else npm install; fi | |
- name: Build Hugo Site | |
if: github.event.action != 'closed' | |
env: | |
HUGO_ENVIRONMENT: preview | |
run: | | |
echo "Building site with baseURL: https://${{ github.repository_owner }}.github.io/${{ github.repository }}/pr-preview/pr-${{ github.event.number }}/" | |
hugo --environment preview --baseURL "https://${{ github.repository_owner }}.github.io/${{ github.repository }}/pr-preview/pr-${{ github.event.number }}/" --minify -d public | |
- name: List Public Directory | |
if: github.event.action != 'closed' | |
run: | | |
echo "Contents of the public directory:" | |
ls -R public | |
- name: Deploy PR Preview | |
uses: rossjrw/pr-preview-action@v1 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
source-dir: ./public | |
action: auto |