Skip to content

Commit 34cd514

Browse files
Testing gh static pages site generation action workflow.
1 parent cab13d3 commit 34cd514

File tree

1 file changed

+96
-0
lines changed

1 file changed

+96
-0
lines changed
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
name: Deploy Next.js site to Pages
2+
3+
on:
4+
# Runs on pushes targeting the default branch
5+
push:
6+
branches: ['main']
7+
8+
# Allows you to run this workflow manually from the Actions tab
9+
workflow_dispatch:
10+
11+
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
12+
permissions:
13+
contents: read
14+
pages: write
15+
id-token: write
16+
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+
concurrency:
20+
group: 'pages'
21+
cancel-in-progress: false
22+
23+
jobs:
24+
# Build job
25+
build:
26+
runs-on: ubuntu-latest
27+
steps:
28+
- name: Checkout
29+
uses: actions/checkout@v4
30+
31+
- name: Detect package manager
32+
id: detect-package-manager
33+
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
39+
echo "manager=pnpm" >> $GITHUB_OUTPUT
40+
echo "command=install" >> $GITHUB_OUTPUT
41+
echo "runner=pnpm exec" >> $GITHUB_OUTPUT
42+
elif [ -f "${{ github.workspace }}/package.json" ]; then
43+
echo "manager=npm" >> $GITHUB_OUTPUT
44+
echo "command=ci" >> $GITHUB_OUTPUT
45+
echo "runner=npx --no-install" >> $GITHUB_OUTPUT
46+
else
47+
echo "Unable to determine package manager"
48+
exit 1
49+
fi
50+
51+
- name: Setup Node
52+
uses: actions/setup-node@v4
53+
with:
54+
node-version: '20'
55+
cache: ${{ steps.detect-package-manager.outputs.manager }}
56+
57+
- name: Setup Pages
58+
uses: actions/configure-pages@v5
59+
with:
60+
# Automatically inject basePath in your Next.js configuration file and disable
61+
# server side image optimization.
62+
static_site_generator: next
63+
64+
- name: Restore cache
65+
uses: actions/cache@v4
66+
with:
67+
path: |
68+
.next/cache
69+
# Generate a new cache whenever packages or source files change.
70+
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+
restore-keys: |
73+
${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock', '**/pnpm-lock.yaml') }}-
74+
75+
- name: Install dependencies
76+
run: ${{ steps.detect-package-manager.outputs.manager }} ${{ steps.detect-package-manager.outputs.command }}
77+
78+
- name: Build with Next.js
79+
run: ${{ steps.detect-package-manager.outputs.runner }} next build
80+
81+
- name: Upload artifact
82+
uses: actions/upload-pages-artifact@v3
83+
with:
84+
path: ./out
85+
86+
# Deployment job
87+
deploy:
88+
environment:
89+
name: github-pages
90+
url: ${{ steps.deployment.outputs.page_url }}
91+
runs-on: ubuntu-latest
92+
needs: build
93+
steps:
94+
- name: Deploy to GitHub Pages
95+
id: deployment
96+
uses: actions/deploy-pages@v4

0 commit comments

Comments
 (0)