Skip to content

Commit f4a1665

Browse files
add Bicep parameter validation workflow and script
1 parent 0bbd905 commit f4a1665

2 files changed

Lines changed: 531 additions & 0 deletions

File tree

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

0 commit comments

Comments
 (0)