Skip to content

Commit 5aa1b61

Browse files
Merge pull request #2 from lahiruudayakumara/main
Refactor code structure for improved readability and maintainability
2 parents 578a898 + 7a94fe4 commit 5aa1b61

4 files changed

Lines changed: 4055 additions & 6472 deletions

File tree

.github/workflows/nextjs.yml

Lines changed: 30 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,75 @@
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-
#
51
name: Deploy Next.js site to Pages
62

73
on:
8-
# Runs on pushes targeting the default branch
94
push:
105
branches: ["main"]
11-
12-
# Allows you to run this workflow manually from the Actions tab
136
workflow_dispatch:
147

15-
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
168
permissions:
179
contents: read
1810
pages: write
1911
id-token: write
2012

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.
2313
concurrency:
2414
group: "pages"
2515
cancel-in-progress: false
2616

2717
jobs:
28-
# Build job
2918
build:
3019
runs-on: ubuntu-latest
20+
3121
steps:
3222
- name: Checkout
3323
uses: actions/checkout@v4
34-
- name: Detect package manager
35-
id: detect-package-manager
36-
run: |
37-
if [ -f "${{ github.workspace }}/yarn.lock" ]; then
38-
echo "manager=yarn" >> $GITHUB_OUTPUT
39-
echo "command=install" >> $GITHUB_OUTPUT
40-
echo "runner=yarn" >> $GITHUB_OUTPUT
41-
exit 0
42-
elif [ -f "${{ github.workspace }}/package.json" ]; then
43-
echo "manager=npm" >> $GITHUB_OUTPUT
44-
echo "command=ci" >> $GITHUB_OUTPUT
45-
echo "runner=npx --no-install" >> $GITHUB_OUTPUT
46-
exit 0
47-
else
48-
echo "Unable to determine package manager"
49-
exit 1
50-
fi
51-
- name: Setup Node
24+
25+
# Install pnpm
26+
- name: Setup pnpm
27+
uses: pnpm/action-setup@v4
28+
with:
29+
version: 9
30+
31+
# Setup Node with pnpm caching
32+
- name: Setup Node.js
5233
uses: actions/setup-node@v4
5334
with:
54-
node-version: "20"
55-
cache: ${{ steps.detect-package-manager.outputs.manager }}
35+
node-version: 20
36+
cache: pnpm
37+
38+
# Setup GitHub Pages
5639
- name: Setup Pages
5740
uses: actions/configure-pages@v5
5841
with:
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).
61-
#
62-
# You may remove this line if you want to manage the configuration yourself.
6342
static_site_generator: next
64-
- name: Restore cache
43+
44+
# Restore Next.js build cache
45+
- name: Restore Next.js cache
6546
uses: actions/cache@v4
6647
with:
67-
path: |
68-
.next/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.
48+
path: .next/cache
49+
key: ${{ runner.os }}-nextjs-${{ hashFiles('pnpm-lock.yaml') }}-${{ hashFiles('**/*.ts', '**/*.tsx') }}
7250
restore-keys: |
73-
${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-
51+
${{ runner.os }}-nextjs-${{ hashFiles('pnpm-lock.yaml') }}-
52+
53+
# Install deps using pnpm
7454
- name: Install dependencies
75-
run: ${{ steps.detect-package-manager.outputs.manager }} ${{ steps.detect-package-manager.outputs.command }}
55+
run: pnpm install --frozen-lockfile
56+
57+
# Build Next.js
7658
- name: Build with Next.js
77-
run: ${{ steps.detect-package-manager.outputs.runner }} next build
59+
run: pnpm next build
60+
61+
# Upload the ".next" static output folder
7862
- name: Upload artifact
7963
uses: actions/upload-pages-artifact@v3
8064
with:
8165
path: ./out
8266

83-
# Deployment job
8467
deploy:
68+
needs: build
69+
runs-on: ubuntu-latest
8570
environment:
8671
name: github-pages
8772
url: ${{ steps.deployment.outputs.page_url }}
88-
runs-on: ubuntu-latest
89-
needs: build
9073
steps:
9174
- name: Deploy to GitHub Pages
9275
id: deployment

0 commit comments

Comments
 (0)