pnpm fix #4. #5
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 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 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 | |
# ✅ Explicitly Install pnpm before setting up Node.js | |
- 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 Pages | |
uses: actions/configure-pages@v5 | |
with: | |
static_site_generator: next | |
- 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: 👷 Build with Next.js | |
run: ${{ env.runner }} next build | |
- name: 📤 Upload artifact | |
uses: actions/upload-pages-artifact@v3 | |
with: | |
path: ./out | |
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 |