Skip to content

Commit 13aa8bb

Browse files
committed
Refactor GitHub Actions workflow for Next.js deployment
1 parent ad520c1 commit 13aa8bb

1 file changed

Lines changed: 27 additions & 58 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 27 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,49 @@
1-
name: Deploy Next.js site to Pages
1+
name: Deploy
22

33
on:
4-
# Runs on pushes targeting the main branch
54
push:
65
branches:
76
- main
87

9-
# Allows you to run this workflow manually from the Actions tab
10-
workflow_dispatch:
11-
12-
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
13-
permissions:
14-
contents: read
15-
pages: write
16-
id-token: write
17-
18-
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
19-
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
20-
concurrency:
21-
group: "pages"
22-
cancel-in-progress: false
23-
248
jobs:
259
build:
10+
name: Build
2611
runs-on: ubuntu-latest
27-
steps:
28-
- name: Checkout
29-
uses: actions/checkout@v4
3012

31-
- uses: pnpm/action-setup@v4
32-
name: Install pnpm
33-
with:
34-
version: 10
35-
run_install: false
13+
steps:
14+
- name: Checkout repo
15+
uses: actions/checkout@v3
3616

37-
- name: Install Node.js
38-
uses: actions/setup-node@v4
39-
with:
40-
node-version: 22
41-
cache: "pnpm"
17+
- name: Setup Node
18+
uses: actions/setup-node@v3
4219

4320
- name: Install dependencies
44-
run: pnpm install
21+
uses: bahmutov/npm-install@v1
4522

46-
- name: Setup Pages
47-
id: setup_pages
48-
uses: actions/configure-pages@v5
23+
- name: Build project
24+
run: npm run build
4925

50-
- name: Restore cache
51-
uses: actions/cache@v4
52-
with:
53-
path: |
54-
.next/cache
55-
# Generate a new cache whenever packages or source files change.
56-
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/pnpm-lock.yaml') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }}
57-
# If source files changed but packages didn't, rebuild from a prior cache.
58-
restore-keys: |
59-
${{ runner.os }}-nextjs-${{ hashFiles('**/pnpm-lock.yaml') }}-
60-
61-
- name: Build with Next.js
62-
run: pnpm run build
63-
env:
64-
PAGES_BASE_PATH: ${{ steps.setup_pages.outputs.base_path }}
65-
66-
- name: Upload artifact
67-
uses: actions/upload-pages-artifact@v3
26+
- name: Upload production-ready build files
27+
uses: actions/upload-artifact@v4
6828
with:
29+
name: production-files
6930
path: ./out
7031

7132
deploy:
72-
environment:
73-
name: github-pages
74-
url: ${{ steps.deployment.outputs.page_url }}
75-
runs-on: ubuntu-latest
33+
name: Deploy
7634
needs: build
35+
runs-on: ubuntu-latest
36+
if: github.ref == 'refs/heads/main'
37+
7738
steps:
39+
- name: Download artifact
40+
uses: actions/download-artifact@v4
41+
with:
42+
name: production-files
43+
path: ./out
44+
7845
- name: Deploy to GitHub Pages
79-
id: deployment
80-
uses: actions/deploy-pages@v4
46+
uses: peaceiris/actions-gh-pages@v3
47+
with:
48+
github_token: ${{ secrets.GITHUB_TOKEN }}
49+
publish_dir: ./out

0 commit comments

Comments
 (0)