|
1 |
| -name: Deploy Next.js site to Pages |
| 1 | +name: 🐙 Deploy Next.js to GitHub Pages |
2 | 2 |
|
3 | 3 | on:
|
4 |
| - # Runs on pushes targeting the default branch |
5 | 4 | push:
|
6 | 5 | branches: ['main']
|
7 |
| - |
8 |
| - # Allows you to run this workflow manually from the Actions tab |
9 | 6 | workflow_dispatch:
|
10 | 7 |
|
11 |
| -# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages |
12 | 8 | permissions:
|
13 | 9 | contents: read
|
14 | 10 | pages: write
|
15 | 11 | id-token: write
|
16 | 12 |
|
17 |
| -# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. |
18 |
| -# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. |
19 | 13 | concurrency:
|
20 | 14 | group: 'pages'
|
21 | 15 | cancel-in-progress: false
|
22 | 16 |
|
23 | 17 | jobs:
|
24 |
| - # Build job |
25 | 18 | build:
|
| 19 | + name: 🛠️ Build Next.js |
26 | 20 | runs-on: ubuntu-latest
|
27 | 21 | steps:
|
28 |
| - - name: Checkout |
| 22 | + # Checkout code |
| 23 | + - name: 🔍 Checkout repository |
29 | 24 | uses: actions/checkout@v4
|
30 | 25 |
|
31 |
| - - name: Detect package manager |
32 |
| - id: detect-package-manager |
| 26 | + # Detect package manager |
| 27 | + - name: 🔎 Detect package manager |
| 28 | + id: detect-pm |
33 | 29 | run: |
|
34 |
| - if [ -f "${{ github.workspace }}/yarn.lock" ]; then |
35 |
| - echo "manager=yarn" >> $GITHUB_OUTPUT |
36 |
| - echo "command=install" >> $GITHUB_OUTPUT |
37 |
| - echo "runner=yarn" >> $GITHUB_OUTPUT |
38 |
| - elif [ -f "${{ github.workspace }}/pnpm-lock.yaml" ]; then |
| 30 | + echo "🔍 Scanning for package manager..." |
| 31 | + if [ -f "pnpm-lock.yaml" ]; then |
| 32 | + echo "✅ Found pnpm lockfile" |
39 | 33 | echo "manager=pnpm" >> $GITHUB_OUTPUT
|
40 | 34 | echo "command=install" >> $GITHUB_OUTPUT
|
41 | 35 | echo "runner=pnpm exec" >> $GITHUB_OUTPUT
|
42 |
| - elif [ -f "${{ github.workspace }}/package.json" ]; then |
| 36 | + elif [ -f "yarn.lock" ]; then |
| 37 | + echo "✅ Found yarn lockfile" |
| 38 | + echo "manager=yarn" >> $GITHUB_OUTPUT |
| 39 | + echo "command=install" >> $GITHUB_OUTPUT |
| 40 | + echo "runner=yarn" >> $GITHUB_OUTPUT |
| 41 | + elif [ -f "package.json" ]; then |
| 42 | + echo "ℹ️ Using npm as fallback" |
43 | 43 | echo "manager=npm" >> $GITHUB_OUTPUT
|
44 | 44 | echo "command=ci" >> $GITHUB_OUTPUT
|
45 | 45 | echo "runner=npx --no-install" >> $GITHUB_OUTPUT
|
46 | 46 | else
|
47 |
| - echo "Unable to determine package manager" |
| 47 | + echo "❌ No package manager detected!" |
48 | 48 | exit 1
|
49 | 49 | fi
|
50 | 50 |
|
51 |
| - - name: Setup Node |
| 51 | + # Setup Node.js with automatic package manager installation |
| 52 | + - name: ⚙️ Setup Node.js |
52 | 53 | uses: actions/setup-node@v4
|
53 | 54 | with:
|
54 | 55 | node-version: '20'
|
55 |
| - cache: ${{ steps.detect-package-manager.outputs.manager }} |
| 56 | + cache: ${{ steps.detect-pm.outputs.manager }} |
| 57 | + package-manager: ${{ steps.detect-pm.outputs.manager }} |
| 58 | + |
| 59 | + # Debugging step to verify installations |
| 60 | + - name: 📝 Check versions |
| 61 | + run: | |
| 62 | + echo "Node.js $(node -v)" |
| 63 | + echo "npm $(npm -v)" |
| 64 | + ${{ steps.detect-pm.outputs.manager }} --version |
56 | 65 |
|
57 |
| - - name: Setup Pages |
| 66 | + # Configure GitHub Pages |
| 67 | + - name: 🌐 Setup Pages |
58 | 68 | uses: actions/configure-pages@v5
|
59 | 69 | with:
|
60 |
| - # Automatically inject basePath in your Next.js configuration file and disable |
61 |
| - # server side image optimization. |
62 | 70 | static_site_generator: next
|
63 | 71 |
|
64 |
| - - name: Restore cache |
| 72 | + # Cache management |
| 73 | + - name: 📦 Restore cache |
65 | 74 | uses: actions/cache@v4
|
66 | 75 | with:
|
67 | 76 | path: |
|
68 | 77 | .next/cache
|
69 |
| - # Generate a new cache whenever packages or source files change. |
70 | 78 | key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock', '**/pnpm-lock.yaml') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }}
|
71 |
| - # If source files changed but packages didn't, rebuild from a prior cache. |
72 | 79 | restore-keys: |
|
73 | 80 | ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock', '**/pnpm-lock.yaml') }}-
|
74 | 81 |
|
75 |
| - - name: Install dependencies |
76 |
| - run: ${{ steps.detect-package-manager.outputs.manager }} ${{ steps.detect-package-manager.outputs.command }} |
| 82 | + # Install dependencies |
| 83 | + - name: 📥 Install dependencies |
| 84 | + run: ${{ steps.detect-pm.outputs.manager }} ${{ steps.detect-pm.outputs.command }} |
77 | 85 |
|
78 |
| - - name: Build with Next.js |
79 |
| - run: ${{ steps.detect-package-manager.outputs.runner }} next build |
| 86 | + # Build project |
| 87 | + - name: 👷 Build with Next.js |
| 88 | + run: ${{ steps.detect-pm.outputs.runner }} next build |
80 | 89 |
|
81 |
| - - name: Upload artifact |
| 90 | + # Upload artifact |
| 91 | + - name: 📤 Upload artifact |
82 | 92 | uses: actions/upload-pages-artifact@v3
|
83 | 93 | with:
|
84 | 94 | path: ./out
|
85 | 95 |
|
86 |
| - # Deployment job |
87 | 96 | deploy:
|
| 97 | + name: 🚀 Deploy to GitHub Pages |
88 | 98 | environment:
|
89 | 99 | name: github-pages
|
90 | 100 | url: ${{ steps.deployment.outputs.page_url }}
|
91 | 101 | runs-on: ubuntu-latest
|
92 | 102 | needs: build
|
93 | 103 | steps:
|
94 |
| - - name: Deploy to GitHub Pages |
| 104 | + - name: 🌍 Deploy to GitHub Pages |
95 | 105 | id: deployment
|
96 | 106 | uses: actions/deploy-pages@v4
|
0 commit comments