Skip to content

Commit 6cc781d

Browse files
uncommented the send notification
1 parent fd26edd commit 6cc781d

File tree

2 files changed

+194
-194
lines changed

2 files changed

+194
-194
lines changed

.github/workflows/deploy.yml

Lines changed: 157 additions & 157 deletions
Original file line numberDiff line numberDiff line change
@@ -225,160 +225,160 @@ jobs:
225225
MACAE_CONTAINER_APP: ${{ needs.deploy.outputs.CONTAINER_APP }}
226226
secrets: inherit
227227

228-
# cleanup-deployment:
229-
# if: always() && needs.deploy.outputs.RESOURCE_GROUP_NAME != ''
230-
# needs: [deploy, e2e-test]
231-
# runs-on: ubuntu-latest
232-
# env:
233-
# RESOURCE_GROUP_NAME: ${{ needs.deploy.outputs.RESOURCE_GROUP_NAME }}
234-
# steps:
235-
# - name: Setup Azure CLI
236-
# run: |
237-
# curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
238-
# az --version
239-
# - name: Login to Azure
240-
# run: |
241-
# az login --service-principal -u ${{ secrets.AZURE_CLIENT_ID }} -p ${{ secrets.AZURE_CLIENT_SECRET }} --tenant ${{ secrets.AZURE_TENANT_ID }}
242-
# az account set --subscription "${{ secrets.AZURE_SUBSCRIPTION_ID }}"
243-
244-
# - name: Extract AI Services and Key Vault Names
245-
# if: always()
246-
# run: |
247-
# echo "Fetching AI Services and Key Vault names before deletion..."
248-
249-
# # Get Key Vault name
250-
# KEYVAULT_NAME=$(az resource list --resource-group "${{ env.RESOURCE_GROUP_NAME }}" --resource-type "Microsoft.KeyVault/vaults" --query "[].name" -o tsv)
251-
# echo "Detected Key Vault: $KEYVAULT_NAME"
252-
# echo "KEYVAULT_NAME=$KEYVAULT_NAME" >> $GITHUB_ENV
253-
# # Extract AI Services names
254-
# echo "Fetching AI Services..."
255-
# AI_SERVICES=$(az resource list --resource-group '${{ env.RESOURCE_GROUP_NAME }}' --resource-type "Microsoft.CognitiveServices/accounts" --query "[].name" -o tsv)
256-
# # Flatten newline-separated values to space-separated
257-
# AI_SERVICES=$(echo "$AI_SERVICES" | paste -sd ' ' -)
258-
# echo "Detected AI Services: $AI_SERVICES"
259-
# echo "AI_SERVICES=$AI_SERVICES" >> $GITHUB_ENV
260-
261-
# - name: Get OpenAI Resource from Resource Group
262-
# id: get_openai_resource
263-
# run: |
264-
265-
# set -e
266-
# echo "Fetching OpenAI resource from resource group ${{ env.RESOURCE_GROUP_NAME }}..."
267-
268-
# # Run the az resource list command to get the OpenAI resource name
269-
# openai_resource_name=$(az resource list --resource-group ${{ env.RESOURCE_GROUP_NAME }} --resource-type "Microsoft.CognitiveServices/accounts" --query "[0].name" -o tsv)
270-
271-
# if [ -z "$openai_resource_name" ]; then
272-
# echo "No OpenAI resource found in resource group ${{ env.RESOURCE_GROUP_NAME }}."
273-
# exit 0
274-
# else
275-
# echo "OPENAI_RESOURCE_NAME=${openai_resource_name}" >> $GITHUB_ENV
276-
# echo "OpenAI resource name: ${openai_resource_name}"
277-
# fi
278-
279-
# - name: Delete Bicep Deployment
280-
# if: always()
281-
# run: |
282-
# set -e
283-
# echo "Checking if resource group exists..."
284-
# rg_exists=$(az group exists --name ${{ env.RESOURCE_GROUP_NAME }})
285-
# if [ "$rg_exists" = "true" ]; then
286-
# echo "Resource group exist. Cleaning..."
287-
# az group delete \
288-
# --name ${{ env.RESOURCE_GROUP_NAME }} \
289-
# --yes \
290-
# --no-wait
291-
# echo "Resource group deleted... ${{ env.RESOURCE_GROUP_NAME }}"
292-
# else
293-
# echo "Resource group does not exists."
294-
# fi
295-
296-
# - name: Wait for resource deletion to complete
297-
# run: |
298-
299-
# # Add resources to the array
300-
# resources_to_check=("${{ env.OPENAI_RESOURCE_NAME }}")
301-
302-
# echo "List of resources to check: ${resources_to_check[@]}"
303-
304-
# # Maximum number of retries
305-
# max_retries=3
306-
307-
# # Retry intervals in seconds (30, 60, 120)
308-
# retry_intervals=(30 60 120)
309-
310-
# # Retry mechanism to check resources
311-
# retries=0
312-
# while true; do
313-
# resource_found=false
314-
315-
# # Get the list of resources in YAML format again on each retry
316-
# resource_list=$(az resource list --resource-group ${{ env.RESOURCE_GROUP_NAME }} --output yaml)
317-
318-
# # Iterate through the resources to check
319-
# for resource in "${resources_to_check[@]}"; do
320-
# echo "Checking resource: $resource"
321-
# if echo "$resource_list" | grep -q "name: $resource"; then
322-
# echo "Resource '$resource' exists in the resource group."
323-
# resource_found=true
324-
# else
325-
# echo "Resource '$resource' does not exist in the resource group."
326-
# fi
327-
# done
328-
329-
# # If any resource exists, retry
330-
# if [ "$resource_found" = true ]; then
331-
# retries=$((retries + 1))
332-
# if [ "$retries" -gt "$max_retries" ]; then
333-
# echo "Maximum retry attempts reached. Exiting."
334-
# break
335-
# else
336-
# # Wait for the appropriate interval for the current retry
337-
# echo "Waiting for ${retry_intervals[$retries-1]} seconds before retrying..."
338-
# sleep ${retry_intervals[$retries-1]}
339-
# fi
340-
# else
341-
# echo "No resources found. Exiting."
342-
# break
343-
# fi
344-
# done
345-
346-
# - name: Purging the Resources
347-
# if: always()
348-
# run: |
349-
350-
# set -e
351-
# echo "Azure OpenAI: ${{ env.OPENAI_RESOURCE_NAME }}"
352-
353-
# # Purge OpenAI Resource
354-
# echo "Purging the OpenAI Resource..."
355-
# if ! az resource delete --ids /subscriptions/${{ secrets.AZURE_SUBSCRIPTION_ID }}/providers/Microsoft.CognitiveServices/locations/eastus/resourceGroups/${{ env.RESOURCE_GROUP_NAME }}/deletedAccounts/${{ env.OPENAI_RESOURCE_NAME }} --verbose; then
356-
# echo "Failed to purge openai resource: ${{ env.OPENAI_RESOURCE_NAME }}"
357-
# else
358-
# echo "Purged the openai resource: ${{ env.OPENAI_RESOURCE_NAME }}"
359-
# fi
360-
361-
# echo "Resource purging completed successfully"
362-
363-
# - name: Send Notification on Failure
364-
#
365-
# run: |
366-
# RUN_URL="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
367-
368-
# # Construct the email body
369-
# EMAIL_BODY=$(cat <<EOF
370-
# {
371-
# "body": "<p>Dear Team,</p><p>We would like to inform you that the Multi-Agent-Custom-Automation-Engine-Solution-Accelerator 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>"
372-
# }
373-
# EOF
374-
# )
375-
376-
# # Send the notification
377-
# curl -X POST "${{ secrets.LOGIC_APP_URL }}" \
378-
# -H "Content-Type: application/json" \
379-
# -d "$EMAIL_BODY" || echo "Failed to send notification"
380-
# - name: Logout from Azure
381-
# if: always()
382-
# run: |
383-
# az logout
384-
# echo "Logged out from Azure."
228+
cleanup-deployment:
229+
if: always() && needs.deploy.outputs.RESOURCE_GROUP_NAME != ''
230+
needs: [deploy, e2e-test]
231+
runs-on: ubuntu-latest
232+
env:
233+
RESOURCE_GROUP_NAME: ${{ needs.deploy.outputs.RESOURCE_GROUP_NAME }}
234+
steps:
235+
- name: Setup Azure CLI
236+
run: |
237+
curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
238+
az --version
239+
- name: Login to Azure
240+
run: |
241+
az login --service-principal -u ${{ secrets.AZURE_CLIENT_ID }} -p ${{ secrets.AZURE_CLIENT_SECRET }} --tenant ${{ secrets.AZURE_TENANT_ID }}
242+
az account set --subscription "${{ secrets.AZURE_SUBSCRIPTION_ID }}"
243+
244+
- name: Extract AI Services and Key Vault Names
245+
if: always()
246+
run: |
247+
echo "Fetching AI Services and Key Vault names before deletion..."
248+
249+
# Get Key Vault name
250+
KEYVAULT_NAME=$(az resource list --resource-group "${{ env.RESOURCE_GROUP_NAME }}" --resource-type "Microsoft.KeyVault/vaults" --query "[].name" -o tsv)
251+
echo "Detected Key Vault: $KEYVAULT_NAME"
252+
echo "KEYVAULT_NAME=$KEYVAULT_NAME" >> $GITHUB_ENV
253+
# Extract AI Services names
254+
echo "Fetching AI Services..."
255+
AI_SERVICES=$(az resource list --resource-group '${{ env.RESOURCE_GROUP_NAME }}' --resource-type "Microsoft.CognitiveServices/accounts" --query "[].name" -o tsv)
256+
# Flatten newline-separated values to space-separated
257+
AI_SERVICES=$(echo "$AI_SERVICES" | paste -sd ' ' -)
258+
echo "Detected AI Services: $AI_SERVICES"
259+
echo "AI_SERVICES=$AI_SERVICES" >> $GITHUB_ENV
260+
261+
- name: Get OpenAI Resource from Resource Group
262+
id: get_openai_resource
263+
run: |
264+
265+
set -e
266+
echo "Fetching OpenAI resource from resource group ${{ env.RESOURCE_GROUP_NAME }}..."
267+
268+
# Run the az resource list command to get the OpenAI resource name
269+
openai_resource_name=$(az resource list --resource-group ${{ env.RESOURCE_GROUP_NAME }} --resource-type "Microsoft.CognitiveServices/accounts" --query "[0].name" -o tsv)
270+
271+
if [ -z "$openai_resource_name" ]; then
272+
echo "No OpenAI resource found in resource group ${{ env.RESOURCE_GROUP_NAME }}."
273+
exit 0
274+
else
275+
echo "OPENAI_RESOURCE_NAME=${openai_resource_name}" >> $GITHUB_ENV
276+
echo "OpenAI resource name: ${openai_resource_name}"
277+
fi
278+
279+
- name: Delete Bicep Deployment
280+
if: always()
281+
run: |
282+
set -e
283+
echo "Checking if resource group exists..."
284+
rg_exists=$(az group exists --name ${{ env.RESOURCE_GROUP_NAME }})
285+
if [ "$rg_exists" = "true" ]; then
286+
echo "Resource group exist. Cleaning..."
287+
az group delete \
288+
--name ${{ env.RESOURCE_GROUP_NAME }} \
289+
--yes \
290+
--no-wait
291+
echo "Resource group deleted... ${{ env.RESOURCE_GROUP_NAME }}"
292+
else
293+
echo "Resource group does not exists."
294+
fi
295+
296+
- name: Wait for resource deletion to complete
297+
run: |
298+
299+
# Add resources to the array
300+
resources_to_check=("${{ env.OPENAI_RESOURCE_NAME }}")
301+
302+
echo "List of resources to check: ${resources_to_check[@]}"
303+
304+
# Maximum number of retries
305+
max_retries=3
306+
307+
# Retry intervals in seconds (30, 60, 120)
308+
retry_intervals=(30 60 120)
309+
310+
# Retry mechanism to check resources
311+
retries=0
312+
while true; do
313+
resource_found=false
314+
315+
# Get the list of resources in YAML format again on each retry
316+
resource_list=$(az resource list --resource-group ${{ env.RESOURCE_GROUP_NAME }} --output yaml)
317+
318+
# Iterate through the resources to check
319+
for resource in "${resources_to_check[@]}"; do
320+
echo "Checking resource: $resource"
321+
if echo "$resource_list" | grep -q "name: $resource"; then
322+
echo "Resource '$resource' exists in the resource group."
323+
resource_found=true
324+
else
325+
echo "Resource '$resource' does not exist in the resource group."
326+
fi
327+
done
328+
329+
# If any resource exists, retry
330+
if [ "$resource_found" = true ]; then
331+
retries=$((retries + 1))
332+
if [ "$retries" -gt "$max_retries" ]; then
333+
echo "Maximum retry attempts reached. Exiting."
334+
break
335+
else
336+
# Wait for the appropriate interval for the current retry
337+
echo "Waiting for ${retry_intervals[$retries-1]} seconds before retrying..."
338+
sleep ${retry_intervals[$retries-1]}
339+
fi
340+
else
341+
echo "No resources found. Exiting."
342+
break
343+
fi
344+
done
345+
346+
- name: Purging the Resources
347+
if: always()
348+
run: |
349+
350+
set -e
351+
echo "Azure OpenAI: ${{ env.OPENAI_RESOURCE_NAME }}"
352+
353+
# Purge OpenAI Resource
354+
echo "Purging the OpenAI Resource..."
355+
if ! az resource delete --ids /subscriptions/${{ secrets.AZURE_SUBSCRIPTION_ID }}/providers/Microsoft.CognitiveServices/locations/eastus/resourceGroups/${{ env.RESOURCE_GROUP_NAME }}/deletedAccounts/${{ env.OPENAI_RESOURCE_NAME }} --verbose; then
356+
echo "Failed to purge openai resource: ${{ env.OPENAI_RESOURCE_NAME }}"
357+
else
358+
echo "Purged the openai resource: ${{ env.OPENAI_RESOURCE_NAME }}"
359+
fi
360+
361+
echo "Resource purging completed successfully"
362+
363+
- name: Send Notification on Failure
364+
365+
run: |
366+
RUN_URL="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
367+
368+
# Construct the email body
369+
EMAIL_BODY=$(cat <<EOF
370+
{
371+
"body": "<p>Dear Team,</p><p>We would like to inform you that the Multi-Agent-Custom-Automation-Engine-Solution-Accelerator 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>"
372+
}
373+
EOF
374+
)
375+
376+
# Send the notification
377+
curl -X POST "${{ secrets.LOGIC_APP_URL }}" \
378+
-H "Content-Type: application/json" \
379+
-d "$EMAIL_BODY" || echo "Failed to send notification"
380+
- name: Logout from Azure
381+
if: always()
382+
run: |
383+
az logout
384+
echo "Logged out from Azure."

.github/workflows/test-automation.yml

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -150,40 +150,40 @@ jobs:
150150
exit 1
151151
fi
152152
153-
# - name: Send Notification
154-
# if: always()
155-
# run: |
156-
# RUN_URL="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
157-
# REPORT_URL=${{ steps.upload_report.outputs.artifact-url }}
158-
# IS_SUCCESS=${{ steps.test_result.outputs.IS_SUCCESS }}
159-
160-
# if [ "$IS_SUCCESS" = "true" ]; then
161-
# EMAIL_BODY=$(cat <<EOF
162-
# {
163-
# "body": "<p>Dear Team,</p><p>We would like to inform you that the ${{ env.accelerator_name }} Test Automation process has completed successfully.</p><p><strong>Run URL:</strong> <a href=\\"${RUN_URL}\\">${RUN_URL}</a><br></p><p><strong>Test Report:</strong> <a href=\\"${REPORT_URL}\\">${REPORT_URL}</a></p><p>Best regards,<br>Your Automation Team</p>",
164-
# "subject": "${{ env.accelerator_name }} Test Automation - Success"
165-
# }
166-
# EOF
167-
# )
168-
# else
169-
# EMAIL_BODY=$(cat <<EOF
170-
# {
171-
# "body": "<p>Dear Team,</p><p>We would like to inform you that the ${{ env.accelerator_name }} Test Automation process has encountered an issue and has failed to complete successfully.</p><p><strong>Run URL:</strong> <a href=\\"${RUN_URL}\\">${RUN_URL}</a><br></p><p><strong>Test Report:</strong> <a href=\\"${REPORT_URL}\\">${REPORT_URL}</a></p><p>Please investigate the matter at your earliest convenience.</p><p>Best regards,<br>Your Automation Team</p>",
172-
# "subject": "${{ env.accelerator_name }} Test Automation - Failure"
173-
# }
174-
# EOF
175-
# )
176-
# fi
177-
178-
# curl -X POST "${{ secrets.EMAILNOTIFICATION_LOGICAPP_URL_TA }}" \
179-
# -H "Content-Type: application/json" \
180-
# -d "$EMAIL_BODY" || echo "Failed to send notification"
181-
182-
# - name: Stop Container App
183-
# if: always()
184-
# uses: azure/cli@v2
185-
# with:
186-
# azcliversion: "latest"
187-
# inlineScript: |
188-
# az rest -m post -u "/subscriptions/${{ secrets.AZURE_SUBSCRIPTION_ID }}/resourceGroups/${{ env.MACAE_RG }}/providers/Microsoft.App/containerApps/${{ env.MACAE_CONTAINER_APP }}/stop?api-version=2025-01-01"
189-
# az logout
153+
- name: Send Notification
154+
if: always()
155+
run: |
156+
RUN_URL="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
157+
REPORT_URL=${{ steps.upload_report.outputs.artifact-url }}
158+
IS_SUCCESS=${{ steps.test_result.outputs.IS_SUCCESS }}
159+
160+
if [ "$IS_SUCCESS" = "true" ]; then
161+
EMAIL_BODY=$(cat <<EOF
162+
{
163+
"body": "<p>Dear Team,</p><p>We would like to inform you that the ${{ env.accelerator_name }} Test Automation process has completed successfully.</p><p><strong>Run URL:</strong> <a href=\\"${RUN_URL}\\">${RUN_URL}</a><br></p><p><strong>Test Report:</strong> <a href=\\"${REPORT_URL}\\">${REPORT_URL}</a></p><p>Best regards,<br>Your Automation Team</p>",
164+
"subject": "${{ env.accelerator_name }} Test Automation - Success"
165+
}
166+
EOF
167+
)
168+
else
169+
EMAIL_BODY=$(cat <<EOF
170+
{
171+
"body": "<p>Dear Team,</p><p>We would like to inform you that the ${{ env.accelerator_name }} Test Automation process has encountered an issue and has failed to complete successfully.</p><p><strong>Run URL:</strong> <a href=\\"${RUN_URL}\\">${RUN_URL}</a><br></p><p><strong>Test Report:</strong> <a href=\\"${REPORT_URL}\\">${REPORT_URL}</a></p><p>Please investigate the matter at your earliest convenience.</p><p>Best regards,<br>Your Automation Team</p>",
172+
"subject": "${{ env.accelerator_name }} Test Automation - Failure"
173+
}
174+
EOF
175+
)
176+
fi
177+
178+
curl -X POST "${{ secrets.EMAILNOTIFICATION_LOGICAPP_URL_TA }}" \
179+
-H "Content-Type: application/json" \
180+
-d "$EMAIL_BODY" || echo "Failed to send notification"
181+
182+
- name: Stop Container App
183+
if: always()
184+
uses: azure/cli@v2
185+
with:
186+
azcliversion: "latest"
187+
inlineScript: |
188+
az rest -m post -u "/subscriptions/${{ secrets.AZURE_SUBSCRIPTION_ID }}/resourceGroups/${{ env.MACAE_RG }}/providers/Microsoft.App/containerApps/${{ env.MACAE_CONTAINER_APP }}/stop?api-version=2025-01-01"
189+
az logout

0 commit comments

Comments
 (0)