Skip to content

Commit c0cc1bd

Browse files
authored
Merge pull request #5 from iddhi-sulakshana/main
Implement CI/CD Pipeline with Git Hooks 🚀
2 parents f287f90 + 4f1e042 commit c0cc1bd

8 files changed

Lines changed: 1657 additions & 300 deletions

File tree

.github/workflows/ci.yml

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main, develop]
6+
pull_request:
7+
branches: [main, develop]
8+
9+
jobs:
10+
lint-and-build:
11+
name: Lint and Build
12+
runs-on: ubuntu-latest
13+
14+
strategy:
15+
matrix:
16+
node-version: [18.x, 20.x]
17+
18+
steps:
19+
- name: Checkout code
20+
uses: actions/checkout@v4
21+
22+
- name: Setup Node.js ${{ matrix.node-version }}
23+
uses: actions/setup-node@v4
24+
with:
25+
node-version: ${{ matrix.node-version }}
26+
27+
- name: Setup pnpm
28+
uses: pnpm/action-setup@v3
29+
with:
30+
version: 8
31+
32+
- name: Get pnpm store directory
33+
shell: bash
34+
run: |
35+
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
36+
37+
- name: Cache pnpm dependencies
38+
uses: actions/cache@v4
39+
with:
40+
path: ${{ env.STORE_PATH }}
41+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
42+
restore-keys: |
43+
${{ runner.os }}-pnpm-store-
44+
45+
- name: Cache Next.js build
46+
uses: actions/cache@v4
47+
with:
48+
path: |
49+
~/.npm
50+
${{ github.workspace }}/.next/cache
51+
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/pnpm-lock.yaml') }}-${{ hashFiles('**/*.js', '**/*.jsx', '**/*.ts', '**/*.tsx') }}
52+
restore-keys: |
53+
${{ runner.os }}-nextjs-${{ hashFiles('**/pnpm-lock.yaml') }}-
54+
55+
- name: Install dependencies
56+
run: pnpm install --frozen-lockfile
57+
58+
- name: Run ESLint
59+
run: pnpm run lint
60+
61+
- name: Type check
62+
run: pnpm run type-check
63+
64+
- name: Build project
65+
run: pnpm run build
66+
env:
67+
NODE_ENV: production
68+
69+
- name: Upload build artifacts
70+
if: matrix.node-version == '20.x'
71+
uses: actions/upload-artifact@v4
72+
with:
73+
name: build-output
74+
path: .next
75+
retention-days: 7
76+
77+
code-quality:
78+
name: Code Quality Checks
79+
runs-on: ubuntu-latest
80+
81+
steps:
82+
- name: Checkout code
83+
uses: actions/checkout@v4
84+
85+
- name: Setup Node.js
86+
uses: actions/setup-node@v4
87+
with:
88+
node-version: 20.x
89+
90+
- name: Setup pnpm
91+
uses: pnpm/action-setup@v3
92+
with:
93+
version: 8
94+
95+
- name: Install dependencies
96+
run: pnpm install --frozen-lockfile
97+
98+
- name: Check for console statements
99+
run: |
100+
echo "Checking for console statements..."
101+
! git grep -n "console\." -- "*.ts" "*.tsx" "*.js" "*.jsx" || echo "Warning: Console statements found"
102+
continue-on-error: true
103+
104+
- name: Check for TODO comments
105+
run: |
106+
echo "Checking for TODO comments..."
107+
git grep -n "TODO" -- "*.ts" "*.tsx" "*.js" "*.jsx" || echo "No TODOs found"
108+
continue-on-error: true
109+
110+
status-check:
111+
name: All Checks Passed
112+
runs-on: ubuntu-latest
113+
needs: [lint-and-build, code-quality]
114+
if: always()
115+
116+
steps:
117+
- name: Check if all jobs passed
118+
if: needs.lint-and-build.result != 'success' || needs.code-quality.result != 'success'
119+
run: |
120+
echo "One or more checks failed"
121+
exit 1
122+
123+
- name: All checks passed
124+
run: echo "✅ All CI checks passed successfully!"

.husky/pre-commit

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
echo "🐥 Running pre-commit checks..."
2+
3+
echo "🔍 Linting..."
4+
npm run lint || exit 1
5+
6+
echo "✅ Linting passed!"

.husky/pre-push

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
echo "🐥 Running pre-push checks..."
2+
3+
echo "🔍 Linting..."
4+
npm run lint || exit 1
5+
6+
echo "📝 Type checking..."
7+
npm run type-check || exit 1
8+
9+
echo "🏗️ Building project..."
10+
npm run build || exit 1
11+
12+
echo "✅ All checks passed! Pushing..."

0 commit comments

Comments
 (0)