-
-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathwizard.sh
More file actions
executable file
·1007 lines (822 loc) · 34.2 KB
/
wizard.sh
File metadata and controls
executable file
·1007 lines (822 loc) · 34.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env bash
# ─────────────────────────────────────────────────────────────────
# GitHub Workflow Blueprint - Setup Wizard
# ─────────────────────────────────────────────────────────────────
# Interactive setup wizard that configures a repository from scratch.
#
# Features:
# - Environment detection and validation
# - Interactive configuration prompts
# - Automated branch creation
# - Secret configuration
# - Bootstrap workflow execution
# - Branch protection setup
# - Comprehensive validation
#
# Usage: ./setup/wizard.sh
#
# Requirements:
# - Git 2.40+
# - GitHub CLI (gh) 2.40+
# - Bash 4.0+ (or compatible shell)
#
# Author: Alireza Rezvani
# Date: 2025-11-06
# ─────────────────────────────────────────────────────────────────
set -euo pipefail
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
PURPLE='\033[0;35m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color
# Global variables
PROJECT_TYPE=""
BRANCHING_STRATEGY=""
PROJECT_URL=""
ANTHROPIC_API_KEY=""
REPO_OWNER=""
REPO_NAME=""
SETUP_LOG="setup-log.txt"
ROLLBACK_NEEDED=false
# ─────────────────────────────────────────────────────────────────
# Utility Functions
# ─────────────────────────────────────────────────────────────────
log() {
echo -e "${GREEN}✓${NC} $1" | tee -a "$SETUP_LOG"
}
log_info() {
echo -e "${BLUE}ℹ${NC} $1" | tee -a "$SETUP_LOG"
}
log_warning() {
echo -e "${YELLOW}⚠${NC} $1" | tee -a "$SETUP_LOG"
}
log_error() {
echo -e "${RED}✗${NC} $1" | tee -a "$SETUP_LOG"
}
log_step() {
echo -e "\n${CYAN}▶${NC} ${PURPLE}$1${NC}" | tee -a "$SETUP_LOG"
}
prompt() {
echo -e "${YELLOW}?${NC} $1"
}
confirm() {
local prompt="$1"
local response
while true; do
read -p "$(echo -e "${YELLOW}?${NC} $prompt (y/n): ")" response
case "$response" in
[Yy]* ) return 0;;
[Nn]* ) return 1;;
* ) echo "Please answer y or n.";;
esac
done
}
# ─────────────────────────────────────────────────────────────────
# Step 1: Welcome & Prerequisites Check
# ─────────────────────────────────────────────────────────────────
show_welcome() {
clear
cat << 'EOF'
╔══════════════════════════════════════════════════════════════════╗
║ ║
║ 🚀 GitHub Workflow Blueprint - Setup Wizard 🚀 ║
║ ║
╚══════════════════════════════════════════════════════════════════╝
This wizard will configure your repository with:
✅ GitHub Actions workflows (8 workflows)
✅ Composite actions (5 reusable actions)
✅ Configuration templates (PR, issues, commits)
✅ Project board integration
✅ Branch protections
Estimated time: <5 minutes
═══════════════════════════════════════════════════════════════════
EOF
echo "" | tee "$SETUP_LOG"
log_info "Setup started at $(date)"
echo ""
}
check_prerequisites() {
log_step "Step 1: Checking Prerequisites"
local all_good=true
# Check Git
if command -v git &> /dev/null; then
local git_version=$(git --version | awk '{print $3}')
log "Git version $git_version detected"
else
log_error "Git is not installed"
log_info "Install from: https://git-scm.com/downloads"
all_good=false
fi
# Check GitHub CLI
if command -v gh &> /dev/null; then
local gh_version=$(gh --version | head -1 | awk '{print $3}')
log "GitHub CLI version $gh_version detected"
else
log_error "GitHub CLI (gh) is not installed"
log_info "Install from: https://cli.github.com/"
all_good=false
fi
# Check GitHub authentication
if command -v gh &> /dev/null; then
if gh auth status &> /dev/null; then
local gh_user=$(gh api user -q .login 2>/dev/null || echo "unknown")
log "Authenticated as: $gh_user"
else
log_error "Not authenticated with GitHub CLI"
log_info "Run: gh auth login"
all_good=false
fi
fi
# Check if in git repository
if git rev-parse --git-dir &> /dev/null; then
log "Git repository detected"
# Get repository info
REPO_OWNER=$(gh repo view --json owner -q .owner.login 2>/dev/null || echo "")
REPO_NAME=$(gh repo view --json name -q .name 2>/dev/null || echo "")
if [[ -n "$REPO_OWNER" && -n "$REPO_NAME" ]]; then
log "Repository: $REPO_OWNER/$REPO_NAME"
else
log_warning "Could not detect GitHub repository info"
fi
else
log_error "Not in a git repository"
log_info "Run: git init && gh repo create"
all_good=false
fi
echo ""
if [[ "$all_good" != true ]]; then
log_error "Prerequisites not met. Please install required tools and try again."
if confirm "Do you want to continue anyway? (not recommended)"; then
log_warning "Continuing without all prerequisites..."
return 0
else
exit 1
fi
fi
return 0
}
# ─────────────────────────────────────────────────────────────────
# Step 2: Detect Project Type
# ─────────────────────────────────────────────────────────────────
detect_project_type() {
log_step "Step 2: Project Type Selection"
cat << 'EOF'
📦 What type of project is this?
1. Web (frontend/backend web applications)
- React, Next.js, Vue, Angular, etc.
- Node.js, Express, NestJS, etc.
2. Mobile (React Native, iOS, Android)
- React Native, Expo
- Native iOS/Android
3. Fullstack (web + backend + optional mobile)
- Complete application stack
- Multiple platforms
EOF
while true; do
read -p "$(echo -e "${YELLOW}?${NC} Enter 1, 2, or 3: ")" choice
case $choice in
1)
PROJECT_TYPE="web"
log "Selected: Web project"
break
;;
2)
PROJECT_TYPE="mobile"
log "Selected: Mobile project"
break
;;
3)
PROJECT_TYPE="fullstack"
log "Selected: Fullstack project"
break
;;
*)
echo "Invalid choice. Please enter 1, 2, or 3."
;;
esac
done
echo ""
}
# ─────────────────────────────────────────────────────────────────
# Step 3: Choose Branching Strategy
# ─────────────────────────────────────────────────────────────────
choose_branching_strategy() {
log_step "Step 3: Branching Strategy Selection"
cat << 'EOF'
🌿 Which branching strategy do you want to use?
1. Simple: feature → main
├─ Best for: Solo developers, small projects
├─ Fast, minimal overhead
└─ Single review step
2. Standard: feature → dev → main (RECOMMENDED)
├─ Best for: Small to medium teams
├─ Good balance of safety and speed
└─ Staging environment before production
3. Complex: feature → dev → staging → main
├─ Best for: Enterprise, multiple environments
├─ Maximum safety, slower
└─ Multiple validation stages
EOF
while true; do
read -p "$(echo -e "${YELLOW}?${NC} Enter 1, 2, or 3 (default: 2): ")" choice
choice=${choice:-2}
case $choice in
1)
BRANCHING_STRATEGY="simple"
log "Selected: Simple branching (feature → main)"
break
;;
2)
BRANCHING_STRATEGY="standard"
log "Selected: Standard branching (feature → dev → main)"
break
;;
3)
BRANCHING_STRATEGY="complex"
log "Selected: Complex branching (feature → dev → staging → main)"
break
;;
*)
echo "Invalid choice. Please enter 1, 2, or 3."
;;
esac
done
echo ""
}
# ─────────────────────────────────────────────────────────────────
# Step 4: Get Project Board URL
# ─────────────────────────────────────────────────────────────────
get_project_url() {
log_step "Step 4: Project Board Configuration"
cat << 'EOF'
📊 Enter your GitHub Project board URL:
Format examples:
• https://github.com/users/USERNAME/projects/NUMBER
• https://github.com/orgs/ORG/projects/NUMBER
Example: https://github.com/users/alirezarezvani/projects/1
EOF
while true; do
read -p "$(echo -e "${YELLOW}?${NC} Project URL: ")" url
# Validate URL format
if [[ $url =~ ^https://github\.com/(users|orgs)/[^/]+/projects/[0-9]+$ ]]; then
PROJECT_URL="$url"
log "Project URL validated: $url"
# Try to verify project exists
log_info "Verifying project access..."
if gh project view "$PROJECT_URL" &> /dev/null; then
log "Project board verified and accessible"
else
log_warning "Could not verify project access (may be a permissions issue)"
if confirm "Continue anyway?"; then
break
else
continue
fi
fi
break
else
log_error "Invalid URL format"
echo "URL must match: https://github.com/(users|orgs)/USERNAME/projects/NUMBER"
fi
done
echo ""
}
# ─────────────────────────────────────────────────────────────────
# Step 5: Get Anthropic API Key
# ─────────────────────────────────────────────────────────────────
get_api_key() {
log_step "Step 5: Anthropic API Key Configuration"
cat << 'EOF'
🔑 Enter your Anthropic API Key:
This is required for Claude Code integration in workflows.
Get your API key from: https://console.anthropic.com/
⚠️ Your API key will be stored as an encrypted repository secret.
EOF
while true; do
read -sp "$(echo -e "${YELLOW}?${NC} API Key (hidden): ")" key
echo ""
# Basic validation
if [[ -z "$key" ]]; then
log_error "API key cannot be empty"
continue
fi
if [[ ! $key =~ ^sk-ant- ]]; then
log_warning "API key doesn't start with 'sk-ant-' (may be invalid)"
if ! confirm "Continue anyway?"; then
continue
fi
fi
if [[ ${#key} -lt 20 ]]; then
log_warning "API key seems too short (may be invalid)"
if ! confirm "Continue anyway?"; then
continue
fi
fi
ANTHROPIC_API_KEY="$key"
log "API key validated (sk-ant-***${key: -4})"
break
done
echo ""
}
# ─────────────────────────────────────────────────────────────────
# Step 6: Configuration Summary
# ─────────────────────────────────────────────────────────────────
show_configuration_summary() {
log_step "Step 6: Configuration Summary"
cat << EOF
╔══════════════════════════════════════════════════════════════════╗
║ Configuration Summary ║
╚══════════════════════════════════════════════════════════════════╝
Project Type: ${PROJECT_TYPE}
Branching Strategy: ${BRANCHING_STRATEGY}
Project Board: ${PROJECT_URL}
API Key: sk-ant-***${ANTHROPIC_API_KEY: -4}
Branches to create:
EOF
case $BRANCHING_STRATEGY in
simple)
echo " • main (already exists)"
;;
standard)
echo " • main (already exists)"
echo " • dev (will be created)"
;;
complex)
echo " • main (already exists)"
echo " • dev (will be created)"
echo " • staging (will be created)"
;;
esac
echo ""
if ! confirm "Ready to proceed with setup?"; then
log_warning "Setup cancelled by user"
echo ""
log_info "Run './setup/wizard.sh' to start over"
exit 0
fi
echo ""
}
# ─────────────────────────────────────────────────────────────────
# Step 7: Create Required Branches
# ─────────────────────────────────────────────────────────────────
create_branches() {
log_step "Step 7: Creating Required Branches"
case $BRANCHING_STRATEGY in
simple)
log "No additional branches needed (using main only)"
;;
standard)
create_branch "dev"
;;
complex)
create_branch "dev"
create_branch "staging"
;;
esac
echo ""
}
create_branch() {
local branch_name="$1"
# Check if branch exists locally
if git rev-parse --verify "$branch_name" &> /dev/null; then
log "Branch '$branch_name' already exists locally"
# Check if exists remotely
if git ls-remote --heads origin "$branch_name" | grep -q "$branch_name"; then
log "Branch '$branch_name' already exists remotely"
return 0
else
# Push existing local branch
log_info "Pushing local branch '$branch_name' to remote..."
if git push -u origin "$branch_name"; then
log "Branch '$branch_name' pushed to remote"
else
log_error "Failed to push branch '$branch_name'"
ROLLBACK_NEEDED=true
return 1
fi
fi
else
# Check if exists remotely but not locally
if git ls-remote --heads origin "$branch_name" | grep -q "$branch_name"; then
log "Branch '$branch_name' exists remotely, checking out..."
git checkout -b "$branch_name" "origin/$branch_name"
log "Branch '$branch_name' checked out from remote"
else
# Create new branch
log_info "Creating branch '$branch_name'..."
local current_branch=$(git branch --show-current)
# Create from main
if git checkout -b "$branch_name"; then
if git push -u origin "$branch_name"; then
log "Branch '$branch_name' created and pushed"
# Switch back to original branch
git checkout "$current_branch" &> /dev/null
else
log_error "Failed to push branch '$branch_name'"
ROLLBACK_NEEDED=true
return 1
fi
else
log_error "Failed to create branch '$branch_name'"
ROLLBACK_NEEDED=true
return 1
fi
fi
fi
return 0
}
# ─────────────────────────────────────────────────────────────────
# Step 8: Set Repository Secrets
# ─────────────────────────────────────────────────────────────────
set_secrets() {
log_step "Step 8: Configuring Repository Secrets"
# Set PROJECT_URL
log_info "Setting PROJECT_URL secret..."
if echo "$PROJECT_URL" | gh secret set PROJECT_URL; then
log "PROJECT_URL configured"
else
log_error "Failed to set PROJECT_URL secret"
log_info "Manual setup: Settings → Secrets and variables → Actions → New repository secret"
log_info "Name: PROJECT_URL"
log_info "Value: $PROJECT_URL"
if ! confirm "Continue anyway?"; then
ROLLBACK_NEEDED=true
return 1
fi
fi
# Set ANTHROPIC_API_KEY
log_info "Setting ANTHROPIC_API_KEY secret..."
if echo "$ANTHROPIC_API_KEY" | gh secret set ANTHROPIC_API_KEY; then
log "ANTHROPIC_API_KEY configured"
else
log_error "Failed to set ANTHROPIC_API_KEY secret"
log_info "Manual setup: Settings → Secrets and variables → Actions → New repository secret"
log_info "Name: ANTHROPIC_API_KEY"
log_info "Value: [your API key]"
if ! confirm "Continue anyway?"; then
ROLLBACK_NEEDED=true
return 1
fi
fi
# Verify secrets
log_info "Verifying secrets..."
if gh secret list | grep -q "PROJECT_URL" && gh secret list | grep -q "ANTHROPIC_API_KEY"; then
log "Both secrets verified"
else
log_warning "Could not verify all secrets"
fi
echo ""
}
# ─────────────────────────────────────────────────────────────────
# Step 9: Run Bootstrap Workflow
# ─────────────────────────────────────────────────────────────────
run_bootstrap() {
log_step "Step 9: Running Bootstrap Workflow"
log_info "Triggering bootstrap.yml workflow..."
if gh workflow run bootstrap.yml; then
log "Bootstrap workflow triggered"
# Wait a moment for workflow to start
sleep 3
# Get the latest run ID
log_info "Waiting for workflow to start..."
local run_id=""
local max_attempts=10
local attempt=0
while [[ -z "$run_id" ]] && [[ $attempt -lt $max_attempts ]]; do
run_id=$(gh run list --workflow=bootstrap.yml --limit 1 --json databaseId --jq '.[0].databaseId' 2>/dev/null || echo "")
if [[ -z "$run_id" ]]; then
sleep 2
((attempt++))
fi
done
if [[ -n "$run_id" ]]; then
log "Workflow started (Run ID: $run_id)"
log_info "Monitoring workflow execution..."
# Monitor workflow (with timeout)
local status=""
local max_wait=120 # 2 minutes
local elapsed=0
while [[ $elapsed -lt $max_wait ]]; do
status=$(gh run view "$run_id" --json status --jq .status 2>/dev/null || echo "")
if [[ "$status" == "completed" ]]; then
local conclusion=$(gh run view "$run_id" --json conclusion --jq .conclusion 2>/dev/null || echo "")
if [[ "$conclusion" == "success" ]]; then
log "Bootstrap workflow completed successfully"
return 0
else
log_error "Bootstrap workflow failed (conclusion: $conclusion)"
log_info "View logs: gh run view $run_id --log"
if confirm "Continue anyway? (not recommended)"; then
return 0
else
ROLLBACK_NEEDED=true
return 1
fi
fi
fi
sleep 5
((elapsed+=5))
done
log_warning "Workflow still running after ${max_wait}s"
log_info "Check status: gh run view $run_id"
if confirm "Continue without waiting?"; then
return 0
else
return 1
fi
else
log_error "Could not get workflow run ID"
log_info "Check manually: gh run list --workflow=bootstrap.yml"
if confirm "Continue anyway?"; then
return 0
else
ROLLBACK_NEEDED=true
return 1
fi
fi
else
log_error "Failed to trigger bootstrap workflow"
log_info "Manual trigger: gh workflow run bootstrap.yml"
if confirm "Continue anyway?"; then
return 0
else
ROLLBACK_NEEDED=true
return 1
fi
fi
echo ""
}
# ─────────────────────────────────────────────────────────────────
# Step 10: Apply Branch Protections
# ─────────────────────────────────────────────────────────────────
apply_branch_protections() {
log_step "Step 10: Applying Branch Protections"
log_warning "Branch protections require GitHub Pro or organization account"
log_info "If you have a free account, you'll need to set these manually"
if ! confirm "Attempt to apply branch protections now?"; then
log_info "Skipping branch protection setup"
log_info "Manual setup: Settings → Branches → Add rule"
echo ""
return 0
fi
# Protect main branch
protect_branch "main" true
# Protect dev branch (if standard/complex)
if [[ "$BRANCHING_STRATEGY" == "standard" ]] || [[ "$BRANCHING_STRATEGY" == "complex" ]]; then
protect_branch "dev" false
fi
# Protect staging branch (if complex)
if [[ "$BRANCHING_STRATEGY" == "complex" ]]; then
protect_branch "staging" false
fi
echo ""
}
protect_branch() {
local branch="$1"
local enforce_admins="$2"
log_info "Protecting branch: $branch"
# Note: This requires GitHub Pro or organization account
# Using gh api to set branch protection
local protection_json='{
"required_status_checks": {
"strict": true,
"contexts": []
},
"enforce_admins": '"$enforce_admins"',
"required_pull_request_reviews": {
"required_approving_review_count": 1,
"dismiss_stale_reviews": true
},
"restrictions": null,
"required_linear_history": true,
"allow_force_pushes": false,
"allow_deletions": false
}'
if gh api "repos/$REPO_OWNER/$REPO_NAME/branches/$branch/protection" \
--method PUT \
--input - <<< "$protection_json" &> /dev/null; then
log "Branch '$branch' protected"
else
log_warning "Could not protect branch '$branch' (may require GitHub Pro)"
log_info "Manual setup: Settings → Branches → Add rule for '$branch'"
fi
}
# ─────────────────────────────────────────────────────────────────
# Step 11: Validate Setup
# ─────────────────────────────────────────────────────────────────
validate_setup() {
log_step "Step 11: Validating Setup"
local all_good=true
# Check branches
log_info "Checking branches..."
case $BRANCHING_STRATEGY in
simple)
if git ls-remote --heads origin main | grep -q main; then
log "✓ Branch 'main' exists"
else
log_error "✗ Branch 'main' missing"
all_good=false
fi
;;
standard)
if git ls-remote --heads origin main | grep -q main; then
log "✓ Branch 'main' exists"
else
log_error "✗ Branch 'main' missing"
all_good=false
fi
if git ls-remote --heads origin dev | grep -q dev; then
log "✓ Branch 'dev' exists"
else
log_error "✗ Branch 'dev' missing"
all_good=false
fi
;;
complex)
if git ls-remote --heads origin main | grep -q main; then
log "✓ Branch 'main' exists"
else
log_error "✗ Branch 'main' missing"
all_good=false
fi
if git ls-remote --heads origin dev | grep -q dev; then
log "✓ Branch 'dev' exists"
else
log_error "✗ Branch 'dev' missing"
all_good=false
fi
if git ls-remote --heads origin staging | grep -q staging; then
log "✓ Branch 'staging' exists"
else
log_error "✗ Branch 'staging' missing"
all_good=false
fi
;;
esac
# Check secrets
log_info "Checking secrets..."
if gh secret list | grep -q "PROJECT_URL"; then
log "✓ PROJECT_URL secret configured"
else
log_error "✗ PROJECT_URL secret missing"
all_good=false
fi
if gh secret list | grep -q "ANTHROPIC_API_KEY"; then
log "✓ ANTHROPIC_API_KEY secret configured"
else
log_error "✗ ANTHROPIC_API_KEY secret missing"
all_good=false
fi
# Check workflows
log_info "Checking workflows..."
local workflow_count=$(ls -1 .github/workflows/*.yml 2>/dev/null | wc -l | tr -d ' ')
if [[ "$workflow_count" -eq 8 ]]; then
log "✓ All 8 workflows present"
else
log_warning "⚠ Found $workflow_count workflows (expected 8)"
fi
# Check composite actions
log_info "Checking composite actions..."
local action_count=$(find .github/actions -name "action.yml" 2>/dev/null | wc -l | tr -d ' ')
if [[ "$action_count" -eq 5 ]]; then
log "✓ All 5 composite actions present"
else
log_warning "⚠ Found $action_count composite actions (expected 5)"
fi
echo ""
if [[ "$all_good" == true ]]; then
log "✅ All validations passed!"
else
log_warning "⚠ Some validations failed (see above)"
fi
echo ""
}
# ─────────────────────────────────────────────────────────────────
# Step 12: Generate Summary
# ─────────────────────────────────────────────────────────────────
show_final_summary() {
log_step "Setup Complete!"
cat << EOF
╔══════════════════════════════════════════════════════════════════╗
║ 🎉 Setup Complete! 🎉 ║
╚══════════════════════════════════════════════════════════════════╝
Your repository is now configured with the GitHub Workflow Blueprint.
📊 Summary:
Project Type: ${PROJECT_TYPE}
Branching: ${BRANCHING_STRATEGY}
Workflows: 8 core workflows
Actions: 5 composite actions
Project Board: Connected
🚀 Next Steps:
1. Create your first issue:
• Go to Issues → New Issue
• Use "Plan Task" template
• Add labels: claude-code + status:ready
• Branch will be auto-created!
2. Start working:
$ git fetch
$ git checkout feature/issue-1-your-task
$ # Make changes
$ git commit -m "feat: your changes"
$ git push
3. Create pull request:
• Use slash command: /create-pr
• Or manually with proper issue linking
• Automated quality checks will run
4. Helpful slash commands:
• /plan-to-issues - Convert Claude plan to issues
• /commit-smart - Smart commit with quality checks
• /create-pr - Create PR with proper linking
• /review-pr - Get Claude code review
• /release - Create production release
📚 Documentation:
• README.md - Project overview
• docs/QUICK_START.md - 5-minute guide
• docs/WORKFLOWS.md - All workflows explained
• docs/COMMANDS.md - All slash commands
• docs/CUSTOMIZATION.md - Advanced configuration
⚙️ Configuration saved to: .github/
═══════════════════════════════════════════════════════════════════
Setup completed at $(date)
Setup log saved to: ${SETUP_LOG}
EOF
}
# ─────────────────────────────────────────────────────────────────
# Rollback Function
# ─────────────────────────────────────────────────────────────────
perform_rollback() {
log_step "Rollback: Cleaning Up"
log_warning "Attempting to rollback changes..."
# Remove created branches
case $BRANCHING_STRATEGY in
standard)
if git ls-remote --heads origin dev | grep -q dev; then
log_info "Deleting remote branch 'dev'..."
git push origin --delete dev 2>/dev/null || true
fi
if git rev-parse --verify dev &> /dev/null; then
git branch -D dev 2>/dev/null || true
fi
;;
complex)
if git ls-remote --heads origin dev | grep -q dev; then
log_info "Deleting remote branch 'dev'..."
git push origin --delete dev 2>/dev/null || true
fi
if git ls-remote --heads origin staging | grep -q staging; then
log_info "Deleting remote branch 'staging'..."
git push origin --delete staging 2>/dev/null || true
fi
if git rev-parse --verify dev &> /dev/null; then
git branch -D dev 2>/dev/null || true
fi
if git rev-parse --verify staging &> /dev/null; then
git branch -D staging 2>/dev/null || true
fi
;;
esac
# Note: We don't remove secrets as they may have existed before
log_info "Secrets left intact (remove manually if needed)"
log "Rollback complete"
echo ""
}
# ─────────────────────────────────────────────────────────────────
# Main Execution
# ─────────────────────────────────────────────────────────────────
main() {
# Trap errors
trap 'if [[ $? -ne 0 ]] && [[ "$ROLLBACK_NEEDED" == true ]]; then perform_rollback; fi' EXIT
# Show welcome
show_welcome
# Step 1: Check prerequisites
check_prerequisites || exit 1
# Step 2: Detect project type
detect_project_type
# Step 3: Choose branching strategy
choose_branching_strategy
# Step 4: Get project URL
get_project_url
# Step 5: Get API key
get_api_key
# Step 6: Show configuration summary
show_configuration_summary
# Step 7: Create branches
create_branches || exit 1
# Step 8: Set secrets
set_secrets || exit 1
# Step 9: Run bootstrap
run_bootstrap || exit 1
# Step 10: Apply branch protections
apply_branch_protections
# Step 11: Validate setup
validate_setup
# Step 12: Show summary
show_final_summary