Skip to content

refactor(gatsby-node): simplify page creation logic and remove redundant redirects #12412

refactor(gatsby-node): simplify page creation logic and remove redundant redirects

refactor(gatsby-node): simplify page creation logic and remove redundant redirects #12412

name: PR Preview Deployment (Gatsby + GitHub Pages)
on:
pull_request_target:
branches: [master]
types: [opened, synchronize, reopened, closed]
permissions:
contents: write
pull-requests: write
concurrency:
group: preview-${{ github.event.pull_request.number || github.run_id }}
cancel-in-progress: true
jobs:
preview:
runs-on: ubuntu-latest
steps:
- name: Checkout PR
if: github.event.action != 'closed'
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Checkout gh-pages for cleanup
if: github.event.action == 'closed'
uses: actions/checkout@v4
with:
ref: gh-pages
- name: Setup Node
if: github.event.action != 'closed'
uses: actions/setup-node@v4
with:
node-version: "20"
- name: Install dependencies
if: github.event.action != 'closed'
run: npm ci
- name: Set PATH_PREFIX for preview
if: github.event.action != 'closed'
run: |
echo "PATH_PREFIX=pr-preview/pr-${{ github.event.pull_request.number }}" >> $GITHUB_ENV
- name: Build PR preview
if: github.event.action != 'closed'
env:
GATSBY_PREVIEW: "true"
GATSBY_SITE_URL: https://${{ github.repository_owner }}.github.io
run: |
PATH_PREFIX=$PATH_PREFIX npm run build:preview
# Prevent indexing
echo -e "User-agent: *\nDisallow: /" > public/robots.txt
- name: Deploy PR preview
if: github.event.action != 'closed'
uses: rossjrw/pr-preview-action@v1.6.3
with:
source-dir: ./public
preview-branch: gh-pages
umbrella-dir: pr-preview
action: auto
comment: false
- name: Comment PR with Preview URL
if: github.event.action != 'closed'
uses: marocchino/sticky-pull-request-comment@v2
with:
header: pr-preview
message: |
🚀 **Preview for PR #${{ github.event.pull_request.number }}**
🌐 https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/pr-preview/pr-${{ github.event.pull_request.number }}/
- name: Cleanup PR preview
if: github.event.action == 'closed'
uses: rossjrw/pr-preview-action@v1.6.3
with:
preview-branch: gh-pages
umbrella-dir: pr-preview
action: remove