-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathManagePDFInvoiceProject.ps1
More file actions
137 lines (115 loc) · 5.81 KB
/
Copy pathManagePDFInvoiceProject.ps1
File metadata and controls
137 lines (115 loc) · 5.81 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
<#
╔══════════════════════════════════════════════════════════════════╗
║ UCSF PDF Invoice Project — DevOps Control Center ║
║ Menu-driven environment manager for Salesforce + GitHub workflow ║
║ Includes baseline, rollback, cleanup, verification, and README ║
║ Author: Maurice J. Davis + ChatGPT DevOps Assistant ║
╚══════════════════════════════════════════════════════════════════╝
#>
# --- SETTINGS ---
$RepoPath = "C:\Users\MauriceJDavis\PDFInvoiceProject"
$OrgAlias = "ucsfsandbox"
$RepoUrl = "https://github.com/mauricedavis/PDFInvoiceProject"
Set-Location $RepoPath
# --- HELPER FUNCTIONS ---
function Create-Baseline {
$timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
$tagStamp = Get-Date -Format "yyyyMMdd_HHmmss"
$branchName = "branch_baseline_reset_${tagStamp}"
$tagName = "baseline_reset_${tagStamp}"
git checkout -b $branchName
git add .
git commit -m "Baseline reset - $timestamp"
git push origin $branchName
git tag -a $tagName -m "Baseline reset $timestamp"
git push origin $tagName
gh release create $tagName --title "Baseline Reset ($timestamp)" --notes "Protected baseline version snapshot"
gh api --method PATCH "repos/mauricedavis/PDFInvoiceProject/git/refs/tags/$tagName/protection" --input-data '{"protected":true}' 2>$null
git checkout main
Write-Host "✅ Baseline branch '$branchName' and protected tag '$tagName' created successfully.`n"
}
function Restore-FromBaseline {
$tags = git tag --list "baseline_reset_*"
if (-not $tags) {
Write-Host "⚠️ No baseline tags found."
return
}
Write-Host "Available baselines:`n$tags"
$selectedTag = Read-Host "Enter the tag name to restore"
if (-not $selectedTag) { Write-Host "❌ No tag selected."; return }
$timestamp = Get-Date -Format "yyyyMMdd_HHmmss"
$rollbackBranch = "rollback_from_${selectedTag}_${timestamp}"
git checkout -b $rollbackBranch $selectedTag
git push origin $rollbackBranch
sf project deploy start --target-org $OrgAlias --ignore-conflicts
sf apex run test --tests ProgramEnrollmentInvoiceController_Tests --target-org $OrgAlias --wait 10
$rollbackTag = "rollback_${timestamp}_$(git rev-parse --short HEAD)"
git tag -a $rollbackTag -m "Rollback from $selectedTag on $timestamp"
git push origin $rollbackTag
gh release create $rollbackTag --title "Rollback ($timestamp)" --notes "Rollback from $selectedTag"
gh api --method PATCH "repos/mauricedavis/PDFInvoiceProject/git/refs/tags/$rollbackTag/protection" --input-data '{"protected":true}' 2>$null
git checkout main
Write-Host "✅ Rollback branch + tag created and verified.`n"
}
function Cleanup-Trigger {
$triggerPath = "force-app\main\default\triggers\ProgramEnrollmentInvoiceTrigger.trigger"
if (Test-Path $triggerPath) {
Remove-Item $triggerPath -Force
Write-Host "🧹 Deleted trigger file locally."
git add .
git commit -m "Remove ProgramEnrollmentInvoiceTrigger"
git push origin main
sf project deploy start --target-org $OrgAlias --ignore-conflicts
Write-Host "✅ Trigger cleanup deployed to Salesforce."
} else {
Write-Host "✅ No trigger file found — already clean."
}
}
function Verify-RepoState {
Write-Host "`n🔍 Listing key tags and releases..."
git tag --list "baseline_*","rollback_*","restored_*"
gh release list
Write-Host "`n✅ Verification complete — check for protected baseline tags."
}
function Update-Readme {
$updateScript = Join-Path $RepoPath "UpdateReadme.ps1"
if (-Not (Test-Path $updateScript)) {
Write-Host "❌ Missing UpdateReadme.ps1 script. Please add it first."
return
}
Write-Host "📝 Running README generator..."
& $updateScript
Write-Host "✅ README.md updated and pushed to GitHub."
}
# --- MENU ---
function Show-Menu {
Clear-Host
Write-Host ""
Write-Host "╔══════════════════════════════════════════════════════╗"
Write-Host "║ UCSF PDF Invoice Project - DevOps Control Center ║"
Write-Host "╠══════════════════════════════════════════════════════╣"
Write-Host "║ 1️⃣ Create Baseline Snapshot ║"
Write-Host "║ 2️⃣ Restore from Baseline ║"
Write-Host "║ 3️⃣ Cleanup Trigger ║"
Write-Host "║ 4️⃣ Verify Repo State ║"
Write-Host "║ 5️⃣ Update README Documentation ║"
Write-Host "║ 0️⃣ Exit ║"
Write-Host "╚══════════════════════════════════════════════════════╝"
}
do {
Show-Menu
$choice = Read-Host "Select an option"
switch ($choice) {
"1" { Create-Baseline }
"2" { Restore-FromBaseline }
"3" { Cleanup-Trigger }
"4" { Verify-RepoState }
"5" { Update-Readme }
"0" { Write-Host "👋 Exiting Control Center."; break }
Default { Write-Host "❌ Invalid option — please try again." }
}
if ($choice -ne "0") {
Write-Host "`nPress Enter to return to menu..."
Read-Host
}
} while ($choice -ne "0")