Skip to content

Commit 69e499f

Browse files
authored
Update deploy.yml
1 parent 5346ed1 commit 69e499f

File tree

1 file changed

+75
-18
lines changed

1 file changed

+75
-18
lines changed

.github/workflows/deploy.yml

Lines changed: 75 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,91 @@
1-
name: Deploy to GitHub Pages
1+
name: Deploy Next.js site to Pages
22

33
on:
4+
# Runs on pushes targeting the default branch
45
push:
5-
branches:
6-
- main
6+
branches: ["main"]
77

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
812
permissions:
9-
contents: write
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
1022

1123
jobs:
12-
deploy:
24+
# Build job
25+
build:
1326
runs-on: ubuntu-latest
27+
env:
28+
NPM_CONFIG_LEGACY_PEER_DEPS: true
1429
steps:
1530
- name: Checkout
1631
uses: actions/checkout@v4
17-
18-
- name: Setup Node.js
32+
- name: Detect package manager
33+
id: detect-package-manager
34+
run: |
35+
if [ -f "${{ github.workspace }}/yarn.lock" ]; then
36+
echo "manager=yarn" >> $GITHUB_OUTPUT
37+
echo "command=install" >> $GITHUB_OUTPUT
38+
echo "runner=yarn" >> $GITHUB_OUTPUT
39+
exit 0
40+
elif [ -f "${{ github.workspace }}/package.json" ]; then
41+
echo "manager=npm" >> $GITHUB_OUTPUT
42+
echo "command=ci" >> $GITHUB_OUTPUT
43+
echo "runner=npx --no-install" >> $GITHUB_OUTPUT
44+
exit 0
45+
else
46+
echo "Unable to determine package manager"
47+
exit 1
48+
fi
49+
- name: Setup Node
1950
uses: actions/setup-node@v4
2051
with:
21-
node-version: 20
22-
52+
node-version: "20"
53+
cache: ${{ steps.detect-package-manager.outputs.manager }}
54+
- name: Setup Pages
55+
uses: actions/configure-pages@v5
56+
with:
57+
# Automatically inject basePath in your Next.js configuration file and disable
58+
# server side image optimization (https://nextjs.org/docs/api-reference/next/image#unoptimized).
59+
#
60+
# You may remove this line if you want to manage the configuration yourself.
61+
static_site_generator: next
62+
- name: Restore cache
63+
uses: actions/cache@v4
64+
with:
65+
path: |
66+
.next/cache
67+
# Generate a new cache whenever packages or source files change.
68+
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }}
69+
# If source files changed but packages didn't, rebuild from a prior cache.
70+
restore-keys: |
71+
${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-
2372
- name: Install dependencies
24-
run: npm install --legacy-peer-deps
25-
26-
- name: Build and Export
27-
run: |
28-
npm run build
73+
run: ${{ steps.detect-package-manager.outputs.manager }} ${{ steps.detect-package-manager.outputs.command }}
74+
- name: Build with Next.js
75+
run: ${{ steps.detect-package-manager.outputs.runner }} next build
76+
- name: Upload artifact
77+
uses: actions/upload-pages-artifact@v3
78+
with:
79+
path: ./out
2980

81+
# Deployment job
82+
deploy:
83+
environment:
84+
name: github-pages
85+
url: ${{ steps.deployment.outputs.page_url }}
86+
runs-on: ubuntu-latest
87+
needs: build
88+
steps:
3089
- name: Deploy to GitHub Pages
31-
uses: peaceiris/actions-gh-pages@v4
32-
with:
33-
github_token: ${{ secrets.GITHUB_TOKEN }}
34-
publish_dir: ./out
90+
id: deployment
91+
uses: actions/deploy-pages@v4

0 commit comments

Comments
 (0)