Skip to content

Commit ab347a2

Browse files
2 parents 5a00479 + 3fa982a commit ab347a2

File tree

1 file changed

+97
-0
lines changed

1 file changed

+97
-0
lines changed

.github/workflows/nextjs.yml

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# Sample workflow for building and deploying a Next.js site to GitHub Pages
2+
#
3+
# To get started with Next.js see: https://nextjs.org/docs/getting-started
4+
#
5+
name: Deploy Next.js site to Pages
6+
7+
defaults:
8+
run:
9+
working-directory: docs
10+
11+
on:
12+
# Runs on pushes targeting the default branch
13+
push:
14+
branches: ["main"]
15+
16+
# Allows you to run this workflow manually from the Actions tab
17+
workflow_dispatch:
18+
19+
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
20+
permissions:
21+
contents: read
22+
pages: write
23+
id-token: write
24+
25+
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
26+
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
27+
concurrency:
28+
group: "pages"
29+
cancel-in-progress: false
30+
31+
jobs:
32+
# Build job
33+
build:
34+
runs-on: ubuntu-latest
35+
steps:
36+
- name: Checkout
37+
uses: actions/checkout@v4
38+
- name: Detect package manager
39+
id: detect-package-manager
40+
run: |
41+
if [ -f "${{ github.workspace }}/yarn.lock" ]; then
42+
echo "manager=yarn" >> $GITHUB_OUTPUT
43+
echo "command=install" >> $GITHUB_OUTPUT
44+
echo "runner=yarn" >> $GITHUB_OUTPUT
45+
exit 0
46+
elif [ -f "${{ github.workspace }}/package.json" ]; then
47+
echo "manager=npm" >> $GITHUB_OUTPUT
48+
echo "command=ci" >> $GITHUB_OUTPUT
49+
echo "runner=npx --no-install" >> $GITHUB_OUTPUT
50+
exit 0
51+
else
52+
echo "Unable to determine package manager"
53+
exit 1
54+
fi
55+
- name: Setup Node
56+
uses: actions/setup-node@v4
57+
with:
58+
node-version: "20"
59+
cache: ${{ steps.detect-package-manager.outputs.manager }}
60+
- name: Setup Pages
61+
uses: actions/configure-pages@v5
62+
with:
63+
# Automatically inject basePath in your Next.js configuration file and disable
64+
# server side image optimization (https://nextjs.org/docs/api-reference/next/image#unoptimized).
65+
#
66+
# You may remove this line if you want to manage the configuration yourself.
67+
static_site_generator: next
68+
- name: Restore cache
69+
uses: actions/cache@v4
70+
with:
71+
path: |
72+
.next/cache
73+
# Generate a new cache whenever packages or source files change.
74+
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }}
75+
# If source files changed but packages didn't, rebuild from a prior cache.
76+
restore-keys: |
77+
${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-
78+
- name: Install dependencies
79+
run: ${{ steps.detect-package-manager.outputs.manager }} ${{ steps.detect-package-manager.outputs.command }}
80+
- name: Build with Next.js
81+
run: ${{ steps.detect-package-manager.outputs.runner }} next build
82+
- name: Upload artifact
83+
uses: actions/upload-pages-artifact@v3
84+
with:
85+
path: ./docs/out
86+
87+
# Deployment job
88+
deploy:
89+
environment:
90+
name: github-pages
91+
url: ${{ steps.deployment.outputs.page_url }}
92+
runs-on: ubuntu-latest
93+
needs: build
94+
steps:
95+
- name: Deploy to GitHub Pages
96+
id: deployment
97+
uses: actions/deploy-pages@v4

0 commit comments

Comments
 (0)