Skip to content

Commit 0f37c04

Browse files
Attempting to fix gh-static workflow.
1 parent 1e245f1 commit 0f37c04

1 file changed

Lines changed: 37 additions & 43 deletions

File tree

.github/workflows/nextjs-static-gh-pages.yml

Lines changed: 37 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ name: 🚀 Deploy Static Next.js to GitHub Pages
22

33
on:
44
push:
5-
branches: ['gh-static']
6-
workflow_dispatch:
5+
branches: ['gh-static'] # Triggers on push to this branch
6+
workflow_dispatch: # Allows manual triggering
77

88
permissions:
99
contents: read
@@ -16,8 +16,28 @@ concurrency:
1616

1717
jobs:
1818
build:
19-
name: 🏗 Build Static Next.js
19+
name: 🏗 Build Static Site
2020
runs-on: ubuntu-latest
21+
22+
# ===================================================================
23+
# THE FIX, PART 1: Create a temporary PostgreSQL database service
24+
# This database will only exist for the duration of this build job.
25+
# ===================================================================
26+
services:
27+
postgres:
28+
image: postgres:15-alpine
29+
env:
30+
POSTGRES_USER: user
31+
POSTGRES_PASSWORD: password
32+
POSTGRES_DB: temp_db
33+
ports:
34+
- 5432:5432 # Map port 5432 on the runner to the container's port 5432
35+
options: >-
36+
--health-cmd pg_isready
37+
--health-interval 10s
38+
--health-timeout 5s
39+
--health-retries 5
40+
2141
steps:
2242
- name: 🔍 Checkout repository
2343
uses: actions/checkout@v4
@@ -29,17 +49,13 @@ jobs:
2949
echo "manager=pnpm" >> $GITHUB_ENV
3050
echo "command=install" >> $GITHUB_ENV
3151
echo "runner=pnpm exec" >> $GITHUB_ENV
32-
elif [ -f "yarn.lock" ]; then
33-
echo "manager=yarn" >> $GITHUB_ENV
34-
echo "command=install" >> $GITHUB_ENV
35-
echo "runner=yarn" >> $GITHUB_ENV
3652
else
3753
echo "manager=npm" >> $GITHUB_ENV
3854
echo "command=ci" >> $GITHUB_ENV
3955
echo "runner=npx --no-install" >> $GITHUB_ENV
4056
fi
4157
42-
- name: 📦 Install pnpm if needed
58+
- name: 📦 Install pnpm
4359
if: env.manager == 'pnpm'
4460
run: npm install -g pnpm
4561

@@ -49,55 +65,33 @@ jobs:
4965
node-version: '20'
5066
cache: ${{ env.manager }}
5167

52-
- name: 📝 Verify Environment
53-
run: |
54-
echo "Node.js $(node -v)"
55-
echo "npm $(npm -v)"
56-
${{ env.manager }} --version
57-
5868
- name: 🌐 Setup GitHub Pages
5969
uses: actions/configure-pages@v5
6070

61-
# ========================
62-
# 🔐 Secrets & Config Setup
63-
# ========================
64-
- name: 🔒 Verify Secrets Exist
65-
run: |
66-
if [ -z "${{ secrets.GOOGLE_SERVICES_JSON_BASE64 }}" ]; then
67-
echo "❌ Critical error: GOOGLE_SERVICES_JSON_BASE64 secret missing!"
68-
exit 1
69-
fi
70-
echo "✅ All secrets present"
71-
72-
- name: 📁 Create google-services.json in Root
73-
run: |
74-
echo "$GOOGLE_SERVICES_JSON_BASE64" | base64 --decode > google-services.json
75-
jq empty google-services.json # Validate JSON
76-
env:
77-
GOOGLE_SERVICES_JSON_BASE64: ${{ secrets.GOOGLE_SERVICES_JSON_BASE64 }}
78-
79-
- name: 📦 Restore cache
80-
uses: actions/cache@v4
81-
with:
82-
path: .next/cache
83-
key: nextjs-${{ runner.os }}-${{ hashFiles('**/package-lock.json', '**/yarn.lock', '**/pnpm-lock.yaml') }}
84-
restore-keys: |
85-
nextjs-${{ runner.os }}-
71+
# NOTE: We do NOT need to create .env or secrets here, as we provide them directly to the build step below.
8672

8773
- name: 📥 Install dependencies
8874
run: ${{ env.manager }} ${{ env.command }}
8975

9076
- name: 🏗 Generate Static Build
77+
# =====================================================================
78+
# THE FIX, PART 2: Provide the database URL to the build command
79+
# This points your app to the temporary database service we created above.
80+
# Note the removal of the deprecated 'next export' command.
81+
# =====================================================================
82+
env:
83+
DATABASE_URL: 'postgresql://user:password@localhost:5432/temp_db'
84+
SHADOW_DATABASE_URL: 'postgresql://user:password@localhost:5432/temp_db_shadow'
85+
# Add any other required build-time environment variables here
9186
run: |
92-
echo "⚠️ Exporting static files. Pages with SSR/API routes will be ignored."
87+
echo "Building static files..."
9388
${{ env.runner }} next build
94-
${{ env.runner }} next export
95-
touch out/.nojekyll # Prevent GitHub from ignoring _next folder
89+
touch out/.nojekyll
9690
9791
- name: 📤 Upload static site
9892
uses: actions/upload-pages-artifact@v3
9993
with:
100-
path: ./out # This is where static files go after next export
94+
path: ./out # With 'output: export', Next.js automatically puts files here.
10195

10296
deploy:
10397
name: 🚀 Deploy to GitHub Pages

0 commit comments

Comments
 (0)