Skip to content

Commit dc3a826

Browse files
committed
ci pipeline added
1 parent 3f326fb commit dc3a826

3 files changed

Lines changed: 283 additions & 0 deletions

File tree

.github/workflows/ci.yml

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
name: CI Pipeline
2+
3+
on:
4+
push:
5+
branches: [ main, master, develop ]
6+
pull_request:
7+
branches: [ main, master, develop ]
8+
9+
jobs:
10+
build-and-test:
11+
runs-on: ubuntu-latest
12+
13+
strategy:
14+
matrix:
15+
node-version: [18.x, 20.x]
16+
17+
steps:
18+
- name: Checkout code
19+
uses: actions/checkout@v4
20+
21+
- name: Setup Node.js ${{ matrix.node-version }}
22+
uses: actions/setup-node@v4
23+
with:
24+
node-version: ${{ matrix.node-version }}
25+
cache: 'npm'
26+
27+
- name: Install dependencies
28+
run: npm install
29+
30+
- name: Verify server file exists
31+
run: |
32+
if [ ! -f server.js ]; then
33+
echo "Error: server.js not found"
34+
exit 1
35+
fi
36+
echo "✓ server.js found"
37+
38+
- name: Verify HTML file exists
39+
run: |
40+
if [ ! -f index.html ]; then
41+
echo "Error: index.html not found"
42+
exit 1
43+
fi
44+
echo "✓ index.html found"
45+
46+
- name: Check JavaScript syntax
47+
run: node -c server.js
48+
49+
- name: Start server in background
50+
run: |
51+
node server.js &
52+
SERVER_PID=$!
53+
echo "SERVER_PID=$SERVER_PID" >> $GITHUB_ENV
54+
sleep 3
55+
56+
- name: Test server is running
57+
run: |
58+
response=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:3000)
59+
if [ "$response" -eq 200 ]; then
60+
echo "✓ Server is running and responding with status 200"
61+
else
62+
echo "✗ Server responded with status $response"
63+
exit 1
64+
fi
65+
66+
- name: Test HTML content is served
67+
run: |
68+
content=$(curl -s http://localhost:3000)
69+
if echo "$content" | grep -q "Calculator"; then
70+
echo "✓ Calculator HTML is being served correctly"
71+
else
72+
echo "✗ Calculator HTML not found in response"
73+
exit 1
74+
fi
75+
76+
- name: Stop server
77+
if: always()
78+
run: |
79+
if [ ! -z "$SERVER_PID" ]; then
80+
kill $SERVER_PID || true
81+
fi
82+
pkill -f "node server.js" || true
83+
84+
lint:
85+
runs-on: ubuntu-latest
86+
87+
steps:
88+
- name: Checkout code
89+
uses: actions/checkout@v4
90+
91+
- name: Setup Node.js
92+
uses: actions/setup-node@v4
93+
with:
94+
node-version: '20.x'
95+
96+
- name: Validate HTML
97+
run: |
98+
echo "Checking HTML structure..."
99+
if grep -q "<!DOCTYPE html>" index.html; then
100+
echo "✓ Valid HTML5 doctype found"
101+
else
102+
echo "✗ HTML5 doctype missing"
103+
exit 1
104+
fi
105+
106+
- name: Check for required HTML elements
107+
run: |
108+
required_elements=("calculator" "display" "buttons")
109+
for element in "${required_elements[@]}"; do
110+
if grep -q "$element" index.html; then
111+
echo "✓ Found: $element"
112+
else
113+
echo "✗ Missing: $element"
114+
exit 1
115+
fi
116+
done
117+
118+
- name: Validate package.json
119+
run: |
120+
if [ -f package.json ]; then
121+
node -e "JSON.parse(require('fs').readFileSync('package.json', 'utf8'))"
122+
echo "✓ package.json is valid JSON"
123+
else
124+
echo "✗ package.json not found"
125+
exit 1
126+
fi

.gitignore

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Node modules
2+
node_modules/
3+
4+
# Logs
5+
logs
6+
*.log
7+
npm-debug.log*
8+
yarn-debug.log*
9+
yarn-error.log*
10+
11+
# Runtime data
12+
pids
13+
*.pid
14+
*.seed
15+
*.pid.lock
16+
17+
# Directory for instrumented libs generated by jscoverage/JSCover
18+
lib-cov
19+
20+
# Coverage directory used by tools like istanbul
21+
coverage
22+
*.lcov
23+
24+
# nyc test coverage
25+
.nyc_output
26+
27+
# Dependency directories
28+
jspm_packages/
29+
30+
# Optional npm cache directory
31+
.npm
32+
33+
# Optional eslint cache
34+
.eslintcache
35+
36+
# Optional REPL history
37+
.node_repl_history
38+
39+
# Output of 'npm pack'
40+
*.tgz
41+
42+
# Yarn Integrity file
43+
.yarn-integrity
44+
45+
# dotenv environment variables file
46+
.env
47+
.env.test
48+
.env.local
49+
50+
# IDE
51+
.vscode/
52+
.idea/
53+
*.swp
54+
*.swo
55+
*~
56+
57+
# OS
58+
.DS_Store
59+
Thumbs.db

README.md

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# Simple Calculator
2+
3+
A simple, interactive calculator web application with a modern UI.
4+
5+
## Features
6+
7+
- ✨ Basic arithmetic operations: Addition, Subtraction, Multiplication, Division
8+
- 🎨 Modern gradient UI with smooth animations
9+
- ⌨️ Keyboard support for quick calculations
10+
- 🛡️ Error handling (e.g., division by zero)
11+
- 📱 Responsive design
12+
13+
## Quick Start
14+
15+
### Prerequisites
16+
- Node.js (v18 or higher)
17+
18+
### Installation & Running
19+
20+
1. Clone the repository
21+
```bash
22+
git clone <your-repo-url>
23+
cd windsurf-project
24+
```
25+
26+
2. Start the server
27+
```bash
28+
node server.js
29+
```
30+
31+
3. Open your browser and visit
32+
```
33+
http://localhost:3000
34+
```
35+
36+
## Usage
37+
38+
### Mouse Controls
39+
Click the calculator buttons to perform operations.
40+
41+
### Keyboard Shortcuts
42+
- **Numbers (0-9)**: Input numbers
43+
- **Operators (+, -, *, /)**: Perform operations
44+
- **Enter or =**: Calculate result
45+
- **Escape**: Clear all (AC)
46+
- **Backspace**: Delete last digit
47+
48+
## Project Structure
49+
50+
```
51+
windsurf-project/
52+
├── .github/
53+
│ └── workflows/
54+
│ └── ci.yml # GitHub Actions CI pipeline
55+
├── index.html # Calculator UI
56+
├── server.js # Node.js server
57+
├── package.json # Project configuration
58+
└── README.md # This file
59+
```
60+
61+
## CI/CD Pipeline
62+
63+
This project includes a GitHub Actions CI pipeline that:
64+
65+
### Build & Test Job
66+
- ✅ Tests on Node.js 18.x and 20.x
67+
- ✅ Verifies all required files exist
68+
- ✅ Checks JavaScript syntax
69+
- ✅ Starts the server and validates it's running
70+
- ✅ Tests HTTP responses
71+
- ✅ Verifies HTML content is served correctly
72+
73+
### Lint Job
74+
- ✅ Validates HTML5 structure
75+
- ✅ Checks for required HTML elements
76+
- ✅ Validates package.json format
77+
78+
The pipeline runs automatically on:
79+
- Push to `main`, `master`, or `develop` branches
80+
- Pull requests to these branches
81+
82+
## Development
83+
84+
To run the project locally:
85+
```bash
86+
npm start
87+
```
88+
89+
To stop the server:
90+
```bash
91+
# Press Ctrl+C in the terminal
92+
# Or kill the process
93+
pkill -f "node server.js"
94+
```
95+
96+
## License
97+
98+
ISC

0 commit comments

Comments
 (0)