Skip to content

Commit 2213987

Browse files
Moved Cleanup job below send Notification Job
1 parent 702fbf4 commit 2213987

1 file changed

Lines changed: 115 additions & 115 deletions

File tree

.github/workflows/deploy-v2.yml

Lines changed: 115 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -627,120 +627,6 @@ jobs:
627627
TEST_SUITE: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.run_e2e_tests || 'GoldenPath-Testing' }}
628628
secrets: inherit
629629

630-
cleanup-deployment:
631-
if: always() && needs.deploy.result == 'success' && needs.deploy.outputs.RESOURCE_GROUP_NAME != '' && github.event.inputs.existing_webapp_url == '' && (github.event_name != 'workflow_dispatch' || github.event.inputs.cleanup_resources == 'true' || github.event.inputs.cleanup_resources == null)
632-
needs: [docker-build, deploy, e2e-test]
633-
runs-on: ubuntu-latest
634-
env:
635-
RESOURCE_GROUP_NAME: ${{ needs.deploy.outputs.RESOURCE_GROUP_NAME }}
636-
AZURE_LOCATION: ${{ needs.deploy.outputs.AZURE_LOCATION }}
637-
AZURE_ENV_OPENAI_LOCATION: ${{ needs.deploy.outputs.AZURE_ENV_OPENAI_LOCATION }}
638-
ENV_NAME: ${{ needs.deploy.outputs.ENV_NAME }}
639-
IMAGE_TAG: ${{ needs.deploy.outputs.IMAGE_TAG }}
640-
steps:
641-
- name: Checkout Code
642-
uses: actions/checkout@v4
643-
644-
- name: Setup Azure Developer CLI
645-
run: |
646-
curl -fsSL https://aka.ms/install-azd.sh | sudo bash
647-
azd version
648-
649-
- name: Login to Azure
650-
run: |
651-
azd auth login --client-id ${{ secrets.AZURE_CLIENT_ID }} --client-secret ${{ secrets.AZURE_CLIENT_SECRET }} --tenant-id ${{ secrets.AZURE_TENANT_ID }}
652-
azd config set defaults.subscription ${{ secrets.AZURE_SUBSCRIPTION_ID }}
653-
654-
- name: Setup Azure CLI for Docker cleanup
655-
run: |
656-
curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
657-
az --version
658-
659-
- name: Login to Azure CLI for Docker cleanup
660-
run: |
661-
az login --service-principal -u ${{ secrets.AZURE_CLIENT_ID }} -p ${{ secrets.AZURE_CLIENT_SECRET }} --tenant ${{ secrets.AZURE_TENANT_ID }}
662-
663-
- name: Delete Docker Images from ACR
664-
if: github.event.inputs.existing_webapp_url == ''
665-
run: |
666-
set -e
667-
echo "🗑️ Cleaning up Docker images from Azure Container Registry..."
668-
669-
# Determine the image tag to delete - check if docker-build job ran
670-
if [[ "${{ needs.docker-build.result }}" == "success" ]]; then
671-
IMAGE_TAG="${{ needs.docker-build.outputs.IMAGE_TAG }}"
672-
echo "Using image tag from docker-build job: $IMAGE_TAG"
673-
else
674-
IMAGE_TAG="${{ needs.deploy.outputs.IMAGE_TAG }}"
675-
echo "Using image tag from deploy job: $IMAGE_TAG"
676-
fi
677-
678-
if [[ -n "$IMAGE_TAG" && "$IMAGE_TAG" != "latest" && "$IMAGE_TAG" != "dev" && "$IMAGE_TAG" != "demo" && "$IMAGE_TAG" != "hotfix" && "$IMAGE_TAG" != "dependabotchanges" ]]; then
679-
echo "Deleting Docker images with tag: $IMAGE_TAG"
680-
681-
# Delete the main image
682-
echo "Deleting image: ${{ secrets.ACR_TEST_LOGIN_SERVER }}/webapp:$IMAGE_TAG"
683-
az acr repository delete --name $(echo "${{ secrets.ACR_TEST_LOGIN_SERVER }}" | cut -d'.' -f1) \
684-
--image webapp:$IMAGE_TAG --yes || echo "Warning: Failed to delete main image or image not found"
685-
686-
echo "✅ Docker images cleanup completed"
687-
else
688-
echo "⚠️ Skipping Docker image cleanup (using standard branch image: $IMAGE_TAG)"
689-
fi
690-
691-
- name: Select Environment and Delete deployment using azd
692-
run: |
693-
set -e
694-
# Try to select the environment if it exists, otherwise create a minimal environment for cleanup
695-
azd env list
696-
if azd env list | grep -q "${{ env.ENV_NAME }}"; then
697-
echo "Environment ${{ env.ENV_NAME }} found, selecting it..."
698-
azd env select ${{ env.ENV_NAME }}
699-
else
700-
echo "Environment ${{ env.ENV_NAME }} not found, creating minimal environment for cleanup..."
701-
azd env new ${{ env.ENV_NAME }} --no-prompt
702-
azd env set AZURE_RESOURCE_GROUP "${{ env.RESOURCE_GROUP_NAME }}"
703-
azd env set AZURE_SUBSCRIPTION_ID "${{ secrets.AZURE_SUBSCRIPTION_ID }}"
704-
azd env set AZURE_ENV_AI_DEPLOYMENTS_LOCATION="${{ env.AZURE_ENV_OPENAI_LOCATION }}"
705-
azd env set AZURE_LOCATION="${{ env.AZURE_LOCATION }}"
706-
fi
707-
708-
echo "Deleting deployment..."
709-
azd down --purge --force --no-prompt
710-
echo "Deployment deleted successfully."
711-
712-
- name: Logout from Azure
713-
if: always()
714-
run: |
715-
azd auth logout
716-
az logout || echo "Warning: Failed to logout from Azure CLI"
717-
echo "Logged out from Azure."
718-
719-
- name: Generate Cleanup Job Summary
720-
if: always()
721-
run: |
722-
echo "## 🧹 Cleanup Job Summary" >> $GITHUB_STEP_SUMMARY
723-
echo "" >> $GITHUB_STEP_SUMMARY
724-
echo "| Field | Value |" >> $GITHUB_STEP_SUMMARY
725-
echo "|-------|--------|" >> $GITHUB_STEP_SUMMARY
726-
echo "| **Job Status** | ${{ job.status == 'success' && '✅ Success' || '❌ Failed' }} |" >> $GITHUB_STEP_SUMMARY
727-
echo "| **Resource Group** | \`${{ env.RESOURCE_GROUP_NAME }}\` |" >> $GITHUB_STEP_SUMMARY
728-
echo "| **Azure Region (Infrastructure)** | \`${{ env.AZURE_LOCATION }}\` |" >> $GITHUB_STEP_SUMMARY
729-
echo "| **Azure OpenAI Region** | \`${{ env.AZURE_ENV_OPENAI_LOCATION }}\` |" >> $GITHUB_STEP_SUMMARY
730-
echo "| **Docker Image Tag** | \`${{ env.IMAGE_TAG }}\` |" >> $GITHUB_STEP_SUMMARY
731-
echo "" >> $GITHUB_STEP_SUMMARY
732-
if [[ "${{ job.status }}" == "success" ]]; then
733-
echo "### ✅ Cleanup Details" >> $GITHUB_STEP_SUMMARY
734-
echo "- Successfully deleted Azure deployment using \`azd down --purge\`" >> $GITHUB_STEP_SUMMARY
735-
echo "- Resource group \`${{ env.RESOURCE_GROUP_NAME }}\` and all associated resources removed" >> $GITHUB_STEP_SUMMARY
736-
else
737-
echo "### ❌ Cleanup Failed" >> $GITHUB_STEP_SUMMARY
738-
echo "- Cleanup process encountered an error" >> $GITHUB_STEP_SUMMARY
739-
echo "- Manual cleanup may be required for:" >> $GITHUB_STEP_SUMMARY
740-
echo " - Resource Group: \`${{ env.RESOURCE_GROUP_NAME }}\`" >> $GITHUB_STEP_SUMMARY
741-
echo "- Check the cleanup-deployment job logs for detailed error information" >> $GITHUB_STEP_SUMMARY
742-
fi
743-
744630
send-notification:
745631
if: always()
746632
needs: [docker-build, deploy, e2e-test]
@@ -869,4 +755,118 @@ jobs:
869755
870756
curl -X POST "${{ secrets.EMAILNOTIFICATION_LOGICAPP_URL_TA }}" \
871757
-H "Content-Type: application/json" \
872-
-d "$EMAIL_BODY" || echo "Failed to send existing URL test failure notification"
758+
-d "$EMAIL_BODY" || echo "Failed to send existing URL test failure notification"
759+
760+
cleanup-deployment:
761+
if: always() && needs.deploy.result == 'success' && needs.deploy.outputs.RESOURCE_GROUP_NAME != '' && github.event.inputs.existing_webapp_url == '' && (github.event_name != 'workflow_dispatch' || github.event.inputs.cleanup_resources == 'true' || github.event.inputs.cleanup_resources == null)
762+
needs: [docker-build, deploy, e2e-test]
763+
runs-on: ubuntu-latest
764+
env:
765+
RESOURCE_GROUP_NAME: ${{ needs.deploy.outputs.RESOURCE_GROUP_NAME }}
766+
AZURE_LOCATION: ${{ needs.deploy.outputs.AZURE_LOCATION }}
767+
AZURE_ENV_OPENAI_LOCATION: ${{ needs.deploy.outputs.AZURE_ENV_OPENAI_LOCATION }}
768+
ENV_NAME: ${{ needs.deploy.outputs.ENV_NAME }}
769+
IMAGE_TAG: ${{ needs.deploy.outputs.IMAGE_TAG }}
770+
steps:
771+
- name: Checkout Code
772+
uses: actions/checkout@v4
773+
774+
- name: Setup Azure Developer CLI
775+
run: |
776+
curl -fsSL https://aka.ms/install-azd.sh | sudo bash
777+
azd version
778+
779+
- name: Login to Azure
780+
run: |
781+
azd auth login --client-id ${{ secrets.AZURE_CLIENT_ID }} --client-secret ${{ secrets.AZURE_CLIENT_SECRET }} --tenant-id ${{ secrets.AZURE_TENANT_ID }}
782+
azd config set defaults.subscription ${{ secrets.AZURE_SUBSCRIPTION_ID }}
783+
784+
- name: Setup Azure CLI for Docker cleanup
785+
run: |
786+
curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
787+
az --version
788+
789+
- name: Login to Azure CLI for Docker cleanup
790+
run: |
791+
az login --service-principal -u ${{ secrets.AZURE_CLIENT_ID }} -p ${{ secrets.AZURE_CLIENT_SECRET }} --tenant ${{ secrets.AZURE_TENANT_ID }}
792+
793+
- name: Delete Docker Images from ACR
794+
if: github.event.inputs.existing_webapp_url == ''
795+
run: |
796+
set -e
797+
echo "🗑️ Cleaning up Docker images from Azure Container Registry..."
798+
799+
# Determine the image tag to delete - check if docker-build job ran
800+
if [[ "${{ needs.docker-build.result }}" == "success" ]]; then
801+
IMAGE_TAG="${{ needs.docker-build.outputs.IMAGE_TAG }}"
802+
echo "Using image tag from docker-build job: $IMAGE_TAG"
803+
else
804+
IMAGE_TAG="${{ needs.deploy.outputs.IMAGE_TAG }}"
805+
echo "Using image tag from deploy job: $IMAGE_TAG"
806+
fi
807+
808+
if [[ -n "$IMAGE_TAG" && "$IMAGE_TAG" != "latest" && "$IMAGE_TAG" != "dev" && "$IMAGE_TAG" != "demo" && "$IMAGE_TAG" != "hotfix" && "$IMAGE_TAG" != "dependabotchanges" ]]; then
809+
echo "Deleting Docker images with tag: $IMAGE_TAG"
810+
811+
# Delete the main image
812+
echo "Deleting image: ${{ secrets.ACR_TEST_LOGIN_SERVER }}/webapp:$IMAGE_TAG"
813+
az acr repository delete --name $(echo "${{ secrets.ACR_TEST_LOGIN_SERVER }}" | cut -d'.' -f1) \
814+
--image webapp:$IMAGE_TAG --yes || echo "Warning: Failed to delete main image or image not found"
815+
816+
echo "✅ Docker images cleanup completed"
817+
else
818+
echo "⚠️ Skipping Docker image cleanup (using standard branch image: $IMAGE_TAG)"
819+
fi
820+
821+
- name: Select Environment and Delete deployment using azd
822+
run: |
823+
set -e
824+
# Try to select the environment if it exists, otherwise create a minimal environment for cleanup
825+
azd env list
826+
if azd env list | grep -q "${{ env.ENV_NAME }}"; then
827+
echo "Environment ${{ env.ENV_NAME }} found, selecting it..."
828+
azd env select ${{ env.ENV_NAME }}
829+
else
830+
echo "Environment ${{ env.ENV_NAME }} not found, creating minimal environment for cleanup..."
831+
azd env new ${{ env.ENV_NAME }} --no-prompt
832+
azd env set AZURE_RESOURCE_GROUP "${{ env.RESOURCE_GROUP_NAME }}"
833+
azd env set AZURE_SUBSCRIPTION_ID "${{ secrets.AZURE_SUBSCRIPTION_ID }}"
834+
azd env set AZURE_ENV_AI_DEPLOYMENTS_LOCATION="${{ env.AZURE_ENV_OPENAI_LOCATION }}"
835+
azd env set AZURE_LOCATION="${{ env.AZURE_LOCATION }}"
836+
fi
837+
838+
echo "Deleting deployment..."
839+
azd down --purge --force --no-prompt
840+
echo "Deployment deleted successfully."
841+
842+
- name: Logout from Azure
843+
if: always()
844+
run: |
845+
azd auth logout
846+
az logout || echo "Warning: Failed to logout from Azure CLI"
847+
echo "Logged out from Azure."
848+
849+
- name: Generate Cleanup Job Summary
850+
if: always()
851+
run: |
852+
echo "## 🧹 Cleanup Job Summary" >> $GITHUB_STEP_SUMMARY
853+
echo "" >> $GITHUB_STEP_SUMMARY
854+
echo "| Field | Value |" >> $GITHUB_STEP_SUMMARY
855+
echo "|-------|--------|" >> $GITHUB_STEP_SUMMARY
856+
echo "| **Job Status** | ${{ job.status == 'success' && '✅ Success' || '❌ Failed' }} |" >> $GITHUB_STEP_SUMMARY
857+
echo "| **Resource Group** | \`${{ env.RESOURCE_GROUP_NAME }}\` |" >> $GITHUB_STEP_SUMMARY
858+
echo "| **Azure Region (Infrastructure)** | \`${{ env.AZURE_LOCATION }}\` |" >> $GITHUB_STEP_SUMMARY
859+
echo "| **Azure OpenAI Region** | \`${{ env.AZURE_ENV_OPENAI_LOCATION }}\` |" >> $GITHUB_STEP_SUMMARY
860+
echo "| **Docker Image Tag** | \`${{ env.IMAGE_TAG }}\` |" >> $GITHUB_STEP_SUMMARY
861+
echo "" >> $GITHUB_STEP_SUMMARY
862+
if [[ "${{ job.status }}" == "success" ]]; then
863+
echo "### ✅ Cleanup Details" >> $GITHUB_STEP_SUMMARY
864+
echo "- Successfully deleted Azure deployment using \`azd down --purge\`" >> $GITHUB_STEP_SUMMARY
865+
echo "- Resource group \`${{ env.RESOURCE_GROUP_NAME }}\` and all associated resources removed" >> $GITHUB_STEP_SUMMARY
866+
else
867+
echo "### ❌ Cleanup Failed" >> $GITHUB_STEP_SUMMARY
868+
echo "- Cleanup process encountered an error" >> $GITHUB_STEP_SUMMARY
869+
echo "- Manual cleanup may be required for:" >> $GITHUB_STEP_SUMMARY
870+
echo " - Resource Group: \`${{ env.RESOURCE_GROUP_NAME }}\`" >> $GITHUB_STEP_SUMMARY
871+
echo "- Check the cleanup-deployment job logs for detailed error information" >> $GITHUB_STEP_SUMMARY
872+
fi

0 commit comments

Comments
 (0)