1+ # setup-dev-branch.ps1 - AI Token Crusher Dev Branch Setup
2+
3+ $Token = " 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"
4+ $Owner = " totalbrain"
5+ $Repo = " TokenOptimizer"
6+
7+ $Headers = @ {
8+ Authorization = " Bearer $Token "
9+ Accept = " application/vnd.github+json"
10+ }
11+
12+ Write-Host " Creating dev branch setup..." - ForegroundColor Cyan
13+
14+ # 1. Create dev branch from main
15+ git checkout main
16+ git pull origin main
17+ git checkout - b dev
18+ git push origin dev
19+
20+ # 2. Set dev as default branch
21+ Invoke-RestMethod - Method Patch - Uri " https://api.github.com/repos/$Owner /$Repo " - Headers $Headers - Body (@ {
22+ default_branch = " dev"
23+ } | ConvertTo-Json )
24+
25+ # 3. Protect main branch (require PR, 1 approval)
26+ $protect = @ {
27+ required_pull_request_reviews = @ {
28+ required_approving_review_count = 1
29+ }
30+ enforce_admins = $true
31+ }
32+ Invoke-RestMethod - Method Put - Uri " https://api.github.com/repos/$Owner /$Repo /branches/main/protection" - Headers $Headers - Body ($protect | ConvertTo-Json - Depth 10 )
33+
34+ # 4. Update README with workflow
35+ $readme_content = @"
36+ ## Workflow
37+ - Fork the repo
38+ - Create feature/issue-# branch from dev
39+ - Work on the issue
40+ - PR to dev
41+ - After tests/approve, merge to dev
42+ - For release: PR dev to main
43+ "@
44+ $readme_base64 = [Convert ]::ToBase64String([Text.Encoding ]::UTF8.GetBytes($readme_content ))
45+ $existing_readme = Invoke-RestMethod " https://api.github.com/repos/$Owner /$Repo /contents/README.md" - Headers $Headers
46+ Invoke-RestMethod - Method Put - Uri " https://api.github.com/repos/$Owner /$Repo /contents/README.md" - Headers $Headers - Body (@ {
47+ message = " Update README with workflow"
48+ content = $readme_base64
49+ sha = $existing_readme.sha
50+ } | ConvertTo-Json )
51+
52+ # 5. Create GitHub Actions for tests on dev
53+ mkdir .github/ workflows - ErrorAction SilentlyContinue
54+ $actions_yaml = @"
55+ name: Test Dev Branch
56+ on:
57+ push:
58+ branches: [dev]
59+ pull_request:
60+ branches: [dev]
61+ jobs:
62+ test:
63+ runs-on: ubuntu-latest
64+ steps:
65+ - uses: actions/checkout@v4
66+ - name: Set up Python
67+ uses: actions/setup-python@v5
68+ with:
69+ python-version: '3.11'
70+ - name: Install deps
71+ run: pip install pytest tiktoken
72+ - name: Run tests
73+ run: pytest tests/ -v
74+ "@
75+ $actions_yaml | Out-File - FilePath " .github/workflows/test-dev.yml" - Encoding utf8
76+
77+ # 6. Commit and push
78+ git add .
79+ git commit - m " setup: dev branch workflow, protected main, actions tests"
80+ git push origin dev
81+
82+ Write-Host " All done! Dev branch is ready." - ForegroundColor Green
83+ Write-Host " Contributors now PR to dev, merge after tests, then PR dev to main for release." - ForegroundColor Green
0 commit comments