Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add action to deploy website previews for PRs #2

Draft
wants to merge 6 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions .github/workflows/preview.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# 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: Check Base URL in Generated HTML
if: github.event.action != 'closed'
run: |
echo "Checking base URL in generated HTML files:"
grep -r "https://${{ github.repository_owner }}.github.io/${{ github.repository }}/pr-preview/pr-${{ github.event.number }}/" public || echo "Base URL not found in some files"

- name: Deploy PR Preview
uses: rossjrw/pr-preview-action@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
source-dir: ./public
action: auto
7 changes: 6 additions & 1 deletion hugo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ baseURL: https://neurodatawithoutborders.github.io/
languageCode: en
title: Neurodata Without Borders
paginate: 6
# Markup
# Markup
markup:
goldmark:
renderer:
Expand All @@ -12,3 +12,8 @@ module:
mounts:
- source: assets
target: assets

# Environment-specific settings
environments:
preview:
baseURL: https://neurodatawithoutborders.github.io/pr-preview/
Loading