Skip to content

Commit d5ebeda

Browse files
'idempotency'
1 parent 06d3a47 commit d5ebeda

File tree

94 files changed

+7512
-8510
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+7512
-8510
lines changed

.github/README.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# GitHub Actions for Learning
2+
3+
## What is GitHub Actions?
4+
5+
GitHub Actions is a CI/CD (Continuous Integration/Continuous Deployment) system built into GitHub. Think of it as a robot that automatically runs tasks when you push code.
6+
7+
## Why learn this as a student?
8+
9+
1. **Industry Standard**: Every company uses CI/CD
10+
2. **Portfolio Value**: Shows you understand professional workflows
11+
3. **Prevents Bugs**: Catches errors before they reach main branch
12+
4. **Free Learning**: GitHub gives you free compute time to experiment
13+
14+
## The Three Workflows Explained:
15+
16+
### 1. CI Pipeline (ci.yml)
17+
18+
**Purpose**: Test your code automatically
19+
**When it runs**: Every time you push code or create a pull request
20+
**What it does**:
21+
22+
- Installs your dependencies
23+
- Runs your tests
24+
- Builds your frontend
25+
- Tests Docker builds
26+
- If ANY step fails, it marks the commit as "broken"
27+
28+
### 2. CD Pipeline (cd.yml)
29+
30+
**Purpose**: Deploy your code (COMMENTED OUT FOR LEARNING)
31+
**Status**: Not needed yet since you're not deploying anywhere
32+
**What it would do**: Push your app to a server when tests pass
33+
34+
### 3. PR Checks (pr-checks.yml)
35+
36+
**Purpose**: Validate pull requests before merging
37+
**When it runs**: When you open a pull request
38+
**What it does**: Same as CI but adds a comment to your PR
39+
40+
## For Learning Phase:
41+
42+
**Keep**: CI Pipeline - This will teach you professional testing habits
43+
**Comment Out**: CD Pipeline - You don't need deployment yet
44+
**Keep**: PR Checks - Good for team projects or practice
45+
46+
## How to use this:
47+
48+
1. Push your code to GitHub
49+
2. Go to your repo -> Actions tab
50+
3. Watch the workflows run
51+
4. See green checkmarks (pass) or red X (fail)
52+
5. Click on failed jobs to see what went wrong
53+
6. Fix the issues and push again
54+
55+
## Learning Benefits:
56+
57+
- Forces you to write tests
58+
- Teaches you Docker
59+
- Shows you industry practices
60+
- Builds good coding habits
61+
- Looks professional on your GitHub profile
62+
63+
## Simple Commands:
64+
65+
```bash
66+
# Test locally first
67+
cd backend && npm test
68+
69+
# Then push
70+
git add .
71+
git commit -m "your changes"
72+
git push
73+
74+
# GitHub Actions will automatically test your code
75+
```
76+
77+
This setup will make you a better developer by forcing good practices.

.github/workflows/cd.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
#
3+
# This file is commented out because you're in learning mode.
4+
# Uncomment everything below when you're ready to deploy to production.
5+
#
6+
# What this would do:
7+
# - Run only when CI tests pass
8+
# - Build production Docker images
9+
# - Deploy your app to a server
10+
#
11+
# For now, focus on the CI pipeline (ci.yml) which tests your code.
12+
13+
# Uncomment the lines below when ready for deployment:
14+
15+
# name: CD Pipeline
16+
# on:
17+
# push:
18+
# branches: [ main ]
19+
# jobs:
20+
# deploy:
21+
# runs-on: ubuntu-latest
22+
# steps:
23+
# - name: Checkout code
24+
# uses: actions/checkout@v4
25+
# - name: Deploy app
26+
# run: echo "Deploying to production..."

.github/workflows/ci.yml

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
name: CI Pipeline
2+
3+
# When to run this workflow
4+
on:
5+
push:
6+
branches: [main, develop]
7+
pull_request:
8+
branches: [main]
9+
10+
jobs:
11+
# Test the backend
12+
test-backend:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
# Step 1: Get the code from GitHub
17+
- name: Checkout code
18+
uses: actions/checkout@v4
19+
20+
# Step 2: Install Node.js
21+
- name: Setup Node.js
22+
uses: actions/setup-node@v4
23+
with:
24+
node-version: "18"
25+
cache: "npm"
26+
cache-dependency-path: backend/package-lock.json
27+
28+
# Step 3: Install dependencies
29+
- name: Install backend dependencies
30+
run: |
31+
cd backend
32+
npm ci
33+
34+
# Step 4: Run tests (THIS IS THE IMPORTANT PART)
35+
- name: Run backend tests
36+
run: |
37+
cd backend
38+
npm test
39+
40+
# Build and test frontend
41+
test-frontend:
42+
runs-on: ubuntu-latest
43+
44+
steps:
45+
- name: Checkout code
46+
uses: actions/checkout@v4
47+
48+
- name: Setup Node.js
49+
uses: actions/setup-node@v4
50+
with:
51+
node-version: "18"
52+
cache: "npm"
53+
cache-dependency-path: frontend/package-lock.json
54+
55+
- name: Install frontend dependencies
56+
run: |
57+
cd frontend
58+
npm ci
59+
60+
# Check for code style issues
61+
- name: Lint frontend code
62+
run: |
63+
cd frontend
64+
npm run lint
65+
66+
# Make sure frontend builds without errors
67+
- name: Build frontend
68+
run: |
69+
cd frontend
70+
npm run build
71+
72+
# Optional: Test Docker builds (comment out if you don't want this yet)
73+
docker-build:
74+
runs-on: ubuntu-latest
75+
needs: [test-backend, test-frontend]
76+
77+
steps:
78+
- name: Checkout code
79+
uses: actions/checkout@v4
80+
81+
- name: Test Docker build
82+
run: |
83+
docker-compose build
84+
echo "Docker images built successfully"

.github/workflows/pr-checks.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: PR Checks
2+
3+
# Run on pull requests
4+
on:
5+
pull_request:
6+
branches: [main, develop]
7+
8+
jobs:
9+
pr-checks:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v4
15+
16+
- name: Setup Node.js
17+
uses: actions/setup-node@v4
18+
with:
19+
node-version: "18"
20+
21+
# Check backend
22+
- name: Install and test backend
23+
run: |
24+
cd backend
25+
npm ci
26+
npm test
27+
28+
# Check frontend
29+
- name: Install and build frontend
30+
run: |
31+
cd frontend
32+
npm ci
33+
npm run lint
34+
npm run build
35+
36+
# Add a comment to PR with results
37+
- name: Comment PR
38+
if: always()
39+
uses: actions/github-script@v7
40+
with:
41+
script: |
42+
github.rest.issues.createComment({
43+
issue_number: context.issue.number,
44+
owner: context.repo.owner,
45+
repo: context.repo.repo,
46+
body: '🤖 **PR Checks Complete!**\n\n✅ Tests passed\n✅ Build successful\n✅ Ready for review!'
47+
})

backend/Dockerfile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Use Node.js official image
2+
FROM node:18-alpine
3+
4+
# Set working directory inside container
5+
WORKDIR /app
6+
7+
# Copy package.json and package-lock.json (if available)
8+
COPY package*.json ./
9+
10+
# Install dependencies
11+
RUN npm install
12+
13+
# Copy the rest of the application code
14+
COPY . .
15+
16+
# Expose the port your app runs on (adjust if different)
17+
EXPOSE 3000
18+
19+
# Command to run your application
20+
CMD ["npm", "start"]

backend/configuration/passport.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ import { configDotenv } from "dotenv";
77
import crypto from "crypto";
88

99
configDotenv();
10-
const randomPass = () => {
11-
return crypto.randomBytes(16).toString("hex");
12-
};
10+
1311

1412
passport.use(
1513
"google",

backend/configuration/s3Config.js

Lines changed: 0 additions & 52 deletions
This file was deleted.

backend/configuration/s3Setup.js

Lines changed: 10 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,16 @@
1-
import {
2-
S3Client,
3-
CreateBucketCommand,
4-
HeadBucketCommand,
5-
} from "@aws-sdk/client-s3";
1+
import { S3Client } from "@aws-sdk/client-s3";
2+
import dotenv from "dotenv";
3+
dotenv.config();
4+
5+
const AWS_REGION = process.env.AWS_REGION || "ap-south-1";
6+
const BUCKET_NAME = process.env.AWS_BUCKET_NAME || "vermaco123";
67

78
const s3Client = new S3Client({
8-
endpoint: process.env.AWS_ENDPOINT_URL || "http://localhost:4566",
9+
region: AWS_REGION,
910
credentials: {
10-
accessKeyId: process.env.AWS_ACCESS_KEY_ID || "test",
11-
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY || "test",
11+
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
12+
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
1213
},
13-
region: process.env.AWS_REGION || "us-east-1",
14-
forcePathStyle: true, //!needed for localstack
1514
});
1615

17-
const BUCKET_NAME = process.env.S3_BUCKET_NAME || "employee-documents";
18-
19-
async function setupS3() {
20-
try {
21-
await s3Client.send(new HeadBucketCommand({ Bucket: BUCKET_NAME }));
22-
console.log(`Bucket ${BUCKET_NAME} already exists.`);
23-
// Bucket exists
24-
//!this means that the bucket already exists
25-
} catch (error) {
26-
if (error.name === "NotFound" || error.$metadata?.httpStatusCode === 404) {
27-
await s3Client.send(new CreateBucketCommand({ Bucket: BUCKET_NAME }));
28-
console.log(`Bucket ${BUCKET_NAME} created successfully.`);
29-
// Bucket created
30-
//!this means the bucket does not exist, so we create it
31-
} else {
32-
console.error("S3 setup failed:", error.message);
33-
// Make sure LocalStack is running
34-
}
35-
}
36-
}
37-
38-
setupS3();
16+
export { s3Client, BUCKET_NAME };

0 commit comments

Comments
 (0)