Skip to content

Removed relative basePath (not allowed). #42

Removed relative basePath (not allowed).

Removed relative basePath (not allowed). #42

name: 🚀 Deploy Static Next.js to GitHub Pages
on:
push:
branches: ['main'] # Triggers on push to main branch
workflow_dispatch: # Allows manual triggering
permissions:
contents: read
pages: write
id-token: write
concurrency:
group: 'pages'
cancel-in-progress: false
jobs:
build:
name: 🏗 Build Static Site
runs-on: ubuntu-latest
steps:
- name: 🔍 Checkout repository
uses: actions/checkout@v4
- name: 🔎 Detect package manager
id: detect-pm
run: |
if [ -f "pnpm-lock.yaml" ]; then
echo "manager=pnpm" >> $GITHUB_ENV
echo "command=install" >> $GITHUB_ENV
echo "runner=pnpm exec" >> $GITHUB_ENV
else
echo "manager=npm" >> $GITHUB_ENV
echo "command=ci" >> $GITHUB_ENV
echo "runner=npx --no-install" >> $GITHUB_ENV
fi
- name: 📦 Install pnpm
if: env.manager == 'pnpm'
run: npm install -g pnpm
- name: ⚙️ Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: ${{ env.manager }}
- name: 🌐 Setup GitHub Pages
uses: actions/configure-pages@v5
# NOTE: We do NOT need to create .env or secrets here, as we provide them directly to the build step below.
- name: 🚫 Ephemerally delete server/api files
run: |
echo "Deleting src/app/api, src/server, src/middleware.ts, and src/app/jobs/[id] for static build..."
rm -rf src/app/api src/server src/middleware.ts src/app/jobs/[id] src/app/[...not-found]
- name: 📥 Install dependencies
run: ${{ env.manager }} ${{ env.command }}
- name: 🏗 Generate Static Build
env:
NEXT_OUTPUT_MODE: export
GITHUB_PAGES: 1
run: |
echo "Building static files for GitHub Pages..."
pnpm build
touch out/.nojekyll
- name: 📤 Upload static site
uses: actions/upload-pages-artifact@v3
with:
path: ./out # With 'output: export', Next.js automatically puts files here.
deploy:
name: 🚀 Deploy to GitHub Pages
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: build
steps:
- name: 🌍 Deploy
id: deployment
uses: actions/deploy-pages@v4