Skip to content

test preview

test preview #64

name: Build and Preview Site
on:
pull_request:
branches: [master]
types: [opened, synchronize, reopened, closed]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: write
pull-requests: write
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout 🛎️
uses: actions/checkout@v6
- name: Install and Build 🔧
env:
PATH_PREFIX: /recognition/pr-preview/pr-${{ github.event.pull_request.number }}
run: |
npm install
node -v
npm run build -- --prefix-paths
- name: Broken Link Check 🔗
uses: technote-space/broken-link-checker-action@v2
with:
target: ./public/**/*.html
- name: Zip Site
run: |
bash script.sh
- name: Upload files
uses: actions/upload-artifact@master
with:
name: public-dir
path: public-dir.zip
retention-days: 1
preview:
needs: build
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout 🛎️
uses: actions/checkout@v6
- name: Download pre-built site
if: github.event_name == 'pull_request'
uses: actions/download-artifact@v4
with:
name: public-dir
path: .
- name: Extract site
if: github.event_name == 'pull_request'
run: |
unzip -q public-dir.zip
# Ensure the extracted folder has the static files in a 'public' dir for the action
if [ -d "public-dir" ] && [ ! -d "public" ]; then
mv public-dir public
elif [ ! -d "public" ]; then
echo "Warning: Neither public nor public-dir found after extraction"
fi
- name: Deploy Preview
if: github.event_name == 'pull_request' && github.event.action != 'closed'
uses: rossjrw/pr-preview-action@v1.6.3
with:
source-dir: public
token: ${{ secrets.GITHUB_TOKEN }}
- name: Remove Preview on Close
if: github.event_name == 'pull_request' && github.event.action == 'closed'
uses: rossjrw/pr-preview-action@v1.6.3
with:
source-dir: public
remove: true
token: ${{ secrets.GITHUB_TOKEN }}