Skip to content

Commit 54f857d

Browse files
authored
Update nextjs.yml
1 parent 19f9c23 commit 54f857d

File tree

1 file changed

+50
-45
lines changed

1 file changed

+50
-45
lines changed

.github/workflows/nextjs.yml

Lines changed: 50 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,67 @@
1-
name: Check NextJs build
1+
# Workflow for deploying static content to GitHub Pages
2+
name: Deploy static content to GitHub Pages
23

34
on:
4-
# Runs on pushes targeting the default branch
5+
# Trigger workflow on push to the main branch
56
push:
6-
branches: ["main"]
7-
8-
# Runs on any open or reopened pull request
9-
pull_request:
10-
types: [opened, reopened] # you can change this according to https://docs.github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs/triggering-a-workflow#using-multiple-events
7+
branches:
8+
- main
119

12-
# Allows you to run this workflow manually from the Actions tab
10+
# Allow manual trigger of the workflow through the Actions tab
1311
workflow_dispatch:
1412

15-
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
1613
permissions:
14+
# Set required permissions for deployment
1715
contents: read
16+
pages: write
1817
id-token: write
1918

19+
concurrency:
20+
# Allow only one deployment at a time, cancel in-progress deployments
21+
group: 'github-pages-deployment'
22+
cancel-in-progress: true
23+
2024
jobs:
21-
# Build job
22-
build:
25+
deploy:
26+
# Define the target deployment environment
27+
environment:
28+
name: github-pages
29+
url: ${{ steps.deployment.outputs.page_url }}
2330
runs-on: ubuntu-latest
31+
2432
steps:
25-
- name: Checkout
33+
# Step 1: Check out the repository
34+
- name: Check out the code
2635
uses: actions/checkout@v4
27-
- name: Detect package manager
28-
id: detect-package-manager
29-
run: |
30-
if [ -f "${{ github.workspace }}/yarn.lock" ]; then
31-
echo "manager=yarn" >> $GITHUB_OUTPUT
32-
echo "command=install" >> $GITHUB_OUTPUT
33-
echo "runner=yarn" >> $GITHUB_OUTPUT
34-
exit 0
35-
elif [ -f "${{ github.workspace }}/package.json" ]; then
36-
echo "manager=npm" >> $GITHUB_OUTPUT
37-
echo "command=ci" >> $GITHUB_OUTPUT
38-
echo "runner=npx --no-install" >> $GITHUB_OUTPUT
39-
exit 0
40-
else
41-
echo "Unable to determine package manager" >&2
42-
exit 1
43-
fi
44-
- name: Setup Node
45-
uses: actions/setup-node@v3
4636
with:
47-
node-version: "22"
48-
cache: ${{ steps.detect-package-manager.outputs.manager }}
49-
- name: Restore cache
50-
uses: actions/cache@v4
37+
fetch-depth: 1
38+
39+
# Step 2: Set up Node.js environment
40+
- name: Set up Node.js
41+
uses: actions/setup-node@v4
5142
with:
52-
path: |
53-
.next/cache
54-
# Generate a new cache whenever packages or source files change.
55-
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }}
56-
# If source files changed but packages didn't, rebuild from a prior cache.
57-
restore-keys: |
58-
${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-
59-
- name: Install dependencies
60-
run: ${{ steps.detect-package-manager.outputs.manager }} ${{ steps.detect-package-manager.outputs.command }}
61-
- name: Build with Next.js
43+
node-version: 20
44+
cache: npm
45+
46+
# Step 3: Install dependencies
47+
- name: Install project dependencies
48+
run: npm ci
49+
50+
# Step 4: Build the project
51+
- name: Build the project
6252
run: npm run build
53+
54+
# Step 5: Configure GitHub Pages
55+
- name: Configure GitHub Pages
56+
uses: actions/configure-pages@v4
57+
58+
# Step 6: Upload build artifacts
59+
- name: Upload build artifacts
60+
uses: actions/upload-pages-artifact@v3
61+
with:
62+
path: ./dist
63+
64+
# Step 7: Deploy to GitHub Pages
65+
- name: Deploy to GitHub Pages
66+
id: deployment
67+
uses: actions/deploy-pages@v4

0 commit comments

Comments
 (0)