-
Notifications
You must be signed in to change notification settings - Fork 709
114 lines (105 loc) · 4.11 KB
/
Copy pathjob-cleanup-deployment.yml
File metadata and controls
114 lines (105 loc) · 4.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
name: Cleanup Deployment Job
on:
workflow_call:
inputs:
runner_os:
description: 'Runner OS (ubuntu-latest or windows-latest)'
required: true
type: string
trigger_type:
description: 'Trigger type (workflow_dispatch, pull_request, schedule)'
required: true
type: string
cleanup_resources:
description: 'Cleanup Deployed Resources'
required: false
default: false
type: boolean
existing_webapp_url:
description: 'Existing Container WebApp URL (Skips Deployment)'
required: false
default: ''
type: string
RESOURCE_GROUP_NAME:
description: 'Resource Group Name to cleanup'
required: true
type: string
AZURE_LOCATION:
description: 'Azure Location'
required: true
type: string
AZURE_ENV_AI_SERVICE_LOCATION:
description: 'Azure OpenAI Location'
required: true
type: string
ENV_NAME:
description: 'Environment Name'
required: true
type: string
IMAGE_TAG:
description: 'Docker Image Tag'
required: true
type: string
jobs:
cleanup-deployment:
runs-on: ${{ inputs.runner_os }}
continue-on-error: true
environment: production
env:
RESOURCE_GROUP_NAME: ${{ inputs.RESOURCE_GROUP_NAME }}
AZURE_LOCATION: ${{ inputs.AZURE_LOCATION }}
AZURE_ENV_AI_SERVICE_LOCATION: ${{ inputs.AZURE_ENV_AI_SERVICE_LOCATION }}
ENV_NAME: ${{ inputs.ENV_NAME }}
IMAGE_TAG: ${{ inputs.IMAGE_TAG }}
steps:
- name: Login to Azure
uses: azure/login@v3
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: Set Azure Subscription
shell: bash
run: az account set --subscription ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: Delete Resource Group (Optimized Cleanup)
id: delete_rg
shell: bash
run: |
set -e
echo "🗑️ Starting optimized resource cleanup..."
echo "Deleting resource group: ${{ env.RESOURCE_GROUP_NAME }}"
az group delete \
--name "${{ env.RESOURCE_GROUP_NAME }}" \
--yes \
--no-wait
echo "✅ Resource group deletion initiated (running asynchronously)"
echo "Note: Resources will be cleaned up in the background"
- name: Logout from Azure
if: always()
shell: bash
run: |
azd auth logout || true
az logout || echo "Warning: Failed to logout from Azure CLI"
echo "Logged out from Azure."
- name: Generate Cleanup Job Summary
if: always()
shell: bash
run: |
echo "## 🧹 Cleanup Job Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Field | Value |" >> $GITHUB_STEP_SUMMARY
echo "|-------|--------|" >> $GITHUB_STEP_SUMMARY
echo "| **Resource Group deletion Status** | ${{ steps.delete_rg.outcome == 'success' && '✅ Initiated' || '❌ Failed' }} |" >> $GITHUB_STEP_SUMMARY
echo "| **Resource Group** | \`${{ env.RESOURCE_GROUP_NAME }}\` |" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
if [[ "${{ steps.delete_rg.outcome }}" == "success" ]]; then
echo "### ✅ Cleanup Details" >> $GITHUB_STEP_SUMMARY
echo "- Successfully initiated deletion for Resource Group \`${{ env.RESOURCE_GROUP_NAME }}\`" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
else
echo "### ❌ Cleanup Failed" >> $GITHUB_STEP_SUMMARY
echo "- Cleanup process encountered an error" >> $GITHUB_STEP_SUMMARY
echo "- Manual cleanup may be required for:" >> $GITHUB_STEP_SUMMARY
echo " - Resource Group: \`${{ env.RESOURCE_GROUP_NAME }}\`" >> $GITHUB_STEP_SUMMARY
echo "- Check the cleanup-deployment job logs for detailed error information" >> $GITHUB_STEP_SUMMARY
fi