Skip to content

Commit cdf140d

Browse files
committed
Update deploy.yml and nextjs.yml for generate manifest
1 parent b3f75f9 commit cdf140d

File tree

2 files changed

+45
-69
lines changed

2 files changed

+45
-69
lines changed

.github/workflows/deploy.yml

Lines changed: 33 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,116 +1,96 @@
1-
# GitHub Actions workflow to deploy a Next.js site to GitHub Pages
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+
#
25
name: Deploy Next.js site to Pages
36

47
on:
5-
# Trigger the workflow on push to the "main" branch
8+
# Runs on pushes targeting the default branch
69
push:
7-
branches: ["main"]
10+
branches: ["*"]
811

9-
# Allow manual runs from the Actions tab
12+
# Allows you to run this workflow manually from the Actions tab
1013
workflow_dispatch:
1114

12-
# Set permissions for GitHub Pages deployment
15+
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
1316
permissions:
1417
contents: read
1518
pages: write
1619
id-token: write
1720

18-
# Allow only one deployment at a time, but do not cancel in-progress deployments
21+
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
22+
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
1923
concurrency:
2024
group: "pages"
2125
cancel-in-progress: false
2226

2327
jobs:
24-
# Build Job: Compiles and prepares the Next.js app for deployment
28+
# Build job
2529
build:
2630
runs-on: ubuntu-latest
27-
2831
steps:
29-
# Step 1: Checkout the repository
30-
- name: Checkout repository
32+
- name: Checkout
3133
uses: actions/checkout@v4
32-
33-
# Step 2: Detect the package manager (npm or yarn)
3434
- name: Detect package manager
3535
id: detect-package-manager
3636
run: |
3737
if [ -f "${{ github.workspace }}/yarn.lock" ]; then
3838
echo "manager=yarn" >> $GITHUB_OUTPUT
3939
echo "command=install" >> $GITHUB_OUTPUT
4040
echo "runner=yarn" >> $GITHUB_OUTPUT
41+
exit 0
4142
elif [ -f "${{ github.workspace }}/package.json" ]; then
4243
echo "manager=npm" >> $GITHUB_OUTPUT
4344
echo "command=ci" >> $GITHUB_OUTPUT
4445
echo "runner=npx --no-install" >> $GITHUB_OUTPUT
46+
exit 0
4547
else
4648
echo "Unable to determine package manager"
4749
exit 1
4850
fi
49-
50-
# Step 3: Setup Node.js environment
51-
- name: Setup Node.js
51+
- name: Setup Node
5252
uses: actions/setup-node@v4
5353
with:
5454
node-version: "20"
5555
cache: ${{ steps.detect-package-manager.outputs.manager }}
56-
57-
# Step 4: Install project dependencies
58-
- name: Install dependencies
59-
run: ${{ steps.detect-package-manager.outputs.manager }} ${{ steps.detect-package-manager.outputs.command }}
60-
61-
# Step 5: Install ts-node
62-
- name: Install ts-node
63-
run: npm install -g ts-node
64-
65-
# Step 6: Run script to generate the manifest file for Next.js
66-
- name: Run manifest generation script
67-
run: ts-node scripts/generateManifest.mjs
68-
# Step 7: Debugging - Check if manifest.json exists
69-
70-
- name: Debug Manifest Generation
71-
run: |
72-
ls -l ./public/
73-
cat ./public/manifest.json || echo "❌ Manifest not found"
74-
75-
# Step 7: Configure GitHub Pages for Next.js
7656
- name: Setup Pages
7757
uses: actions/configure-pages@v5
7858
with:
79-
# Automatically configures basePath and disables image optimization
80-
static_site_generator: next
59+
# Automatically inject basePath in your Next.js configuration file and disable
60+
# server side image optimization (https://nextjs.org/docs/api-reference/next/image#unoptimized).
8161

82-
# Step 8: Restore Next.js build cache to speed up builds
83-
- name: Restore Next.js cache
62+
# You may remove this line if you want to manage the configuration yourself.
63+
static_site_generator: next
64+
- name: Restore cache
8465
uses: actions/cache@v4
8566
with:
8667
path: |
8768
.next/cache
88-
# Generate cache key based on package files and source code
89-
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }}
90-
# If cache key changes, try restoring from a previous cache
69+
# Generate a new cache whenever packages or source files change.
70+
key: ${{ runner.os }}-nextjs-${{ hashFiles('*/package-lock.json', '/yarn.lock') }}-${{ hashFiles('.[jt]s', '*.[jt]sx') }}
71+
# If source files changed but packages didn't, rebuild from a prior cache.
9172
restore-keys: |
92-
${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-
93-
94-
# Step 9: Build the Next.js project
73+
${{ runner.os }}-nextjs-${{ hashFiles('*/package-lock.json', '*/yarn.lock') }}-
74+
- name: Install dependencies
75+
run: ${{ steps.detect-package-manager.outputs.manager }} ${{ steps.detect-package-manager.outputs.command }}
76+
- name: Install ts-node
77+
run: npm install -g ts-node
78+
- name: Run manifest generation script
79+
run: ts-node scripts/generateManifest.mjs
9580
- name: Build with Next.js
9681
run: ${{ steps.detect-package-manager.outputs.runner }} next build
97-
98-
# Step 10: Upload the built site as an artifact for deployment
99-
- name: Upload build artifacts
82+
- name: Upload artifact
10083
uses: actions/upload-pages-artifact@v3
10184
with:
10285
path: ./out
103-
104-
# Deployment Job: Deploys the built site to GitHub Pages
86+
# Deployment job
10587
deploy:
10688
environment:
10789
name: github-pages
10890
url: ${{ steps.deployment.outputs.page_url }}
10991
runs-on: ubuntu-latest
11092
needs: build
111-
11293
steps:
113-
# Step 11: Deploy the site to GitHub Pages
11494
- name: Deploy to GitHub Pages
11595
id: deployment
116-
uses: actions/deploy-pages@v4
96+
uses: actions/deploy-pages@v4

.github/workflows/nextjs.yml

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ name: Deploy Next.js site to Pages
77
on:
88
# Runs on pushes targeting the default branch
99
push:
10-
branches: ["main"]
10+
branches: ["*"]
1111

1212
# Allows you to run this workflow manually from the Actions tab
1313
workflow_dispatch:
@@ -31,7 +31,6 @@ jobs:
3131
steps:
3232
- name: Checkout
3333
uses: actions/checkout@v4
34-
3534
- name: Detect package manager
3635
id: detect-package-manager
3736
run: |
@@ -49,45 +48,42 @@ jobs:
4948
echo "Unable to determine package manager"
5049
exit 1
5150
fi
52-
5351
- name: Setup Node
5452
uses: actions/setup-node@v4
5553
with:
5654
node-version: "20"
5755
cache: ${{ steps.detect-package-manager.outputs.manager }}
58-
5956
- name: Setup Pages
6057
uses: actions/configure-pages@v5
6158
with:
62-
static_site_generator: next
59+
# Automatically inject basePath in your Next.js configuration file and disable
60+
# server side image optimization (https://nextjs.org/docs/api-reference/next/image#unoptimized).
6361

62+
# You may remove this line if you want to manage the configuration yourself.
63+
static_site_generator: next
6464
- name: Restore cache
6565
uses: actions/cache@v4
6666
with:
6767
path: |
6868
.next/cache
69-
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }}
69+
# Generate a new cache whenever packages or source files change.
70+
key: ${{ runner.os }}-nextjs-${{ hashFiles('*/package-lock.json', '/yarn.lock') }}-${{ hashFiles('.[jt]s', '*.[jt]sx') }}
71+
# If source files changed but packages didn't, rebuild from a prior cache.
7072
restore-keys: |
71-
${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-
72-
73+
${{ runner.os }}-nextjs-${{ hashFiles('*/package-lock.json', '*/yarn.lock') }}-
7374
- name: Install dependencies
7475
run: ${{ steps.detect-package-manager.outputs.manager }} ${{ steps.detect-package-manager.outputs.command }}
75-
7676
- name: Install ts-node
77-
run: npm install -g ts-node
78-
77+
run: npm install -g ts-node
7978
- name: Generate Manifest
8079
run: ts-node scripts/generateManifest.mjs
81-
8280
- name: Build with Next.js
8381
run: ${{ steps.detect-package-manager.outputs.runner }} next build
84-
8582
- name: Upload artifact
8683
uses: actions/upload-pages-artifact@v3
8784
with:
8885
path: ./out
89-
90-
# Deployment job
86+
# Deployment job
9187
deploy:
9288
environment:
9389
name: github-pages
@@ -97,4 +93,4 @@ jobs:
9793
steps:
9894
- name: Deploy to GitHub Pages
9995
id: deployment
100-
uses: actions/deploy-pages@v4
96+
uses: actions/deploy-pages@v4

0 commit comments

Comments
 (0)