Skip to content

Commit 864574e

Browse files
committed
Refactor project structure and add necessary files
1 parent 4d0e25e commit 864574e

File tree

11 files changed

+1345
-0
lines changed

11 files changed

+1345
-0
lines changed

.cursorindexingignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
# Don't index SpecStory auto-save files, but allow explicit context inclusion via @ references
3+
.specstory/**

.github/rulesets/README.md

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
# 🛡️ GitHub Rulesets for Bilten
2+
3+
This directory contains GitHub Rulesets that enforce security, quality, and deployment policies for the Bilten event management platform.
4+
5+
## 📋 Overview
6+
7+
GitHub Rulesets provide a centralized way to manage repository rules and policies. They help ensure code quality, security, and compliance across the project.
8+
9+
## 🎯 Rulesets
10+
11+
### 1. Security Ruleset (`security-ruleset.json`)
12+
**Target**: Main branches (main, master, develop, release/*)
13+
**Purpose**: Enforce security policies and prevent vulnerabilities
14+
15+
**Key Features**:
16+
- 🔍 Secret scanning and push protection
17+
- 📦 Dependency review
18+
- 🔒 Code scanning with CodeQL
19+
- ✅ Required security workflows
20+
- 👥 Mandatory code reviews (2 approvals)
21+
- 🔐 Required commit signatures
22+
- 📝 Linear history requirement
23+
24+
### 2. Quality Ruleset (`quality-ruleset.json`)
25+
**Target**: All branches except hotfix and docs
26+
**Purpose**: Ensure code quality and maintainability
27+
28+
**Key Features**:
29+
- 🧪 Required CI/CD workflows
30+
- ✅ Status checks (Build, Tests, Lint, Type Check, Coverage)
31+
- 👥 Code reviews (1 approval)
32+
- 💬 Conversation resolution
33+
- 🚀 Staging deployment requirement
34+
35+
### 3. Production Ruleset (`production-ruleset.json`)
36+
**Target**: Main branches only (main, master)
37+
**Purpose**: Strict production deployment controls
38+
39+
**Key Features**:
40+
- 🚀 Production deployment workflows
41+
- 🔒 Security audit requirements
42+
- ⚡ Performance and E2E tests
43+
- 👥 Strict code reviews (3 approvals)
44+
- 🔐 Required signatures
45+
- 📝 Linear history
46+
- 💬 Conversation resolution
47+
- 🛡️ Backup verification
48+
49+
### 4. Development Ruleset (`development-ruleset.json`)
50+
**Target**: Development branches (develop, feature/*, hotfix/*)
51+
**Purpose**: Streamlined development workflow
52+
53+
**Key Features**:
54+
- 🧪 Basic CI/CD workflows
55+
- ✅ Essential status checks
56+
- 👥 Light code reviews (1 approval)
57+
- 🚀 Development deployment
58+
59+
## 🔧 Configuration
60+
61+
### Enforcement Levels
62+
- **Active**: Rules are enforced and block non-compliant changes
63+
- **Evaluate**: Rules are evaluated but don't block changes (for testing)
64+
65+
### Bypass Actors
66+
Rulesets can be bypassed by:
67+
- **Integration**: Automated systems (CI/CD)
68+
- **User**: Specific users with bypass permissions
69+
- **Never**: No bypass allowed (production rules)
70+
71+
### Conditions
72+
Rulesets apply based on:
73+
- **Branch patterns**: Which branches the rules apply to
74+
- **Repository names**: Which repositories are affected
75+
- **File paths**: Specific files or directories
76+
77+
## 🚀 Implementation
78+
79+
### 1. Enable Rulesets
80+
```bash
81+
# Using GitHub CLI
82+
gh api repos/:owner/:repo/rulesets \
83+
--method POST \
84+
--field name="Bilten Security Ruleset" \
85+
--field enforcement=active \
86+
--field target=branch \
87+
--field rules='[{"type":"secret_scanning","state":"enabled"}]'
88+
```
89+
90+
### 2. Apply to Branches
91+
```bash
92+
# Apply security ruleset to main branch
93+
gh api repos/:owner/:repo/branches/main/protection \
94+
--method PUT \
95+
--field required_status_checks='{"strict":true,"contexts":["Security Scan"]}' \
96+
--field enforce_admins=true
97+
```
98+
99+
### 3. Configure Workflows
100+
Ensure the required workflows exist:
101+
- `.github/workflows/security-scan.yml`
102+
- `.github/workflows/ci.yml`
103+
- `.github/workflows/test.yml`
104+
- `.github/workflows/lint.yml`
105+
- `.github/workflows/deploy-production.yml`
106+
107+
## 📊 Monitoring
108+
109+
### Ruleset Status
110+
Monitor ruleset compliance through:
111+
- GitHub repository insights
112+
- Pull request status checks
113+
- Security tab alerts
114+
- Dependabot notifications
115+
116+
### Metrics
117+
Track key metrics:
118+
- Ruleset bypass frequency
119+
- Failed status checks
120+
- Security scan results
121+
- Code review turnaround time
122+
123+
## 🔄 Maintenance
124+
125+
### Regular Updates
126+
- Review and update ruleset configurations monthly
127+
- Adjust enforcement levels based on team feedback
128+
- Update bypass permissions as needed
129+
- Monitor and optimize workflow performance
130+
131+
### Troubleshooting
132+
Common issues and solutions:
133+
134+
#### Ruleset Not Applied
135+
```bash
136+
# Check ruleset status
137+
gh api repos/:owner/:repo/rulesets
138+
139+
# Verify branch protection
140+
gh api repos/:owner/:repo/branches/main/protection
141+
```
142+
143+
#### Workflow Failures
144+
```bash
145+
# Check workflow runs
146+
gh run list --workflow=security-scan.yml
147+
148+
# View workflow logs
149+
gh run view <run-id> --log
150+
```
151+
152+
#### Bypass Issues
153+
```bash
154+
# Check bypass permissions
155+
gh api repos/:owner/:repo/rulesets/:ruleset-id/bypass_actors
156+
```
157+
158+
## 📚 Resources
159+
160+
- [GitHub Rulesets Documentation](https://docs.github.com/en/rest/repos/rules)
161+
- [Branch Protection API](https://docs.github.com/en/rest/branches/branch-protection)
162+
- [Security Best Practices](https://docs.github.com/en/code-security)
163+
- [Workflow Syntax](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions)
164+
165+
## 🤝 Contributing
166+
167+
When updating rulesets:
168+
1. Test changes in a development environment
169+
2. Update this documentation
170+
3. Notify the team of changes
171+
4. Monitor for any issues after deployment
172+
173+
## 📞 Support
174+
175+
For questions or issues with rulesets:
176+
1. Check the [Common Issues](Common-Issues) wiki page
177+
2. Review GitHub documentation
178+
3. Create an issue with detailed information
179+
4. Contact the development team
180+
181+
---
182+
183+
**Note**: These rulesets are designed to balance security, quality, and development velocity. Adjust configurations based on your team's needs and project requirements.

.github/rulesets/apply-rulesets.sh

Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
#!/bin/bash
2+
3+
# 🛡️ Bilten GitHub Rulesets Application Script
4+
# This script applies all rulesets to the Bilten repository
5+
6+
set -e
7+
8+
# Colors for output
9+
RED='\033[0;31m'
10+
GREEN='\033[0;32m'
11+
YELLOW='\033[1;33m'
12+
BLUE='\033[0;34m'
13+
NC='\033[0m' # No Color
14+
15+
# Configuration
16+
REPO_OWNER="iDorgham"
17+
REPO_NAME="Bilten"
18+
RULESETS_DIR=".github/rulesets"
19+
20+
echo -e "${BLUE}🛡️ Applying GitHub Rulesets for Bilten${NC}"
21+
echo "=================================================="
22+
23+
# Function to check if GitHub CLI is installed
24+
check_gh_cli() {
25+
if ! command -v gh &> /dev/null; then
26+
echo -e "${RED}❌ GitHub CLI (gh) is not installed.${NC}"
27+
echo "Please install it from: https://cli.github.com/"
28+
exit 1
29+
fi
30+
}
31+
32+
# Function to check authentication
33+
check_auth() {
34+
if ! gh auth status &> /dev/null; then
35+
echo -e "${RED}❌ Not authenticated with GitHub CLI.${NC}"
36+
echo "Please run: gh auth login"
37+
exit 1
38+
fi
39+
}
40+
41+
# Function to apply a ruleset
42+
apply_ruleset() {
43+
local ruleset_file=$1
44+
local ruleset_name=$(basename "$ruleset_file" .json)
45+
46+
echo -e "${YELLOW}📋 Applying $ruleset_name...${NC}"
47+
48+
if [ ! -f "$ruleset_file" ]; then
49+
echo -e "${RED}❌ Ruleset file not found: $ruleset_file${NC}"
50+
return 1
51+
fi
52+
53+
# Read the ruleset JSON
54+
local ruleset_content=$(cat "$ruleset_file")
55+
56+
# Apply the ruleset using GitHub CLI
57+
local response=$(gh api repos/$REPO_OWNER/$REPO_NAME/rulesets \
58+
--method POST \
59+
--input "$ruleset_file" \
60+
--silent 2>&1 || true)
61+
62+
if echo "$response" | grep -q "already exists"; then
63+
echo -e "${YELLOW}⚠️ Ruleset already exists, updating...${NC}"
64+
65+
# Get the ruleset ID
66+
local ruleset_id=$(gh api repos/$REPO_OWNER/$REPO_NAME/rulesets \
67+
--jq ".[] | select(.name == \"$(echo "$ruleset_content" | jq -r '.name')\") | .id" \
68+
--silent)
69+
70+
if [ -n "$ruleset_id" ]; then
71+
# Update existing ruleset
72+
gh api repos/$REPO_OWNER/$REPO_NAME/rulesets/$ruleset_id \
73+
--method PUT \
74+
--input "$ruleset_file" \
75+
--silent
76+
echo -e "${GREEN}✅ Updated $ruleset_name${NC}"
77+
else
78+
echo -e "${RED}❌ Could not find ruleset ID for $ruleset_name${NC}"
79+
return 1
80+
fi
81+
elif echo "$response" | grep -q "error"; then
82+
echo -e "${RED}❌ Failed to apply $ruleset_name:${NC}"
83+
echo "$response"
84+
return 1
85+
else
86+
echo -e "${GREEN}✅ Applied $ruleset_name${NC}"
87+
fi
88+
}
89+
90+
# Function to list existing rulesets
91+
list_rulesets() {
92+
echo -e "${BLUE}📋 Existing Rulesets:${NC}"
93+
gh api repos/$REPO_OWNER/$REPO_NAME/rulesets \
94+
--jq '.[] | " - \(.name) (ID: \(.id), Enforcement: \(.enforcement))"' \
95+
--silent || echo " No rulesets found"
96+
echo ""
97+
}
98+
99+
# Function to validate ruleset files
100+
validate_rulesets() {
101+
echo -e "${BLUE}🔍 Validating ruleset files...${NC}"
102+
103+
local valid=true
104+
105+
for ruleset_file in "$RULESETS_DIR"/*.json; do
106+
if [ -f "$ruleset_file" ]; then
107+
if jq empty "$ruleset_file" 2>/dev/null; then
108+
echo -e "${GREEN}✅ Valid JSON: $(basename "$ruleset_file")${NC}"
109+
else
110+
echo -e "${RED}❌ Invalid JSON: $(basename "$ruleset_file")${NC}"
111+
valid=false
112+
fi
113+
fi
114+
done
115+
116+
if [ "$valid" = false ]; then
117+
echo -e "${RED}❌ Some ruleset files have invalid JSON${NC}"
118+
exit 1
119+
fi
120+
}
121+
122+
# Function to show ruleset summary
123+
show_summary() {
124+
echo -e "${BLUE}📊 Ruleset Summary:${NC}"
125+
echo " - Security Ruleset: Enforces security policies"
126+
echo " - Quality Ruleset: Ensures code quality"
127+
echo " - Production Ruleset: Strict production controls"
128+
echo " - Development Ruleset: Streamlined development workflow"
129+
echo ""
130+
}
131+
132+
# Main execution
133+
main() {
134+
# Check prerequisites
135+
check_gh_cli
136+
check_auth
137+
138+
echo -e "${GREEN}✅ GitHub CLI is installed and authenticated${NC}"
139+
echo ""
140+
141+
# Show summary
142+
show_summary
143+
144+
# Validate ruleset files
145+
validate_rulesets
146+
echo ""
147+
148+
# List existing rulesets
149+
list_rulesets
150+
151+
# Apply each ruleset
152+
echo -e "${BLUE}🚀 Applying rulesets...${NC}"
153+
echo ""
154+
155+
local success_count=0
156+
local total_count=0
157+
158+
for ruleset_file in "$RULESETS_DIR"/*.json; do
159+
if [ -f "$ruleset_file" ] && [ "$(basename "$ruleset_file")" != "README.md" ]; then
160+
total_count=$((total_count + 1))
161+
if apply_ruleset "$ruleset_file"; then
162+
success_count=$((success_count + 1))
163+
fi
164+
echo ""
165+
fi
166+
done
167+
168+
# Final summary
169+
echo "=================================================="
170+
if [ $success_count -eq $total_count ]; then
171+
echo -e "${GREEN}🎉 Successfully applied $success_count/$total_count rulesets${NC}"
172+
else
173+
echo -e "${YELLOW}⚠️ Applied $success_count/$total_count rulesets (some failed)${NC}"
174+
fi
175+
176+
echo ""
177+
echo -e "${BLUE}📋 Next steps:${NC}"
178+
echo " 1. Review the applied rulesets in GitHub"
179+
echo " 2. Configure branch protection rules"
180+
echo " 3. Set up required workflows"
181+
echo " 4. Test the rulesets with a sample PR"
182+
echo ""
183+
echo -e "${BLUE}📚 Documentation:${NC}"
184+
echo " - Ruleset docs: .github/rulesets/README.md"
185+
echo " - GitHub docs: https://docs.github.com/en/rest/repos/rules"
186+
}
187+
188+
# Run main function
189+
main "$@"

0 commit comments

Comments
 (0)