Skip to content

Commit b7dfb86

Browse files
Add GitHub Pages deployment workflow.
Configure static export for Next.js and fix build settings so CI can publish to Pages. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 42a6c0e commit b7dfb86

4 files changed

Lines changed: 93 additions & 1 deletion

File tree

‎.github/workflows/deploy-pages.yml‎

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
name: Deploy Next.js site to Pages
2+
3+
on:
4+
push:
5+
branches: ["main"]
6+
workflow_dispatch:
7+
8+
permissions:
9+
contents: read
10+
pages: write
11+
id-token: write
12+
13+
concurrency:
14+
group: "pages"
15+
cancel-in-progress: false
16+
17+
jobs:
18+
build:
19+
runs-on: ubuntu-latest
20+
steps:
21+
- name: Checkout
22+
uses: actions/checkout@v4
23+
24+
- name: Detect package manager
25+
id: detect-package-manager
26+
run: |
27+
if [ -f "${{ github.workspace }}/yarn.lock" ]; then
28+
echo "manager=yarn" >> $GITHUB_OUTPUT
29+
echo "command=install" >> $GITHUB_OUTPUT
30+
echo "runner=yarn" >> $GITHUB_OUTPUT
31+
exit 0
32+
elif [ -f "${{ github.workspace }}/package.json" ]; then
33+
echo "manager=npm" >> $GITHUB_OUTPUT
34+
echo "command=ci" >> $GITHUB_OUTPUT
35+
echo "runner=npx --no-install" >> $GITHUB_OUTPUT
36+
exit 0
37+
else
38+
echo "Unable to determine package manager"
39+
exit 1
40+
fi
41+
42+
- name: Setup Node
43+
uses: actions/setup-node@v4
44+
with:
45+
node-version: "20"
46+
cache: ${{ steps.detect-package-manager.outputs.manager }}
47+
48+
- name: Setup Pages
49+
uses: actions/configure-pages@v5
50+
with:
51+
static_site_generator: next
52+
53+
- name: Restore cache
54+
uses: actions/cache@v4
55+
with:
56+
path: |
57+
.next/cache
58+
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }}
59+
restore-keys: |
60+
${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-
61+
62+
- name: Install dependencies
63+
run: ${{ steps.detect-package-manager.outputs.manager }} ${{ steps.detect-package-manager.outputs.command }}
64+
65+
- name: Build with Next.js
66+
run: ${{ steps.detect-package-manager.outputs.runner }} next build
67+
68+
- name: Upload artifact
69+
uses: actions/upload-pages-artifact@v3
70+
with:
71+
path: ./out
72+
73+
deploy:
74+
environment:
75+
name: github-pages
76+
url: ${{ steps.deployment.outputs.page_url }}
77+
runs-on: ubuntu-latest
78+
needs: build
79+
steps:
80+
- name: Deploy to GitHub Pages
81+
id: deployment
82+
uses: actions/deploy-pages@v5

‎next.config.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
import type { NextConfig } from "next";
22

3+
const repoName = process.env.GITHUB_REPOSITORY?.split("/")[1];
4+
const basePath =
5+
process.env.GITHUB_ACTIONS === "true" && repoName ? `/${repoName}` : "";
6+
37
const nextConfig: NextConfig = {
8+
output: "export",
9+
basePath,
10+
trailingSlash: true,
411
images: {
12+
unoptimized: true,
513
remotePatterns: [
614
{ protocol: "https", hostname: "github.com" },
715
{ protocol: "https", hostname: "githubusercontent.com" },

‎src/app/sitemap.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { getAllDocSlugs } from "@/lib/docs";
33
import { blogPosts } from "@/lib/routes";
44
import { site } from "@/lib/site";
55

6+
export const dynamic = "force-static";
7+
68
const routes = [
79
"",
810
"philosophy",

‎src/lib/github.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { site } from "@/lib/site";
33
export async function getGitHubStars(): Promise<number> {
44
try {
55
const res = await fetch("https://api.github.com/repos/DebugSwift/DebugSwift", {
6-
next: { revalidate: 3600 },
6+
cache: "force-cache",
77
headers: { Accept: "application/vnd.github+json" },
88
});
99
if (!res.ok) return 0;

0 commit comments

Comments
 (0)