-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.ps1
More file actions
186 lines (154 loc) · 8.4 KB
/
deploy.ps1
File metadata and controls
186 lines (154 loc) · 8.4 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
# ==============================================================================
# VibeGarden Master Pipeline: Sync-Gated Deployment
# ==============================================================================
# ==============================================================================
# 1. PRE-FLIGHT DEPENDENCY CHECK
# ==============================================================================
$dependenciesPassed = $true
# A. Check for Git
if (-not (Get-Command git -ErrorAction SilentlyContinue)) {
Write-Host "[ERROR] Git is NOT installed. Please install Git for Windows." -ForegroundColor Red
$dependenciesPassed = $false
}
# B. Check for Zowe CLI
if (-not (Get-Command zowe -ErrorAction SilentlyContinue)) {
Write-Host "[ERROR] Zowe CLI is NOT installed. Please install it via Node.js (npm install -g @zowe/cli)." -ForegroundColor Red
$dependenciesPassed = $false
}
# C. Check for Environment Variables (The Credentials)
if ([string]::IsNullOrWhiteSpace($env:ZOWE_USER) -or [string]::IsNullOrWhiteSpace($env:ZOWE_PASSWORD)) {
Write-Host "[ERROR] Missing Credentials: ZOWE_USER and ZOWE_PASSWORD environment variables must be set." -ForegroundColor Red
Write-Host " Try: $env:ZOWE_USER='your_id'; $env:ZOWE_PASSWORD='your_password'" -ForegroundColor Gray
$dependenciesPassed = $false
}
# D. Check Folder Structure
$requiredFolders = @("COBOL", "JCL")
foreach ($folder in $requiredFolders) {
if (-not (Test-Path $folder)) {
Write-Host "[ERROR] Missing Folder: Could not find the '$folder' directory in the current path." -ForegroundColor Red
$dependenciesPassed = $false
}
}
# E. Final Decision: Stop if any check failed
if (-not $dependenciesPassed) {
Write-Host "`n VibeGarden Pipeline cannot start until dependencies are fixed.`n" -ForegroundColor Yellow
exit 1
}
Write-Host " All dependencies verified. Starting VibeGarden Master Pipeline..." -ForegroundColor Cyan
# ==============================================================================
# 2. CONFIGURATION ---
# ==============================================================================
$myUSER_ID = $env:ZOWE_USER
$myPASSWORD = $env:ZOWE_PASSWORD
$JCL_PDS = "$($myUSER_ID).ZMYPRSNL.JCL"
$COBOL_PDS = "$($myUSER_ID).ZMYPRSNL.COBOL"
# A. Log File Setup
$logDir = "./logs"
if (-not (Test-Path $logDir)) { New-Item -Path $logDir -ItemType Directory }
$logFile = "$logDir/deploy-$(Get-Date -Format 'yyyyMMdd-HHmm').md"
# B. Write logs into the new log file
function Write-Log($msg, $color) {
$timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
# 1. Keep Terminal Colors for your live view
Write-Host "[$timestamp] $msg" -ForegroundColor $color
# 2. Markdown Formatting for the Log File
# # = Green (Heading 1), > = Cyan (Blockquote), - = Yellow/White (List)
$mdLine = switch ($color) {
"Green" { "## PASS: $msg" } # Bold Green-ish Header
"Red" { "## ERROR: $msg" } # Bold Red-ish Header
"Cyan" { "> SYNC: $msg" } # Indented Blue-ish block
"Yellow" { "- INFO: $msg" } # Bulleted Yellow-ish line
"Orange" { "- WARN: $msg" }
Default { " $msg" }
}
"$mdLine [$timestamp] " | Out-File -FilePath $logFile -Append
}
#==============================================================================
# 3. Start the stopwatch
#==============================================================================
$totalStartTime = Get-Date
#==============================================================================
# 4. PRE-DEPLOYMENT GIT RECORD
# We commit locally first so your work is saved before we talk to the mainframe.
#==============================================================================
Write-Log "[1/7] Recording local changes (Local Commit)..." "Yellow"
git add .
git commit -m "VibeGarden Build Started: $(Get-Date -Format 'HH:mm')" --allow-empty
#==============================================================================
# 5. VERSIONING LOGIC
#==============================================================================
$version = Get-Date -Format "yyyyMMdd"
$buildId = "B" + (Get-Date -Format "HHmm") # Example: B1430
$newTag = "$version-$buildId"
Write-Log "Updating COBOL Version Tag to: $newTag" "Cyan"
# Read the file, replace the placeholder, and save it back
(Get-Content "COBOL\CALCDVOP.cbl") -replace "BUILD-TAG", $newTag |
Set-Content "COBOL\CALCDVOP.cbl"
#==============================================================================
# 6. MAINFRAME UPLOAD
#==============================================================================
Write-Log "[2/7] Uploading Source to $myUSER_ID..." "Yellow"
zowe files upload file-to-data-set "COBOL\CALCDVOP.cbl" "$COBOL_PDS(CALCDVOP)" --user $myUSER_ID --pass $myPASSWORD
zowe files upload file-to-data-set "JCL\COMPJCL.jcl" "$JCL_PDS(COMPJCL)" --user $myUSER_ID --pass $myPASSWORD
zowe files upload file-to-data-set "JCL\RUNJCL.jcl" "$JCL_PDS(RUNJCL)" --user $myUSER_ID --pass $myPASSWORD
#==============================================================================
# 7. COMPILE SECTION
#==============================================================================
Write-Log "[3/7] Compiling COBOL..." "Yellow"
$compRaw = zowe jobs submit data-set "$JCL_PDS(COMPJCL)" --wait-for-output --rfj --user $myUSER_ID --pass $myPASSWORD
$compJob = $compRaw | ConvertFrom-Json
$rc = $compJob.data.retcode
# A. If $rc is empty, it means the Zowe command failed to get a result at all
if ([string]::IsNullOrWhiteSpace($rc)) {
$rc = "UNKNOWN (Zowe Communication Error)"
}
if ($rc -ne "CC 0000" -and $rc -ne "CC 0004") {
Write-Log "[ERROR] COMPILE FAILED: $($rc). Check spool for errors." "Red"
exit 1 # Script stops here; nothing is pushed to GitHub.
}
Write-Log " COMPILE SUCCESS" "Green"
#==============================================================================
# 8. EXECUTION SECTION
#==============================================================================
Write-Log "[4/7] Running Automated TESTS (RUNJCL)..." "Yellow"
$runRaw = zowe jobs submit data-set "$JCL_PDS(RUNJCL)" --wait-for-output --rfj --user $myUSER_ID --pass $myPASSWORD
$runJob = $runRaw | ConvertFrom-Json
$jobId = $runJob.data.jobid
# A. Dynamic Spool Lookup for SYSOUT
$spoolFiles = zowe jobs list spool-files-by-jobid $jobId --rfj --user $myUSER_ID --pass $myPASSWORD | ConvertFrom-Json
$sysoutId = ($spoolFiles.data | Where-Object { $_.ddname.Trim() -eq "SYSOUT" }).id
if (-not $sysoutId) { $sysoutId = $spoolFiles.data[-1].id } # Fallback to last file
$testResults = zowe jobs view spool-file-by-id $jobId $sysoutId --user $myUSER_ID --pass $myPASSWORD
#==============================================================================
# 9. VALIDATION & GITHUB PUSH
#==============================================================================
Write-Log "[5/7] Validating Result Logic..." "Yellow"
Write-Host "--- PROGRAM OUTPUT ---" -ForegroundColor Gray
Write-Host $testResults.Trim() -ForegroundColor White
Write-Host "----------------------" -ForegroundColor Gray
# A. DIRECT EXTRACTION: We search and capture in one command without using $Matches
$regexPattern = "VibeGarden Result:\s*(?<val>[\d,.]+)"
$foundValue = ([regex]::Match($testResults, $regexPattern)).Groups['val'].Value
# B. Validation Gate: This check will now work because $foundValue is never a null array
if (-not [string]::IsNullOrWhiteSpace($foundValue)) {
$foundValue = $foundValue.Trim()
Write-Log " TESTS PASSED: Captured Result: $foundValue" "Green"
# GITHUB SYNC
Write-Log "[6/7] Success! Pushing 'Blessed' code to GitHub..." "Yellow"
git commit --amend -m "VibeGarden Success: Job $jobId - Result $foundValue"
git push
Write-Log " GITHUB SYNCED" "Cyan"
}
else {
Write-Log "[ERROR] TEST FAILED: Could not extract numeric result from output." "Red"
Write-Log " [RUNTIME ERROR] WARNING: Code updated on Mainframe but NOT on GitHub." "Yellow"
exit 1
}
#==============================================================================
# 10. Calculate elapsed time and write the final completion message to the log
#==============================================================================
$totalEndTime = Get-Date
$duration = $totalEndTime - $totalStartTime
$timeString = "{0:mm} min {0:ss} sec" -f $duration
Write-Log "[7/7] VibeGarden Pipeline Finished Successfully in $timeString!" "Yellow"
#===========================================================================================================================================s