Upgraded pnpm version. #16
This file contains hidden or 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
name: 🚀 Deploy Static Next.js to GitHub Pages | |
on: | |
push: | |
branches: ['main'] | |
workflow_dispatch: | |
permissions: | |
contents: read | |
pages: write | |
id-token: write | |
concurrency: | |
group: 'pages' | |
cancel-in-progress: false | |
jobs: | |
build: | |
name: 🏗 Build Static Next.js | |
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 | |
elif [ -f "yarn.lock" ]; then | |
echo "manager=yarn" >> $GITHUB_ENV | |
echo "command=install" >> $GITHUB_ENV | |
echo "runner=yarn" >> $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 needed | |
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: 📝 Verify Environment | |
run: | | |
echo "Node.js $(node -v)" | |
echo "npm $(npm -v)" | |
${{ env.manager }} --version | |
- name: 🌐 Setup GitHub Pages | |
uses: actions/configure-pages@v5 | |
# ======================== | |
# 🔐 Secrets & Config Setup | |
# ======================== | |
- name: 🔒 Verify Secrets Exist | |
run: | | |
if [ -z "${{ secrets.GOOGLE_SERVICES_JSON_BASE64 }}" ]; then | |
echo "❌ Critical error: GOOGLE_SERVICES_JSON_BASE64 secret missing!" | |
exit 1 | |
fi | |
echo "✅ All secrets present" | |
- name: 📁 Create google-services.json in Root | |
run: | | |
echo "$GOOGLE_SERVICES_JSON_BASE64" | base64 --decode > google-services.json | |
jq empty google-services.json # Validate JSON | |
env: | |
GOOGLE_SERVICES_JSON_BASE64: ${{ secrets.GOOGLE_SERVICES_JSON_BASE64 }} | |
- name: 📦 Restore cache | |
uses: actions/cache@v4 | |
with: | |
path: .next/cache | |
key: nextjs-${{ runner.os }}-${{ hashFiles('**/package-lock.json', '**/yarn.lock', '**/pnpm-lock.yaml') }} | |
restore-keys: | | |
nextjs-${{ runner.os }}- | |
- name: 📥 Install dependencies | |
run: ${{ env.manager }} ${{ env.command }} | |
- name: 🏗 Generate Static Build | |
run: | | |
echo "⚠️ Exporting static files. Pages with SSR/API routes will be ignored." | |
${{ env.runner }} next build | |
${{ env.runner }} next export | |
touch out/.nojekyll # Prevent GitHub from ignoring _next folder | |
- name: 📤 Upload static site | |
uses: actions/upload-pages-artifact@v3 | |
with: | |
path: ./out # This is where static files go after next export | |
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 |