Skip to content

Commit e134c9c

Browse files
authored
Merge pull request #4 from YosefKahlon/week5
Week5
2 parents 0e39316 + e246c67 commit e134c9c

11,013 files changed

Lines changed: 1157313 additions & 1 deletion

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: 458 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,8 @@
1111
* [Networking & SSH](./week3_practice/Networking%20&%20SSH.md)
1212

1313
# Part 4
14-
* [Advanced Git & GitHub](./week4/github_practice.md)
14+
* [Advanced Git & GitHub](./week4/github_practice.md)
15+
16+
# Part 5
17+
* [CI/CD with GitHub Action](./week5/CICD_with_GitHub_Actions.md)
18+

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+
```

week5/DISCORD_SETUP.md

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
# Discord Webhook Setup for CI/CD Notifications
2+
3+
This guide explains how to set up Discord webhook notifications for your GitHub Actions CI/CD pipeline.
4+
5+
## 🔧 Setting Up Discord Webhook
6+
7+
### Step 1: Create a Discord Webhook
8+
9+
1. Open Discord and navigate to your server
10+
2. Right-click on the channel where you want notifications
11+
3. Select **Edit Channel****Integrations****Webhooks**
12+
4. Click **Create Webhook**
13+
5. Give it a name like "CI/CD Notifications"
14+
6. Copy the webhook URL
15+
16+
### Step 2: Add Webhook to GitHub Secrets
17+
18+
1. Go to your GitHub repository
19+
2. Navigate to **Settings****Secrets and variables****Actions**
20+
3. Click **New repository secret**
21+
4. Name: `DISCORD_WEBHOOK_URL`
22+
5. Value: Paste your Discord webhook URL
23+
6. Click **Add secret**
24+
25+
## 📋 Notification Features
26+
27+
The enhanced CI/CD pipeline now includes:
28+
29+
### 🎯 Individual Job Notifications
30+
- **Success notifications** for each job completion (backend/frontend)
31+
- **Failure notifications** with direct links to logs
32+
- **Matrix strategy support** - separate notifications for each Node.js version
33+
34+
### 📊 Rich Embed Information
35+
Each notification includes:
36+
- Job name and status
37+
- Node.js version being tested
38+
- Repository and branch information
39+
- Commit hash with clickable link
40+
- Timestamp
41+
- Direct links to workflow logs (for failures)
42+
43+
### 🏆 Deployment Summary
44+
- Final summary notification after all jobs complete
45+
- Overall status (success/failure)
46+
- Individual job status breakdown
47+
- Links to full workflow run
48+
49+
## 🎨 Notification Types
50+
51+
### ✅ Success Notifications
52+
- **Green color** (3066993)
53+
- Checkmark emoji
54+
- Job completion timestamp
55+
- All relevant metadata
56+
57+
### ❌ Failure Notifications
58+
- **Red color** (15158332)
59+
- X emoji
60+
- Direct link to workflow logs
61+
- Debugging information
62+
63+
### 📈 Summary Notifications
64+
- **Color based on overall status**
65+
- Complete pipeline overview
66+
- Individual job results
67+
- Workflow run links
68+
69+
## 🔄 Workflow Structure
70+
71+
```
72+
CI Pipeline
73+
├── backend-tests (Node.js 16, 18)
74+
│ ├── Run tests
75+
│ ├── Upload artifacts
76+
│ ├── Validate deployment
77+
│ └── Send Discord notification
78+
├── frontend-tests (Node.js 16, 18)
79+
│ ├── Run tests
80+
│ ├── Upload artifacts
81+
│ ├── Validate deployment
82+
│ └── Send Discord notification
83+
└── deployment-summary
84+
└── Send overall status to Discord
85+
```
86+
87+
## 🧪 Testing the Setup
88+
89+
1. **Push a commit** to trigger the workflow
90+
2. **Check Discord** for notifications
91+
3. **Verify all matrix jobs** send individual notifications
92+
4. **Confirm summary** notification appears after all jobs complete
93+
94+
## 🛠️ Customization Options
95+
96+
### Modify Notification Content
97+
Edit the JSON payload in the workflow file to customize:
98+
- Embed titles and descriptions
99+
- Colors and emojis
100+
- Field information
101+
- Links and formatting
102+
103+
### Add More Notification Triggers
104+
You can add notifications for:
105+
- Deployment starts
106+
- Specific test failures
107+
- Performance metrics
108+
- Security scan results
109+
110+
### Channel Routing
111+
Create multiple webhooks for different channels:
112+
- Success notifications → #ci-success
113+
- Failure notifications → #ci-alerts
114+
- Summary notifications → #deployments
115+
116+
## 🔍 Troubleshooting
117+
118+
### Common Issues
119+
120+
1. **Webhook URL not working**
121+
- Verify the URL is correct in GitHub secrets
122+
- Check Discord webhook is still active
123+
124+
2. **Notifications not appearing**
125+
- Check workflow logs for curl errors
126+
- Verify JSON syntax in webhook payload
127+
128+
3. **Missing information in notifications**
129+
- Ensure all GitHub context variables are available
130+
- Check matrix strategy is properly configured
131+
132+
### Debug Commands
133+
134+
Test webhook manually:
135+
```bash
136+
curl -H "Content-Type: application/json" \
137+
-X POST \
138+
-d '{"content": "Test notification"}' \
139+
YOUR_WEBHOOK_URL
140+
```
141+
142+
## 📝 Example Notification
143+
144+
Here's what a successful backend test notification looks like:
145+
146+
```
147+
✅ Backend Tests Passed
148+
Backend tests for Node.js 18 completed successfully
149+
150+
Job: backend-tests
151+
Node.js Version: 18
152+
Repository: username/repo-name
153+
Branch: main
154+
Commit: abc123def (linked)
155+
Duration: Job completed at 2024-01-15T10:30:00Z
156+
157+
GitHub Actions
158+
```
159+
160+
## 🚀 Next Steps
161+
162+
With Discord notifications set up, you now have:
163+
- Real-time CI/CD status updates
164+
- Quick access to failure logs
165+
- Complete pipeline visibility
166+
- Team collaboration improvements
167+
168+
The pipeline will automatically notify your Discord channel for every push, pull request, or manual workflow trigger!

0 commit comments

Comments
 (0)