Setting the file. One moment.
Workflow · Azure Validate · microsoft/azure-skills · Skills Docs
ContentsBack to the top of the page 28.8
Errors · azd
(opens in a new tab)
references/scripts/ workflow.ps1
PowerShell · 129 lines · 5 KB
string
]$WorkspacePath
,
14 [ string ]$CompletedStep
15 )
16
17 enum ValidationStep {
18 None
19 LoadPlan
20 AddValidationSteps
21 RunValidation
22 BuildVerification
23 StaticRoleVerification
24 RecordProof
25 ResolveErrors
26 UpdateStatus
27 }
28
29 if ( -not $WorkspacePath) {
30 Write-Error "WorkspacePath is required."
31 exit 2
32 }
33
34 if ( -not ( Test-Path - Path $WorkspacePath - PathType Container)) {
35 Write-Error "Error: WorkspacePath ' $WorkspacePath ' does not exist or is not a directory."
36 exit 2
37 }
38
39 # Resolve the step the agent just completed.
40 # Omitting -CompletedStep signals the start of the workflow (None).
41 $step = [ ValidationStep ]::None
42 if ( -not [ string ]::IsNullOrEmpty($CompletedStep)) {
43 if ( -not [ enum ]::TryParse([ ValidationStep ] , $CompletedStep , $true , [ ref ]$step)) {
44 $validValues = ([ enum ]::GetNames([ ValidationStep ])) -join ", "
45 Write-Error "Error: '-CompletedStep $CompletedStep ' is not a valid step. Valid values: $validValues "
46 exit 2
47 }
48 }
49
50 # Record progress in .azure/validate-status.json (creating it if needed).
51 $azureDir = Join-Path - Path $WorkspacePath - ChildPath ".azure"
52 if ( -not ( Test-Path - Path $azureDir)) {
53 New-Item - ItemType Directory - Path $azureDir | Out-Null
54 }
55 $validateStatusPath = Join-Path - Path $azureDir - ChildPath "validate-status.json"
56 $validateStatusJson = @ { completedStep = $step.ToString() } | ConvertTo-Json
57 [ System.IO.File ]::WriteAllText($validateStatusPath , $validateStatusJson + [ Environment ]::NewLine , ( New-Object System.Text.UTF8Encoding( $false )))
58
59 # Emit the next action based on the step just completed.
60
61 # Step 1: Load Plan
62 if ($step -eq [ ValidationStep ]::None) {
63 Write-Output 'Action: Read `.azure/deployment-plan.md` for recipe and configuration. If missing, run azure-prepare first, then come back to workflow.ps1.'
64 Write-Output "Next: re-run workflow.ps1 with -CompletedStep LoadPlan after completing the action."
65 Write-Output 'Reference: `.azure/deployment-plan.md'
66 exit 0
67 }
68
69 # Step 2: Add Validation Steps
70 if ($step -eq [ ValidationStep ]::LoadPlan) {
71 Write-Output 'Action: Copy the recipe '' s `Validation Steps` into `.azure/deployment-plan.md` as children of `All validation checks pass`.'
72 Write-Output "Next: re-run workflow.ps1 with -CompletedStep AddValidationSteps after completing the action."
73 Write-Output 'Reference: references/recipes/README.md, `.azure/deployment-plan.md'
74 exit 0
75 }
76
77 # Step 3: Run Validation
78 if ($step -eq [ ValidationStep ]::AddValidationSteps) {
79 Write-Output "Action: Execute the recipe-specific validation commands."
80 Write-Output "Next: re-run workflow.ps1 with -CompletedStep RunValidation after completing the action."
81 Write-Output "Reference: references/recipes/README.md"
82 exit 0
83 }
84
85 # Step 4: Build Verification
86 if ($step -eq [ ValidationStep ]::RunValidation) {
87 Write-Output "Action: Build the project and fix any errors before proceeding."
88 Write-Output "Next: re-run workflow.ps1 with -CompletedStep BuildVerification after completing the action."
89 Write-Output "Reference: See the recipe for build details."
90 exit 0
91 }
92
93 # Step 5: Static Role Verification
94 if ($step -eq [ ValidationStep ]::BuildVerification) {
95 Write-Output "Action: Review the Bicep/Terraform for correct RBAC role assignments in code."
96 Write-Output "Next: re-run workflow.ps1 with -CompletedStep StaticRoleVerification after completing the action."
97 Write-Output "Reference: references/role-verification.md"
98 exit 0
99 }
100
101 # Step 6: Record Proof
102 if ($step -eq [ ValidationStep ]::StaticRoleVerification) {
103 Write-Output "Action: Populate **Section 7: Validation Proof** in the plan with the commands run and their results."
104 Write-Output "Next: re-run workflow.ps1 with -CompletedStep RecordProof after completing the action."
105 Write-Output 'Reference: `.azure/deployment-plan.md'
106 exit 0
107 }
108
109 # Step 7: Resolve Errors
110 if ($step -eq [ ValidationStep ]::RecordProof) {
111 Write-Output "Action: Fix any validation failures before proceeding."
112 Write-Output "Next: re-run workflow.ps1 with -CompletedStep ResolveErrors after completing the action."
113 Write-Output "Reference: See the recipe's errors.md."
114 exit 0
115 }
116
117 # Step 8: Update Status
118 if ($step -eq [ ValidationStep ]::ResolveErrors) {
119 Write-Output 'Action: Only after ALL checks pass, set the plan status to `Validated`.'
120 Write-Output "Next: re-run workflow.ps1 with -CompletedStep UpdateStatus after completing the action."
121 Write-Output 'Reference: `.azure/deployment-plan.md'
122 exit 0
123 }
124
125 # Step 9: Deploy (workflow complete)
126 if ($step -eq [ ValidationStep ]::UpdateStatus) {
127 Write-Output "Action: The azure-validate workflow is complete. If the user explicitly requested deployment, invoke azure-deploy. Otherwise STOP and report the validation results."
128 exit 0
129 }