Skip to content

Commit 4abbe20

Browse files
Add Bicep parameter validation workflow and script
1 parent 5517013 commit 4abbe20

2 files changed

Lines changed: 534 additions & 0 deletions

File tree

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
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+
- 'Deployment/validate_bicep_params.py'
17+
workflow_dispatch:
18+
push:
19+
branches:
20+
- hb-psl-38859
21+
22+
env:
23+
accelerator_name: "DKM"
24+
25+
jobs:
26+
validate:
27+
runs-on: ubuntu-latest
28+
steps:
29+
- name: Checkout Code
30+
uses: actions/checkout@v4
31+
32+
- name: Set up Python
33+
uses: actions/setup-python@v5
34+
with:
35+
python-version: '3.11'
36+
37+
- name: Validate infra/ parameters
38+
id: validate_infra
39+
continue-on-error: true
40+
run: |
41+
set +e
42+
python Deployment/validate_bicep_params.py --dir infra --strict --no-color --json-output infra_results.json 2>&1 | tee infra_output.txt
43+
EXIT_CODE=${PIPESTATUS[0]}
44+
set -e
45+
echo "## Infra Param Validation" >> "$GITHUB_STEP_SUMMARY"
46+
echo '```' >> "$GITHUB_STEP_SUMMARY"
47+
cat infra_output.txt >> "$GITHUB_STEP_SUMMARY"
48+
echo '```' >> "$GITHUB_STEP_SUMMARY"
49+
exit $EXIT_CODE
50+
51+
- name: Set overall result
52+
id: result
53+
run: |
54+
if [[ "${{ steps.validate_infra.outcome }}" == "failure" ]]; then
55+
echo "status=failure" >> "$GITHUB_OUTPUT"
56+
else
57+
echo "status=success" >> "$GITHUB_OUTPUT"
58+
fi
59+
60+
- name: Upload validation results
61+
if: always()
62+
uses: actions/upload-artifact@v4
63+
with:
64+
name: bicep-validation-results
65+
path: |
66+
infra_results.json
67+
retention-days: 30
68+
69+
- name: Send schedule notification on failure
70+
if: steps.result.outputs.status == 'failure'
71+
env:
72+
LOGICAPP_URL: ${{ secrets.EMAILNOTIFICATION_LOGICAPP_URL_TA }}
73+
GITHUB_REPOSITORY: ${{ github.repository }}
74+
GITHUB_RUN_ID: ${{ github.run_id }}
75+
ACCELERATOR_NAME: ${{ env.accelerator_name }}
76+
run: |
77+
RUN_URL="https://github.com/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}"
78+
INFRA_OUTPUT=$(sed 's/&/\&amp;/g; s/</\&lt;/g; s/>/\&gt;/g' infra_output.txt)
79+
80+
jq -n \
81+
--arg name "${ACCELERATOR_NAME}" \
82+
--arg infra "$INFRA_OUTPUT" \
83+
--arg url "$RUN_URL" \
84+
'{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>")}' \
85+
| curl -X POST "${LOGICAPP_URL}" \
86+
-H "Content-Type: application/json" \
87+
-d @- || echo "Failed to send notification"
88+
89+
- name: Send schedule notification on success
90+
if: steps.result.outputs.status == 'success'
91+
env:
92+
LOGICAPP_URL: ${{ secrets.EMAILNOTIFICATION_LOGICAPP_URL_TA }}
93+
GITHUB_REPOSITORY: ${{ github.repository }}
94+
GITHUB_RUN_ID: ${{ github.run_id }}
95+
ACCELERATOR_NAME: ${{ env.accelerator_name }}
96+
run: |
97+
RUN_URL="https://github.com/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}"
98+
INFRA_OUTPUT=$(sed 's/&/\&amp;/g; s/</\&lt;/g; s/>/\&gt;/g' infra_output.txt)
99+
100+
jq -n \
101+
--arg name "${ACCELERATOR_NAME}" \
102+
--arg infra "$INFRA_OUTPUT" \
103+
--arg url "$RUN_URL" \
104+
'{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>")}' \
105+
| curl -X POST "${LOGICAPP_URL}" \
106+
-H "Content-Type: application/json" \
107+
-d @- || echo "Failed to send notification"
108+
109+
- name: Fail if errors found
110+
if: steps.result.outputs.status == 'failure'
111+
run: exit 1

0 commit comments

Comments
 (0)