1
- name : 🐙 Deploy Next.js to GitHub Pages
1
+ name : 🚀 Deploy Next.js to GitHub Pages
2
2
3
3
on :
4
4
push :
@@ -19,57 +19,48 @@ jobs:
19
19
name : 🛠️ Build Next.js
20
20
runs-on : ubuntu-latest
21
21
steps :
22
- # Checkout code
23
22
- name : 🔍 Checkout repository
24
23
uses : actions/checkout@v4
25
24
26
- # Detect package manager
27
25
- name : 🔎 Detect package manager
28
26
id : detect-pm
29
27
run : |
30
- echo "🔍 Scanning for package manager..."
31
28
if [ -f "pnpm-lock.yaml" ]; then
32
- echo "✅ Found pnpm lockfile"
33
29
echo "manager=pnpm" >> $GITHUB_OUTPUT
34
30
echo "command=install" >> $GITHUB_OUTPUT
35
31
echo "runner=pnpm exec" >> $GITHUB_OUTPUT
36
32
elif [ -f "yarn.lock" ]; then
37
- echo "✅ Found yarn lockfile"
38
33
echo "manager=yarn" >> $GITHUB_OUTPUT
39
34
echo "command=install" >> $GITHUB_OUTPUT
40
35
echo "runner=yarn" >> $GITHUB_OUTPUT
41
- elif [ -f "package.json" ]; then
42
- echo "ℹ️ Using npm as fallback"
36
+ else
43
37
echo "manager=npm" >> $GITHUB_OUTPUT
44
38
echo "command=ci" >> $GITHUB_OUTPUT
45
39
echo "runner=npx --no-install" >> $GITHUB_OUTPUT
46
- else
47
- echo "❌ No package manager detected!"
48
- exit 1
49
40
fi
50
41
51
- # Setup Node.js with automatic package manager installation
52
42
- name : ⚙️ Setup Node.js
53
43
uses : actions/setup-node@v4
54
44
with :
55
45
node-version : ' 20'
56
46
cache : ${{ steps.detect-pm.outputs.manager }}
57
- package-manager : ${{ steps.detect-pm.outputs.manager }}
58
47
59
- # Debugging step to verify installations
60
- - name : 📝 Check versions
48
+ # New step to install pnpm if needed
49
+ - name : 📦 Install Package Manager
50
+ if : steps.detect-pm.outputs.manager == 'pnpm'
51
+ run : npm install -g pnpm
52
+
53
+ - name : 📝 Verify Environment
61
54
run : |
62
55
echo "Node.js $(node -v)"
63
56
echo "npm $(npm -v)"
64
57
${{ steps.detect-pm.outputs.manager }} --version
65
58
66
- # Configure GitHub Pages
67
59
- name : 🌐 Setup Pages
68
60
uses : actions/configure-pages@v5
69
61
with :
70
62
static_site_generator : next
71
63
72
- # Cache management
73
64
- name : 📦 Restore cache
74
65
uses : actions/cache@v4
75
66
with :
@@ -79,15 +70,12 @@ jobs:
79
70
restore-keys : |
80
71
${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock', '**/pnpm-lock.yaml') }}-
81
72
82
- # Install dependencies
83
73
- name : 📥 Install dependencies
84
74
run : ${{ steps.detect-pm.outputs.manager }} ${{ steps.detect-pm.outputs.command }}
85
75
86
- # Build project
87
76
- name : 👷 Build with Next.js
88
77
run : ${{ steps.detect-pm.outputs.runner }} next build
89
78
90
- # Upload artifact
91
79
- name : 📤 Upload artifact
92
80
uses : actions/upload-pages-artifact@v3
93
81
with :
101
89
runs-on : ubuntu-latest
102
90
needs : build
103
91
steps :
104
- - name : 🌍 Deploy to GitHub Pages
92
+ - name : 🌍 Deploy
105
93
id : deployment
106
94
uses : actions/deploy-pages@v4
0 commit comments