Skip to content

Commit 252ead6

Browse files
Merge pull request #172 from microsoft/hb-psl-38859
ci: Add Bicep parameter validation workflow and script
2 parents 4585232 + a03144f commit 252ead6

File tree

4 files changed

+531
-6
lines changed

4 files changed

+531
-6
lines changed
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
name: Validate Bicep Parameters
2+
3+
permissions:
4+
contents: read
5+
6+
on:
7+
schedule:
8+
- cron: '30 6 * * 3' # Wednesday 12:00 PM IST (6:30 AM UTC)
9+
pull_request:
10+
branches:
11+
- main
12+
- dev
13+
paths:
14+
- 'infra/**/*.bicep'
15+
- 'infra/**/*.parameters.json'
16+
- 'scripts/validate_bicep_params.py'
17+
workflow_dispatch:
18+
19+
env:
20+
accelerator_name: "Container Migration"
21+
22+
jobs:
23+
validate:
24+
runs-on: ubuntu-latest
25+
steps:
26+
- name: Checkout Code
27+
uses: actions/checkout@v4
28+
29+
- name: Set up Python
30+
uses: actions/setup-python@v5
31+
with:
32+
python-version: '3.11'
33+
34+
- name: Validate infra/ parameters
35+
id: validate_infra
36+
continue-on-error: true
37+
run: |
38+
set +e
39+
python scripts/validate_bicep_params.py --dir infra --strict --no-color --json-output infra_results.json 2>&1 | tee infra_output.txt
40+
EXIT_CODE=${PIPESTATUS[0]}
41+
set -e
42+
echo "## Infra Param Validation" >> "$GITHUB_STEP_SUMMARY"
43+
echo '```' >> "$GITHUB_STEP_SUMMARY"
44+
cat infra_output.txt >> "$GITHUB_STEP_SUMMARY"
45+
echo '```' >> "$GITHUB_STEP_SUMMARY"
46+
exit $EXIT_CODE
47+
48+
- name: Set overall result
49+
id: result
50+
run: |
51+
if [[ "${{ steps.validate_infra.outcome }}" == "failure" ]]; then
52+
echo "status=failure" >> "$GITHUB_OUTPUT"
53+
else
54+
echo "status=success" >> "$GITHUB_OUTPUT"
55+
fi
56+
57+
- name: Upload validation results
58+
if: always()
59+
uses: actions/upload-artifact@v4
60+
with:
61+
name: bicep-validation-results
62+
path: |
63+
infra_results.json
64+
retention-days: 30
65+
66+
- name: Send schedule notification on failure
67+
if: github.event_name == 'schedule' && steps.result.outputs.status == 'failure'
68+
env:
69+
LOGICAPP_URL: ${{ secrets.EMAILNOTIFICATION_LOGICAPP_URL_TA }}
70+
GITHUB_REPOSITORY: ${{ github.repository }}
71+
GITHUB_RUN_ID: ${{ github.run_id }}
72+
ACCELERATOR_NAME: ${{ env.accelerator_name }}
73+
run: |
74+
RUN_URL="https://github.com/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}"
75+
INFRA_OUTPUT=$(sed 's/&/\&amp;/g; s/</\&lt;/g; s/>/\&gt;/g' infra_output.txt)
76+
77+
jq -n \
78+
--arg name "${ACCELERATOR_NAME}" \
79+
--arg infra "$INFRA_OUTPUT" \
80+
--arg url "$RUN_URL" \
81+
'{subject: ("Bicep Parameter Validation Report - " + $name + " - Issues Detected"), body: ("<p>Dear Team,</p><p>The scheduled <strong>Bicep Parameter Validation</strong> for <strong>" + $name + "</strong> has detected parameter mapping errors.</p><p><strong>infra/ Results:</strong></p><pre>" + $infra + "</pre><p><strong>Run URL:</strong> <a href=\"" + $url + "\">" + $url + "</a></p><p>Please fix the parameter mapping issues at your earliest convenience.</p><p>Best regards,<br>Your Automation Team</p>")}' \
82+
| curl -X POST "${LOGICAPP_URL}" \
83+
-H "Content-Type: application/json" \
84+
-d @- || echo "Failed to send notification"
85+
86+
- name: Send schedule notification on success
87+
if: github.event_name == 'schedule' && steps.result.outputs.status == 'success'
88+
env:
89+
LOGICAPP_URL: ${{ secrets.EMAILNOTIFICATION_LOGICAPP_URL_TA }}
90+
GITHUB_REPOSITORY: ${{ github.repository }}
91+
GITHUB_RUN_ID: ${{ github.run_id }}
92+
ACCELERATOR_NAME: ${{ env.accelerator_name }}
93+
run: |
94+
RUN_URL="https://github.com/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}"
95+
INFRA_OUTPUT=$(sed 's/&/\&amp;/g; s/</\&lt;/g; s/>/\&gt;/g' infra_output.txt)
96+
97+
jq -n \
98+
--arg name "${ACCELERATOR_NAME}" \
99+
--arg infra "$INFRA_OUTPUT" \
100+
--arg url "$RUN_URL" \
101+
'{subject: ("Bicep Parameter Validation Report - " + $name + " - Passed"), body: ("<p>Dear Team,</p><p>The scheduled <strong>Bicep Parameter Validation</strong> for <strong>" + $name + "</strong> has completed successfully. All parameter mappings are valid.</p><p><strong>infra/ Results:</strong></p><pre>" + $infra + "</pre><p><strong>Run URL:</strong> <a href=\"" + $url + "\">" + $url + "</a></p><p>Best regards,<br>Your Automation Team</p>")}' \
102+
| curl -X POST "${LOGICAPP_URL}" \
103+
-H "Content-Type: application/json" \
104+
-d @- || echo "Failed to send notification"
105+
106+
- name: Fail if errors found
107+
if: steps.result.outputs.status == 'failure'
108+
run: exit 1

infra/main.parameters.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88
"location": {
99
"value": "${AZURE_LOCATION}"
1010
},
11-
"secondaryLocation": {
12-
"value": "${AZURE_SECONDARY_LOCATION}"
13-
},
1411
"containerRegistryHost": {
1512
"value": "${AZURE_CONTAINER_REGISTRY_HOST}"
1613
},

infra/main.waf.parameters.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88
"location": {
99
"value": "${AZURE_LOCATION}"
1010
},
11-
"secondaryLocation": {
12-
"value": "${AZURE_SECONDARY_LOCATION}"
13-
},
1411
"containerRegistryHost": {
1512
"value": "${AZURE_CONTAINER_REGISTRY_HOST}"
1613
},

0 commit comments

Comments
 (0)