Skip to content

Commit 18bda3d

Browse files
Merge pull request #137 from Roopan-Microsoft/main
Sync Dev changes to Main branch | CI Pipeline addition to validate Bicep
2 parents fe120c3 + cf8f2d9 commit 18bda3d

File tree

2 files changed

+100
-0
lines changed

2 files changed

+100
-0
lines changed

.github/CODEOWNERS

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Lines starting with '#' are comments.
2+
# Each line is a file pattern followed by one or more owners.
3+
4+
# These owners will be the default owners for everything in the repo.
5+
* @Avijit-Microsoft @Roopan-Microsoft @Prajwal-Microsoft

.github/workflows/deploy.yml

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
name: CI-Validate Deployment
2+
on:
3+
push:
4+
branches:
5+
- main
6+
schedule:
7+
- cron: '0 6,18 * * *' # Runs at 6:00 AM and 6:00 PM GMT
8+
9+
jobs:
10+
deploy:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout Code
14+
uses: actions/checkout@v3
15+
16+
- name: Setup Azure CLI
17+
run: |
18+
curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
19+
az --version # Verify installation
20+
21+
- name: Login to Azure
22+
run: |
23+
az login --service-principal -u ${{ secrets.AZURE_CLIENT_ID }} -p ${{ secrets.AZURE_CLIENT_SECRET }} --tenant ${{ secrets.AZURE_TENANT_ID }}
24+
25+
- name: Install Bicep CLI
26+
run: az bicep install
27+
28+
- name: Generate Resource Group Name
29+
id: generate_rg_name
30+
run: |
31+
echo "Generating a unique resource group name..."
32+
TIMESTAMP=$(date +%Y%m%d%H%M%S)
33+
COMMON_PART="ci-ckmv2"
34+
UNIQUE_RG_NAME="${COMMON_PART}${TIMESTAMP}"
35+
echo "RESOURCE_GROUP_NAME=${UNIQUE_RG_NAME}" >> $GITHUB_ENV
36+
echo "Generated Resource_GROUP_PREFIX: ${UNIQUE_RG_NAME}"
37+
38+
- name: Create Resource Group
39+
run: |
40+
az group create --name ${{ env.RESOURCE_GROUP_NAME }} --location eastus
41+
42+
- name: Generate Unique Solution Prefix
43+
id: generate_solution_prefix
44+
run: |
45+
set -e
46+
COMMON_PART="ckm2"
47+
TIMESTAMP=$(date +%s)
48+
UPDATED_TIMESTAMP=$(echo $TIMESTAMP | tail -c 3)
49+
UNIQUE_SOLUTION_PREFIX="${COMMON_PART}${UPDATED_TIMESTAMP}"
50+
echo "SOLUTION_PREFIX=${UNIQUE_SOLUTION_PREFIX}" >> $GITHUB_ENV
51+
echo "Generated SOLUTION_PREFIX: ${UNIQUE_SOLUTION_PREFIX}"
52+
53+
- name: Deploy Bicep Template
54+
id: deploy
55+
run: |
56+
set -e
57+
az deployment group create \
58+
--resource-group ${{ env.RESOURCE_GROUP_NAME }} \
59+
--template-file Deployment/bicep/main.bicep \
60+
--parameters solutionPrefix=${{ env.SOLUTION_PREFIX }} location=eastus
61+
62+
- name: Delete Bicep Deployment
63+
if: success()
64+
run: |
65+
set -e
66+
echo "Checking if resource group exists..."
67+
rg_exists=$(az group exists --name ${{ env.RESOURCE_GROUP_NAME }})
68+
if [ "$rg_exists" = "true" ]; then
69+
echo "Resource group exist. Cleaning..."
70+
az group delete \
71+
--name ${{ env.RESOURCE_GROUP_NAME }} \
72+
--yes \
73+
--no-wait
74+
echo "Resource group deleted... ${{ env.RESOURCE_GROUP_NAME }}"
75+
else
76+
echo "Resource group does not exists."
77+
fi
78+
79+
- name: Send Notification on Failure
80+
if: failure()
81+
run: |
82+
RUN_URL="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
83+
84+
# Construct the email body
85+
EMAIL_BODY=$(cat <<EOF
86+
{
87+
"body": "<p>Dear Team,</p><p>We would like to inform you that the CKMv2 Automation process has encountered an issue and has failed to complete successfully.</p><p><strong>Build URL:</strong> ${RUN_URL}<br> ${OUTPUT}</p><p>Please investigate the matter at your earliest convenience.</p><p>Best regards,<br>Your Automation Team</p>"
88+
}
89+
EOF
90+
)
91+
92+
# Send the notification
93+
curl -X POST "${{ secrets.LOGIC_APP_URL }}" \
94+
-H "Content-Type: application/json" \
95+
-d "$EMAIL_BODY" || echo "Failed to send notification"

0 commit comments

Comments
 (0)