Skip to content

Commit 1fdefc6

Browse files
committed
add ci
1 parent eeabadc commit 1fdefc6

11,009 files changed

Lines changed: 1156425 additions & 0 deletions

File tree

Some content is hidden

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

.github/workflows/ci.yml

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
name: CI Workflow
2+
3+
on:
4+
push:
5+
branches:
6+
- week5
7+
- main
8+
pull_request:
9+
branches:
10+
- main
11+
workflow_dispatch:
12+
13+
14+
15+
jobs:
16+
backend-tests:
17+
name: Backend Tests (Node.js ${{ matrix.node-version }})
18+
runs-on: ubuntu-latest
19+
20+
strategy:
21+
matrix:
22+
node-version: [14, 16, 18]
23+
24+
steps:
25+
- name: Checkout code
26+
uses: actions/checkout@v4
27+
28+
- name: Set up Node.js ${{ matrix.node-version }}
29+
uses: actions/setup-node@v4
30+
with:
31+
node-version: ${{ matrix.node-version }}
32+
cache: 'npm'
33+
cache-dependency-path: week5/backend/package-lock.json
34+
35+
- name: Install backend dependencies
36+
run: |
37+
cd week5/backend
38+
npm ci
39+
40+
- name: Run backend tests
41+
run: |
42+
cd week5/backend
43+
npm test
44+
45+
- name: Start backend server and health check
46+
run: |
47+
cd week5/backend
48+
npm start &
49+
sleep 5
50+
curl -f http://localhost:3000/health
51+
curl -f http://localhost:3000/api/users
52+
pkill -f "node server.js"
53+
54+
frontend-tests:
55+
name: Frontend Tests (Node.js ${{ matrix.node-version }})
56+
runs-on: ubuntu-latest
57+
58+
strategy:
59+
matrix:
60+
node-version: [14, 16, 18]
61+
62+
steps:
63+
- name: Checkout code
64+
uses: actions/checkout@v4
65+
66+
- name: Set up Node.js ${{ matrix.node-version }}
67+
uses: actions/setup-node@v4
68+
with:
69+
node-version: ${{ matrix.node-version }}
70+
cache: 'npm'
71+
cache-dependency-path: week5/frontend/package-lock.json
72+
73+
- name: Install frontend dependencies
74+
run: |
75+
cd week5/frontend
76+
npm ci
77+
78+
- name: Run frontend tests
79+
run: |
80+
cd week5/frontend
81+
npm test
82+
83+
integration-tests:
84+
name: Integration Tests
85+
runs-on: ubuntu-latest
86+
needs: [backend-tests, frontend-tests]
87+
88+
steps:
89+
- name: Checkout code
90+
uses: actions/checkout@v4
91+
92+
- name: Set up Node.js
93+
uses: actions/setup-node@v4
94+
with:
95+
node-version: '18'
96+
cache: 'npm'
97+
98+
- name: Install all dependencies
99+
run: |
100+
cd week5/backend && npm ci
101+
cd ../frontend && npm ci
102+
103+
- name: Start backend server
104+
run: |
105+
cd week5/backend
106+
npm start &
107+
sleep 5
108+
109+
- name: Verify API endpoints
110+
run: |
111+
# Test all API endpoints
112+
curl -f http://localhost:3000/
113+
curl -f http://localhost:3000/health
114+
curl -f http://localhost:3000/api/users
115+
116+
# Test creating a user
117+
curl -f -X POST http://localhost:3000/api/users \
118+
-H "Content-Type: application/json" \
119+
-d '{"name":"Test User","email":"test@example.com"}'
120+
121+
# Test getting the created user
122+
curl -f http://localhost:3000/api/users/4
123+
124+
125+

week5/CICD_with_GitHub_Actions.md

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# CI/CD with GitHub Actions
2+
3+
## Questions and Answers
4+
5+
### What is a GitHub Action?
6+
7+
A **GitHub Action** is a custom application that performs a frequently repeated task in your software development workflow. GitHub Actions are the individual units of functionality that can be combined to create workflows. They can be:
8+
9+
- **Pre-built actions** from the GitHub Marketplace (created by GitHub or the community)
10+
- **Custom actions** that you create yourself
11+
- **Docker container actions** or **JavaScript actions**
12+
13+
Actions can perform tasks like:
14+
- Building and testing code
15+
- Deploying applications
16+
- Sending notifications
17+
- Interacting with APIs
18+
- Managing issues and pull requests
19+
20+
**Where do GitHub Actions run?**
21+
GitHub Actions run on **GitHub-hosted runners** (virtual machines in the cloud), not on your local machine. GitHub provides runners with different operating systems:
22+
- **Ubuntu Linux** (most common)
23+
- **Windows Server**
24+
- **macOS**
25+
26+
You can also use **self-hosted runners** if you need to run actions on your own infrastructure for security, performance, or specific environment requirements.
27+
28+
### What is the difference between a job and a step?
29+
30+
**Job:**
31+
- A **job** is a set of steps that execute on the same runner (virtual machine)
32+
- Jobs run in parallel by default (unless dependencies are specified)
33+
- Each job runs in a fresh virtual environment
34+
- Jobs can have dependencies on other jobs using the `needs` keyword
35+
- Example: You might have separate jobs for "build", "test", and "deploy"
36+
37+
**Step:**
38+
- A **step** is an individual task within a job
39+
- Steps run sequentially within a job
40+
- Each step can run commands or use actions
41+
- Steps share the same runner environment and file system
42+
- Steps can pass data between each other within the same job
43+
44+
**Hierarchy:**
45+
```
46+
Workflow
47+
├── Job 1
48+
│ ├── Step 1
49+
│ ├── Step 2
50+
│ └── Step 3
51+
└── Job 2
52+
├── Step 1
53+
└── Step 2
54+
```
55+
56+
### What triggers a workflow?
57+
58+
GitHub workflows can be triggered by various **events**:
59+
60+
**1. Push Events:**
61+
- `push` - When code is pushed to specific branches
62+
- `pull_request` - When a pull request is opened, updated, or closed
63+
64+
**2. Scheduled Events:**
65+
- `schedule` - Run workflows on a schedule using cron syntax
66+
- Example: `cron: '0 0 * * *'` (daily at midnight)
67+
68+
**3. Manual Events:**
69+
- `workflow_dispatch` - Manually trigger workflows from GitHub UI
70+
- `repository_dispatch` - Trigger via API calls
71+
72+
**4. Repository Events:**
73+
- `issues` - When issues are created, edited, etc.
74+
- `release` - When releases are published
75+
- `fork` - When the repository is forked
76+
77+
**5. External Events:**
78+
- `webhook` - External webhooks
79+
- API calls to trigger workflows
80+
81+
**Example trigger configuration:**
82+
```yaml
83+
on:
84+
push:
85+
branches: [ main, develop ]
86+
pull_request:
87+
branches: [ main ]
88+
schedule:
89+
- cron: '0 2 * * 1' # Every Monday at 2 AM
90+
workflow_dispatch: # Manual trigger
91+
```

0 commit comments

Comments
 (0)