Skip to content

Commit 78d0731

Browse files
author
Harmanpreet Kaur
committed
edited deployment files
1 parent b41fbe0 commit 78d0731

File tree

2 files changed

+131
-37
lines changed

2 files changed

+131
-37
lines changed
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
name: CI-Validate Deployment-KM-Generic
2+
on:
3+
push:
4+
branches:
5+
6+
- main
7+
- dev
8+
- demo
9+
10+
schedule:
11+
- cron: '0 6,18 * * *' # Runs at 6:00 AM and 6:00 PM GMT
12+
13+
jobs:
14+
deploy:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Checkout Code
18+
uses: actions/checkout@v3
19+
20+
- name: Setup Azure CLI
21+
run: |
22+
curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
23+
az --version # Verify installation
24+
25+
- name: Login to Azure
26+
run: |
27+
az login --service-principal -u ${{ secrets.AZURE_CLIENT_ID }} -p ${{ secrets.AZURE_CLIENT_SECRET }} --tenant ${{ secrets.AZURE_TENANT_ID }}
28+
29+
- name: Install Bicep CLI
30+
run: az bicep install
31+
32+
- name: Generate Resource Group Name
33+
id: generate_rg_name
34+
run: |
35+
echo "Generating a unique resource group name..."
36+
TIMESTAMP=$(date +%Y%m%d%H%M%S)
37+
COMMON_PART="ci-KMGeneric"
38+
UNIQUE_RG_NAME="${COMMON_PART}${TIMESTAMP}"
39+
echo "RESOURCE_GROUP_NAME=${UNIQUE_RG_NAME}" >> $GITHUB_ENV
40+
echo "Generated Resource_GROUP_PREFIX: ${UNIQUE_RG_NAME}"
41+
42+
- name: Create Resource Group
43+
run: |
44+
az group create --name ${{ env.RESOURCE_GROUP_NAME }} --location westeurope
45+
46+
- name: Generate Unique Solution Prefix
47+
id: generate_solution_prefix
48+
run: |
49+
set -e
50+
COMMON_PART="km"
51+
TIMESTAMP=$(date +%s)
52+
UPDATED_TIMESTAMP=$(echo $TIMESTAMP | tail -c 3)
53+
UNIQUE_SOLUTION_PREFIX="${COMMON_PART}${UPDATED_TIMESTAMP}"
54+
echo "SOLUTION_PREFIX=${UNIQUE_SOLUTION_PREFIX}" >> $GITHUB_ENV
55+
echo "Generated SOLUTION_PREFIX: ${UNIQUE_SOLUTION_PREFIX}"
56+
57+
58+
- name: Determine Tag Name Based on Branch
59+
id: determine_tag
60+
run: echo "tagname=${{ github.ref_name == 'main' && 'latest' || github.ref_name == 'dev' && 'dev' || github.ref_name == 'demo' && 'demo' || github.head_ref || 'default' }}" >> $GITHUB_OUTPUT
61+
62+
- name: Deploy Bicep Template
63+
id: deploy
64+
run: |
65+
set -e
66+
az deployment group create \
67+
--resource-group ${{ env.RESOURCE_GROUP_NAME }} \
68+
--template-file Deployment/bicep/main.bicep \
69+
--parameters solutionPrefix=${{ env.SOLUTION_PREFIX }} otherLocation=centralus imageTag=${{ steps.determine_tag.outputs.tagname }}
70+
71+
72+
73+
- name: Send Notification on Failure
74+
if: failure()
75+
run: |
76+
RUN_URL="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
77+
78+
# Construct the email body
79+
EMAIL_BODY=$(cat <<EOF
80+
{
81+
"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>"
82+
}
83+
EOF
84+
)
85+
86+
# Send the notification
87+
curl -X POST "${{ secrets.LOGIC_APP_URL }}" \
88+
-H "Content-Type: application/json" \
89+
-d "$EMAIL_BODY" || echo "Failed to send notification"
90+
91+
92+
- name: Delete Bicep Deployment
93+
94+
run: |
95+
set -e
96+
echo "Checking if resource group exists..."
97+
rg_exists=$(az group exists --name ${{ env.RESOURCE_GROUP_NAME }})
98+
if [ "$rg_exists" = "true" ]; then
99+
echo "Resource group exist. Cleaning..."
100+
az group delete \
101+
--name ${{ env.RESOURCE_GROUP_NAME }} \
102+
--yes \
103+
--no-wait
104+
echo "Resource group deleted... ${{ env.RESOURCE_GROUP_NAME }}"
105+
else
106+
echo "Resource group does not exists."
107+
fi
108+

.github/workflows/deploy.yml

Lines changed: 23 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
1-
name: CI-Validate Deployment-KM-Generic
1+
name: CI-Validate Deployment-CKM-V2
22
on:
33
push:
44
branches:
5+
- ckm-v2
56

6-
- main
7-
- dev
8-
- demo
9-
10-
schedule:
11-
- cron: '0 6,18 * * *' # Runs at 6:00 AM and 6:00 PM GMT
127

138
jobs:
149
deploy:
@@ -34,41 +29,51 @@ jobs:
3429
run: |
3530
echo "Generating a unique resource group name..."
3631
TIMESTAMP=$(date +%Y%m%d%H%M%S)
37-
COMMON_PART="ci-KMGeneric"
32+
COMMON_PART="ci-ckmv2"
3833
UNIQUE_RG_NAME="${COMMON_PART}${TIMESTAMP}"
3934
echo "RESOURCE_GROUP_NAME=${UNIQUE_RG_NAME}" >> $GITHUB_ENV
4035
echo "Generated Resource_GROUP_PREFIX: ${UNIQUE_RG_NAME}"
4136
4237
- name: Create Resource Group
4338
run: |
44-
az group create --name ${{ env.RESOURCE_GROUP_NAME }} --location westeurope
39+
az group create --name ${{ env.RESOURCE_GROUP_NAME }} --location eastus
4540
4641
- name: Generate Unique Solution Prefix
4742
id: generate_solution_prefix
4843
run: |
4944
set -e
50-
COMMON_PART="km"
45+
COMMON_PART="ckm2"
5146
TIMESTAMP=$(date +%s)
5247
UPDATED_TIMESTAMP=$(echo $TIMESTAMP | tail -c 3)
5348
UNIQUE_SOLUTION_PREFIX="${COMMON_PART}${UPDATED_TIMESTAMP}"
5449
echo "SOLUTION_PREFIX=${UNIQUE_SOLUTION_PREFIX}" >> $GITHUB_ENV
5550
echo "Generated SOLUTION_PREFIX: ${UNIQUE_SOLUTION_PREFIX}"
5651
57-
58-
- name: Determine Tag Name Based on Branch
59-
id: determine_tag
60-
run: echo "tagname=${{ github.ref_name == 'main' && 'latest' || github.ref_name == 'dev' && 'dev' || github.ref_name == 'demo' && 'demo' || github.head_ref || 'default' }}" >> $GITHUB_OUTPUT
61-
6252
- name: Deploy Bicep Template
6353
id: deploy
6454
run: |
6555
set -e
6656
az deployment group create \
6757
--resource-group ${{ env.RESOURCE_GROUP_NAME }} \
6858
--template-file Deployment/bicep/main.bicep \
69-
--parameters solutionPrefix=${{ env.SOLUTION_PREFIX }} otherLocation=centralus imageTag=${{ steps.determine_tag.outputs.tagname }}
59+
--parameters solutionPrefix=${{ env.SOLUTION_PREFIX }} location=eastus
7060
71-
61+
- name: Delete Bicep Deployment
62+
if: success()
63+
run: |
64+
set -e
65+
echo "Checking if resource group exists..."
66+
rg_exists=$(az group exists --name ${{ env.RESOURCE_GROUP_NAME }})
67+
if [ "$rg_exists" = "true" ]; then
68+
echo "Resource group exist. Cleaning..."
69+
az group delete \
70+
--name ${{ env.RESOURCE_GROUP_NAME }} \
71+
--yes \
72+
--no-wait
73+
echo "Resource group deleted... ${{ env.RESOURCE_GROUP_NAME }}"
74+
else
75+
echo "Resource group does not exists."
76+
fi
7277
7378
- name: Send Notification on Failure
7479
if: failure()
@@ -86,23 +91,4 @@ jobs:
8691
# Send the notification
8792
curl -X POST "${{ secrets.LOGIC_APP_URL }}" \
8893
-H "Content-Type: application/json" \
89-
-d "$EMAIL_BODY" || echo "Failed to send notification"
90-
91-
92-
- name: Delete Bicep Deployment
93-
94-
run: |
95-
set -e
96-
echo "Checking if resource group exists..."
97-
rg_exists=$(az group exists --name ${{ env.RESOURCE_GROUP_NAME }})
98-
if [ "$rg_exists" = "true" ]; then
99-
echo "Resource group exist. Cleaning..."
100-
az group delete \
101-
--name ${{ env.RESOURCE_GROUP_NAME }} \
102-
--yes \
103-
--no-wait
104-
echo "Resource group deleted... ${{ env.RESOURCE_GROUP_NAME }}"
105-
else
106-
echo "Resource group does not exists."
107-
fi
108-
94+
-d "$EMAIL_BODY" || echo "Failed to send notification"

0 commit comments

Comments
 (0)