Skip to content

Commit 4e41258

Browse files
deploy yml file changes for template validation
1 parent 6302ffc commit 4e41258

File tree

1 file changed

+54
-19
lines changed

1 file changed

+54
-19
lines changed

.github/workflows/deploy.yml

Lines changed: 54 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
SELECTED_AI_REGION: ${{ steps.deploy.outputs.selected_ai_region || env.VALID_REGION }}
2525
steps:
2626
- name: Checkout Code
27-
uses: actions/checkout@v3
27+
uses: actions/checkout@v4
2828

2929
- name: Setup Azure CLI
3030
run: |
@@ -38,19 +38,33 @@ jobs:
3838
- name: Run Quota Check
3939
id: quota-check
4040
run: |
41+
set -e
4142
export AZURE_CLIENT_ID=${{ secrets.AZURE_CLIENT_ID }}
4243
export AZURE_TENANT_ID=${{ secrets.AZURE_TENANT_ID }}
43-
export AZURE_CLIENT_SECRET=${{ secrets.AZURE_CLIENT_SECRET }}
44+
export AZURE_CLIENT_SECRET=${{ secrets.AZURE_CLIENT_SECRET }}
4445
export AZURE_SUBSCRIPTION_ID="${{ secrets.AZURE_SUBSCRIPTION_ID }}"
4546
export GPT_MIN_CAPACITY="${{ env.GPT_MIN_CAPACITY }}"
4647
export AZURE_REGIONS="${{ vars.AZURE_REGIONS }}"
4748
chmod +x scripts/checkquota.sh
48-
if ! scripts/checkquota.sh; then
49-
# If quota check fails due to insufficient quota, set the flag
50-
if grep -q "No region with sufficient quota found" scripts/checkquota.sh; then
51-
echo "QUOTA_FAILED=true" >> $GITHUB_ENV
52-
fi
53-
exit 1 # Fail the pipeline if any other failure occurs
49+
echo "Running quota script..."
50+
# Capture stdout & stderr
51+
if ! bash -c './scripts/checkquota.sh' | tee quota.out; then
52+
echo "Quota script exited non-zero." >&2
53+
fi
54+
echo "--- Quota Script Output (truncated) ---"
55+
head -100 quota.out || true
56+
# Parse VALID_REGION if present
57+
REGION_LINE=$(grep -E '^VALID_REGION=' quota.out || true)
58+
if [ -n "$REGION_LINE" ]; then
59+
echo "$REGION_LINE" >> $GITHUB_ENV
60+
echo "Captured $REGION_LINE"
61+
fi
62+
if grep -qi 'No region with sufficient quota found' quota.out; then
63+
echo "QUOTA_FAILED=true" >> $GITHUB_ENV
64+
echo "Quota failure detected: no region with sufficient quota." >&2
65+
fi
66+
if ! grep -q '^VALID_REGION=' quota.out; then
67+
echo "WARNING: VALID_REGION not found; will fallback later." >&2
5468
fi
5569
5670
- name: Send Notification on Quota Failure
@@ -75,6 +89,14 @@ jobs:
7589
- name: Install Bicep CLI
7690
run: az bicep install
7791

92+
- name: Install jq
93+
run: |
94+
if ! command -v jq >/dev/null 2>&1; then
95+
sudo apt-get update -y
96+
sudo apt-get install -y jq
97+
fi
98+
jq --version
99+
78100
- name: Generate Resource Group Name
79101
id: generate_rg_name
80102
run: |
@@ -127,10 +149,14 @@ jobs:
127149
IMAGE_TAG="latest"
128150
fi
129151
130-
EFFECTIVE_AI_REGION="${VALID_REGION:-eastus}"
152+
EFFECTIVE_AI_REGION="${VALID_REGION:-eastus}" # VALID_REGION exported earlier if quota script succeeded
131153
echo "Using AI Deployments Region: $EFFECTIVE_AI_REGION"
132154
echo "selected_ai_region=$EFFECTIVE_AI_REGION" >> $GITHUB_OUTPUT
133155
156+
echo "Resource Group: ${{ env.RESOURCE_GROUP_NAME }} (Created in northcentralus)"
157+
echo "Solution Prefix: ${{ env.SOLUTION_PREFIX }}"
158+
echo "Image Tag: ${IMAGE_TAG}"
159+
134160
az deployment group create \
135161
--name ${{ env.SOLUTION_PREFIX }}-deployment \
136162
--resource-group ${{ env.RESOURCE_GROUP_NAME }} \
@@ -142,26 +168,35 @@ jobs:
142168
capacity=${{ env.GPT_MIN_CAPACITY }} \
143169
imageVersion="${IMAGE_TAG}" \
144170
createdBy="Pipeline"
145-
- name: Assign Contributor role to Service Principal
171+
- name: Assign Contributor role to Service Principal (Idempotent)
146172
if: always()
147173
run: |
148-
echo "Assigning Contributor role to SPN for RG: ${{ env.RESOURCE_GROUP_NAME }}"
149-
az role assignment create \
150-
--assignee ${{ secrets.AZURE_CLIENT_ID }} \
151-
--role "Contributor" \
152-
--scope /subscriptions/${{ secrets.AZURE_SUBSCRIPTION_ID }}/resourceGroups/${{ env.RESOURCE_GROUP_NAME }}
174+
scope=/subscriptions/${{ secrets.AZURE_SUBSCRIPTION_ID }}/resourceGroups/${{ env.RESOURCE_GROUP_NAME }}
175+
echo "Ensuring Contributor role on scope: $scope"
176+
existing=$(az role assignment list --assignee ${{ secrets.AZURE_CLIENT_ID }} --scope "$scope" --query '[0].id' -o tsv || true)
177+
if [ -n "$existing" ]; then
178+
echo "Role assignment already exists: $existing"
179+
else
180+
az role assignment create --assignee ${{ secrets.AZURE_CLIENT_ID }} --role "Contributor" --scope "$scope" || echo "Non-fatal: role assignment create failed (possibly permission or propagation delay)."
181+
fi
153182
154183
155184
- name: Get Deployment Output and extract Values
156185
id: get_output
157186
run: |
158187
set -e
159-
echo "Fetching deployment output..."
188+
echo "Fetching deployment outputs..."
160189
BICEP_OUTPUT=$(az deployment group show --name ${{ env.SOLUTION_PREFIX }}-deployment --resource-group ${{ env.RESOURCE_GROUP_NAME }} --query "properties.outputs" -o json)
161-
echo "Extracting deployment output..."
162-
WEBAPP_URL=$(echo $BICEP_OUTPUT | jq -r '.weB_APP_URL.value')
190+
echo "Raw outputs JSON length: $(echo "$BICEP_OUTPUT" | wc -c)"
191+
# Correct output key is WEB_APP_URL (verified in infra/main.bicep)
192+
WEBAPP_URL=$(echo "$BICEP_OUTPUT" | jq -r '.WEB_APP_URL.value // empty')
193+
if [ -z "$WEBAPP_URL" ]; then
194+
echo "::error::WEB_APP_URL output missing or empty. Full outputs below:" >&2
195+
echo "$BICEP_OUTPUT" >&2
196+
exit 1
197+
fi
163198
echo "WEBAPP_URL=$WEBAPP_URL" >> $GITHUB_OUTPUT
164-
echo "Deployment output: $BICEP_OUTPUT"
199+
echo "Resolved WEB_APP_URL: $WEBAPP_URL"
165200
166201
- name: Logout from Azure
167202
if: always()

0 commit comments

Comments
 (0)