Skip to content

Commit 6587b1f

Browse files
Merge pull request #1 from Roopan-Microsoft/psl-automate-ci
Added Deploy.yml file for validation
2 parents a34670c + c92681f commit 6587b1f

File tree

1 file changed

+92
-0
lines changed

1 file changed

+92
-0
lines changed

.github/workflows/deploy.yml

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

0 commit comments

Comments
 (0)