Skip to content

Commit 777b257

Browse files
committed
Add CI/CD pipeline documentation and implement validation scripts for documentation structure and problem directories
1 parent 0964010 commit 777b257

File tree

9 files changed

+1172
-0
lines changed

9 files changed

+1172
-0
lines changed

.github/README.md

Lines changed: 207 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,207 @@
1+
# 🚀 CI/CD Pipeline Documentation
2+
3+
This directory contains the automated CI/CD pipeline for the LeetCode Problem Solutions repository. The pipeline automatically updates all documentation files when new problems are added.
4+
5+
## 📁 Structure
6+
7+
```
8+
.github/
9+
├── workflows/
10+
│ ├── auto-update-docs.yml # Main auto-update workflow
11+
│ ├── validate-docs.yml # Documentation validation
12+
│ └── manual-update.yml # Manual update trigger
13+
└── scripts/
14+
├── update_documentation.py # Main documentation updater
15+
├── validate_documentation.py # Documentation validator
16+
├── check_links.py # Link checker
17+
├── validate_problems.py # Problem structure validator
18+
└── manual_update.py # Manual update script
19+
```
20+
21+
## 🔄 Workflows
22+
23+
### 1. Auto-Update Documentation (`auto-update-docs.yml`)
24+
25+
**Triggers:**
26+
- Push to `main`/`master` branch with changes in problem directories
27+
- Pull requests affecting problem directories
28+
29+
**Actions:**
30+
- Detects new/modified problems
31+
- Scans problem metadata (title, difficulty, topics, languages)
32+
- Updates all documentation files:
33+
- `README.md` - Repository structure and problem tables
34+
- `INDEX.md` - Problem indices and categorization
35+
- `PERFORMANCE_ANALYSIS.md` - Performance metrics and analysis
36+
- `InterviewPreparation.md` - Interview references and examples
37+
- Commits changes automatically
38+
39+
### 2. Documentation Validation (`validate-docs.yml`)
40+
41+
**Triggers:**
42+
- All pushes and pull requests
43+
44+
**Actions:**
45+
- Validates documentation structure
46+
- Checks for broken internal links
47+
- Validates problem directory structure
48+
- Ensures markdown syntax correctness
49+
50+
### 3. Manual Update (`manual-update.yml`)
51+
52+
**Triggers:**
53+
- Manual workflow dispatch
54+
55+
**Options:**
56+
- Update type: `all`, `readme`, `index`, `performance`, `interview-prep`
57+
- Force update: Update even if no changes detected
58+
59+
## 🛠️ Scripts
60+
61+
### `update_documentation.py`
62+
Main documentation updater that:
63+
- Scans all problem directories
64+
- Extracts metadata from `Problem.md` files
65+
- Detects available solution languages
66+
- Updates all documentation files with new content
67+
68+
### `validate_documentation.py`
69+
Validates documentation structure:
70+
- Checks for required sections
71+
- Validates markdown format
72+
- Ensures consistency across files
73+
74+
### `check_links.py`
75+
Validates internal links:
76+
- Finds broken relative links
77+
- Skips external URLs
78+
- Reports missing referenced files
79+
80+
### `validate_problems.py`
81+
Validates problem directory structure:
82+
- Ensures `Problem.md` exists
83+
- Checks for solution files
84+
- Validates problem metadata format
85+
86+
## 🚀 How It Works
87+
88+
### Automatic Updates
89+
90+
1. **Detection**: When you push changes to problem directories, the workflow detects modified files
91+
2. **Scanning**: The script scans all problem directories and extracts metadata
92+
3. **Update**: All documentation files are updated with new problem information
93+
4. **Commit**: Changes are automatically committed with a descriptive message
94+
95+
### Adding New Problems
96+
97+
When you add a new problem:
98+
99+
1. Create the problem directory (e.g., `Daily_Problems/DailyProblem7/`)
100+
2. Add `Problem.md` with proper format:
101+
```markdown
102+
# 1234. Problem Title
103+
104+
**Difficulty**: Medium
105+
**Topics**: Array, Dynamic Programming
106+
107+
[Problem description...]
108+
```
109+
3. Add solution files (`InCPP.cpp`, `InJava.java`, etc.)
110+
4. Push to repository
111+
5. CI/CD automatically updates all documentation! 🎉
112+
113+
### Manual Updates
114+
115+
If you need to manually trigger updates:
116+
117+
1. Go to GitHub Actions tab
118+
2. Select "Manual Documentation Update"
119+
3. Click "Run workflow"
120+
4. Choose update type and options
121+
5. Click "Run workflow" button
122+
123+
## 📊 Monitoring
124+
125+
### GitHub Actions Dashboard
126+
- View workflow runs and status
127+
- Check validation results
128+
- Monitor automatic updates
129+
130+
### Workflow Summaries
131+
Each workflow provides detailed summaries:
132+
- Files changed
133+
- Problems detected
134+
- Validation results
135+
- Performance reports
136+
137+
## 🔧 Configuration
138+
139+
### Environment Variables
140+
- `GITHUB_TOKEN`: Automatically provided by GitHub Actions
141+
- No additional secrets required
142+
143+
### Permissions
144+
Workflows have:
145+
- `contents: write` - To commit documentation updates
146+
- `pull-requests: write` - To comment on PRs
147+
148+
## 🛡️ Error Handling
149+
150+
### Validation Failures
151+
- Broken links stop the workflow
152+
- Missing required files generate warnings
153+
- Structure violations are reported
154+
155+
### Update Failures
156+
- Failed updates are logged
157+
- Manual intervention may be required
158+
- Rollback procedures available
159+
160+
## 🎯 Best Practices
161+
162+
### Problem Structure
163+
Ensure each problem directory has:
164+
- `Problem.md` with proper format
165+
- At least one solution file
166+
- Consistent naming conventions
167+
168+
### Commit Messages
169+
Automatic commits include:
170+
- Changed files list
171+
- Problem numbers affected
172+
- Timestamp and workflow info
173+
174+
### Review Process
175+
- Validate changes before pushing
176+
- Review auto-generated documentation
177+
- Monitor workflow results
178+
179+
## 🚀 Benefits
180+
181+
### Automation
182+
- ✅ Zero manual documentation maintenance
183+
- ✅ Consistent formatting across all files
184+
- ✅ Real-time updates when problems are added
185+
186+
### Quality Assurance
187+
- ✅ Link validation prevents broken references
188+
- ✅ Structure validation ensures consistency
189+
- ✅ Automatic error detection and reporting
190+
191+
### Developer Experience
192+
- ✅ Focus on problem-solving, not documentation
193+
- ✅ Immediate feedback on changes
194+
- ✅ Professional-quality repository maintenance
195+
196+
## 🔮 Future Enhancements
197+
198+
Planned improvements:
199+
- Performance benchmark automation
200+
- Test case validation
201+
- Solution correctness checking
202+
- Multi-language compilation testing
203+
- Advanced metrics and analytics
204+
205+
---
206+
207+
**Happy Coding!** 🎉 The CI/CD pipeline ensures your repository stays perfectly organized and up-to-date automatically!

.github/scripts/check_links.py

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Link Checker for Documentation
4+
==============================
5+
6+
Checks for broken internal links in all markdown files.
7+
"""
8+
9+
import os
10+
import re
11+
from pathlib import Path
12+
import logging
13+
14+
logging.basicConfig(level=logging.INFO)
15+
logger = logging.getLogger(__name__)
16+
17+
class LinkChecker:
18+
def __init__(self):
19+
self.root_path = Path(".")
20+
self.broken_links = []
21+
22+
def check_file_links(self, file_path: Path) -> None:
23+
"""Check all links in a markdown file"""
24+
if not file_path.exists():
25+
return
26+
27+
content = file_path.read_text(encoding='utf-8')
28+
29+
# Find all markdown links [text](url)
30+
link_pattern = r'\[([^\]]+)\]\(([^)]+)\)'
31+
links = re.findall(link_pattern, content)
32+
33+
for link_text, link_url in links:
34+
# Skip external links (http/https)
35+
if link_url.startswith(('http://', 'https://', 'mailto:')):
36+
continue
37+
38+
# Skip anchors
39+
if link_url.startswith('#'):
40+
continue
41+
42+
# Check if file exists
43+
target_path = file_path.parent / link_url
44+
if not target_path.exists():
45+
# Try relative to root
46+
target_path = self.root_path / link_url
47+
if not target_path.exists():
48+
self.broken_links.append({
49+
'file': str(file_path),
50+
'link_text': link_text,
51+
'link_url': link_url
52+
})
53+
54+
def run(self) -> int:
55+
"""Check all markdown files for broken links"""
56+
logger.info("Starting link validation...")
57+
58+
# Check all markdown files
59+
md_files = list(self.root_path.glob("*.md"))
60+
md_files.extend(self.root_path.glob("**/*.md"))
61+
62+
for md_file in md_files:
63+
# Skip files in .git directory
64+
if '.git' in str(md_file):
65+
continue
66+
self.check_file_links(md_file)
67+
68+
# Report results
69+
if self.broken_links:
70+
logger.error(f"Found {len(self.broken_links)} broken links:")
71+
for link in self.broken_links:
72+
logger.error(f" ❌ {link['file']}: [{link['link_text']}]({link['link_url']})")
73+
else:
74+
logger.info("✅ All links are valid!")
75+
76+
return len(self.broken_links)
77+
78+
if __name__ == "__main__":
79+
checker = LinkChecker()
80+
exit_code = checker.run()
81+
exit(exit_code)

.github/scripts/manual_update.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Manual Documentation Update Script
4+
=================================
5+
6+
Allows manual triggering of documentation updates with specific options.
7+
"""
8+
9+
import argparse
10+
import sys
11+
from pathlib import Path
12+
13+
# Import the main updater
14+
sys.path.append(str(Path(__file__).parent))
15+
from update_documentation import DocumentationUpdater
16+
17+
class ManualUpdater(DocumentationUpdater):
18+
def __init__(self, update_type: str, force: bool):
19+
super().__init__()
20+
self.update_type = update_type
21+
self.force = force
22+
23+
def run(self) -> None:
24+
"""Run manual update based on specified type"""
25+
print(f"Starting manual documentation update (type: {self.update_type}, force: {self.force})")
26+
27+
self.scan_problems()
28+
29+
if not self.force and not self.daily_problems and not self.regular_problems:
30+
print("No problems found and force=False, skipping update")
31+
return
32+
33+
if self.update_type in ['all', 'readme']:
34+
print("Updating README.md...")
35+
self.update_readme()
36+
37+
if self.update_type in ['all', 'index']:
38+
print("Updating INDEX.md...")
39+
self.update_index()
40+
41+
if self.update_type in ['all', 'performance']:
42+
print("Updating PERFORMANCE_ANALYSIS.md...")
43+
self.update_performance_analysis()
44+
45+
if self.update_type in ['all', 'interview-prep']:
46+
print("Updating InterviewPreparation.md...")
47+
self.update_interview_preparation()
48+
49+
print("Manual documentation update completed!")
50+
51+
def main():
52+
parser = argparse.ArgumentParser(description='Manual documentation updater')
53+
parser.add_argument('--type', choices=['all', 'readme', 'index', 'performance', 'interview-prep'],
54+
default='all', help='Type of update to perform')
55+
parser.add_argument('--force', type=bool, default=False,
56+
help='Force update even if no changes detected')
57+
58+
args = parser.parse_args()
59+
60+
updater = ManualUpdater(args.type, args.force)
61+
updater.run()
62+
63+
if __name__ == "__main__":
64+
main()

0 commit comments

Comments
 (0)