Skip to content

Commit bfd92f8

Browse files
Merge branch 'main' into hotfix
2 parents 5b944d1 + 4655b3c commit bfd92f8

File tree

6 files changed

+212
-11
lines changed

6 files changed

+212
-11
lines changed

.github/workflows/deploy.yml

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,49 @@ jobs:
1414
- name: Checkout Code
1515
uses: actions/checkout@v3
1616

17+
- name: Run Quota Check
18+
id: quota-check
19+
run: |
20+
export AZURE_CLIENT_ID=${{ secrets.AZURE_CLIENT_ID }}
21+
export AZURE_TENANT_ID=${{ secrets.AZURE_TENANT_ID }}
22+
export AZURE_CLIENT_SECRET=${{ secrets.AZURE_CLIENT_SECRET }}
23+
export AZURE_SUBSCRIPTION_ID="${{ secrets.AZURE_SUBSCRIPTION_ID }}"
24+
export GPT_MIN_CAPACITY="50"
25+
export AZURE_REGIONS="${{ vars.AZURE_REGIONS }}"
26+
27+
chmod +x deploy/scripts/checkquota.sh
28+
if ! deploy/scripts/checkquota.sh; then
29+
# If quota check fails due to insufficient quota, set the flag
30+
if grep -q "No region with sufficient quota found" deploy/scripts/checkquota.sh; then
31+
echo "QUOTA_FAILED=true" >> $GITHUB_ENV
32+
fi
33+
exit 1 # Fail the pipeline if any other failure occurs
34+
fi
35+
36+
- name: Send Notification on Quota Failure
37+
if: env.QUOTA_FAILED == 'true'
38+
run: |
39+
RUN_URL="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
40+
EMAIL_BODY=$(cat <<EOF
41+
{
42+
"body": "<p>Dear Team,</p><p>The quota check has failed, and the pipeline cannot proceed.</p><p><strong>Build URL:</strong> ${RUN_URL}</p><p>Please take necessary action.</p><p>Best regards,<br>Your Automation Team</p>"
43+
}
44+
EOF
45+
)
46+
47+
curl -X POST "${{ secrets.AUTO_LOGIC_APP_URL }}" \
48+
-H "Content-Type: application/json" \
49+
-d "$EMAIL_BODY" || echo "Failed to send notification"
50+
51+
- name: Fail Pipeline if Quota Check Fails
52+
if: env.QUOTA_FAILED == 'true'
53+
run: exit 1
54+
55+
- name: Set Deployment Region
56+
run: |
57+
echo "Selected Region: $VALID_REGION"
58+
echo "AZURE_LOCATION=$VALID_REGION" >> $GITHUB_ENV
59+
1760
- name: Setup Azure CLI
1861
run: |
1962
curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
@@ -45,7 +88,7 @@ jobs:
4588
rg_exists=$(az group exists --name ${{ env.RESOURCE_GROUP_NAME }})
4689
if [ "$rg_exists" = "false" ]; then
4790
echo "Resource group does not exist. Creating..."
48-
az group create --name ${{ env.RESOURCE_GROUP_NAME }} --location eastus || { echo "Error creating resource group"; exit 1; }
91+
az group create --name ${{ env.RESOURCE_GROUP_NAME }} --location ${{ env.AZURE_LOCATION }} || { echo "Error creating resource group"; exit 1; }
4992
else
5093
echo "Resource group already exists."
5194
fi
@@ -58,7 +101,7 @@ jobs:
58101
az deployment group create \
59102
--resource-group ${{ env.RESOURCE_GROUP_NAME }} \
60103
--template-file deploy/macae.bicep \
61-
--parameters azureOpenAILocation=eastus cosmosLocation=eastus2
104+
--parameters azureOpenAILocation=${{env.AZURE_LOCATION }} cosmosLocation=${{env.AZURE_LOCATION }}
62105
63106
64107
- name: Send Notification on Failure

.github/workflows/docker-build-and-push.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
uses: docker/setup-buildx-action@v1
3333

3434
- name: Log in to Azure Container Registry
35-
if: ${{ github.event_name == 'push' && (github.ref_name == 'main' || github.ref_name == 'dev' || github.ref_name == 'demo' || github.ref_name == 'hotfix') }}
35+
if: ${{ (github.ref_name == 'main' || github.ref_name == 'dev' || github.ref_name == 'demo' || github.ref_name == 'hotfix') }}
3636
uses: azure/docker-login@v2
3737
with:
3838
login-server: ${{ secrets.ACR_LOGIN_SERVER }}

.github/workflows/stale-bot.yml

Lines changed: 70 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,82 @@
1-
name: 'Stale Bot'
1+
name: "Manage Stale Issues, PRs & Unmerged Branches"
22
on:
33
schedule:
4-
- cron: '0 1 * * *'
5-
4+
- cron: '30 1 * * *' # Runs daily at 1:30 AM UTC
5+
workflow_dispatch: # Allows manual triggering
66
permissions:
77
contents: write
88
issues: write
99
pull-requests: write
10-
1110
jobs:
1211
stale:
1312
runs-on: ubuntu-latest
1413
steps:
15-
- uses: actions/stale@v9
14+
- name: Mark Stale Issues and PRs
15+
uses: actions/stale@v9
1616
with:
17-
stale-issue-message: 'This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 30 days.'
17+
stale-issue-message: "This issue is stale because it has been open 180 days with no activity. Remove stale label or comment, or it will be closed in 30 days."
18+
stale-pr-message: "This PR is stale because it has been open 180 days with no activity. Please update or it will be closed in 30 days."
1819
days-before-stale: 180
19-
days-before-close: 30
20+
days-before-close: 30
21+
exempt-issue-labels: "keep"
22+
exempt-pr-labels: "keep"
23+
cleanup-branches:
24+
runs-on: ubuntu-latest
25+
steps:
26+
- name: Checkout Repository
27+
uses: actions/checkout@v4
28+
with:
29+
fetch-depth: 0 # Fetch full history for accurate branch checks
30+
- name: Fetch All Branches
31+
run: git fetch --all --prune
32+
- name: List Merged Branches With No Activity in Last 3 Months
33+
run: |
34+
35+
echo "Branch Name,Last Commit Date,Committer,Committed In Branch,Action" > merged_branches_report.csv
36+
37+
for branch in $(git for-each-ref --format '%(refname:short) %(committerdate:unix)' refs/remotes/origin | awk -v date=$(date -d '3 months ago' +%s) '$2 < date {print $1}'); do
38+
if [[ "$branch" != "origin/main" && "$branch" != "origin/dev" ]]; then
39+
branch_name=${branch#origin/}
40+
# Ensure the branch exists locally before getting last commit date
41+
git fetch origin "$branch_name" || echo "Could not fetch branch: $branch_name"
42+
last_commit_date=$(git log -1 --format=%ci "origin/$branch_name" || echo "Unknown")
43+
committer_name=$(git log -1 --format=%cn "origin/$branch_name" || echo "Unknown")
44+
committed_in_branch=$(git branch -r --contains "origin/$branch_name" | tr -d ' ' | paste -sd "," -)
45+
echo "$branch_name,$last_commit_date,$committer_name,$committed_in_branch,Delete" >> merged_branches_report.csv
46+
fi
47+
done
48+
- name: List PR Approved and Merged Branches Older Than 30 Days
49+
run: |
50+
51+
for branch in $(gh api repos/${{ github.repository }}/pulls --jq '.[] | select(.merged_at != null and (.base.ref == "main" or .base.ref == "dev")) | select(.merged_at | fromdateiso8601 < (now - 2592000)) | .head.ref'); do
52+
# Ensure the branch exists locally before getting last commit date
53+
git fetch origin "$branch" || echo "Could not fetch branch: $branch"
54+
last_commit_date=$(git log -1 --format=%ci origin/$branch || echo "Unknown")
55+
committer_name=$(git log -1 --format=%cn origin/$branch || echo "Unknown")
56+
committed_in_branch=$(git branch -r --contains "origin/$branch" | tr -d ' ' | paste -sd "," -)
57+
echo "$branch,$last_commit_date,$committer_name,$committed_in_branch,Delete" >> merged_branches_report.csv
58+
done
59+
env:
60+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
61+
- name: List Open PR Branches With No Activity in Last 3 Months
62+
run: |
63+
64+
for branch in $(gh api repos/${{ github.repository }}/pulls --state open --jq '.[] | select(.base.ref == "main" or .base.ref == "dev") | .head.ref'); do
65+
# Ensure the branch exists locally before getting last commit date
66+
git fetch origin "$branch" || echo "Could not fetch branch: $branch"
67+
last_commit_date=$(git log -1 --format=%ci origin/$branch || echo "Unknown")
68+
committer_name=$(git log -1 --format=%cn origin/$branch || echo "Unknown")
69+
if [[ $(date -d "$last_commit_date" +%s) -lt $(date -d '3 months ago' +%s) ]]; then
70+
# If no commit in the last 3 months, mark for deletion
71+
committed_in_branch=$(git branch -r --contains "origin/$branch" | tr -d ' ' | paste -sd "," -)
72+
echo "$branch,$last_commit_date,$committer_name,$committed_in_branch,Delete" >> merged_branches_report.csv
73+
fi
74+
done
75+
env:
76+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
77+
- name: Upload CSV Report of Inactive Branches
78+
uses: actions/upload-artifact@v4
79+
with:
80+
name: merged-branches-report
81+
path: merged_branches_report.csv
82+
retention-days: 30

deploy/scripts/checkquota.sh

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#!/bin/bash
2+
3+
# List of Azure regions to check for quota (update as needed)
4+
IFS=', ' read -ra REGIONS <<< "$AZURE_REGIONS"
5+
6+
SUBSCRIPTION_ID="${AZURE_SUBSCRIPTION_ID}"
7+
GPT_MIN_CAPACITY="${GPT_MIN_CAPACITY}"
8+
AZURE_CLIENT_ID="${AZURE_CLIENT_ID}"
9+
AZURE_TENANT_ID="${AZURE_TENANT_ID}"
10+
AZURE_CLIENT_SECRET="${AZURE_CLIENT_SECRET}"
11+
12+
# Authenticate using Managed Identity
13+
echo "Authentication using Managed Identity..."
14+
if ! az login --service-principal -u "$AZURE_CLIENT_ID" -p "$AZURE_CLIENT_SECRET" --tenant "$AZURE_TENANT_ID"; then
15+
echo "❌ Error: Failed to login using Managed Identity."
16+
exit 1
17+
fi
18+
19+
echo "🔄 Validating required environment variables..."
20+
if [[ -z "$SUBSCRIPTION_ID" || -z "$GPT_MIN_CAPACITY" || -z "$REGIONS" ]]; then
21+
echo "❌ ERROR: Missing required environment variables."
22+
exit 1
23+
fi
24+
25+
echo "🔄 Setting Azure subscription..."
26+
if ! az account set --subscription "$SUBSCRIPTION_ID"; then
27+
echo "❌ ERROR: Invalid subscription ID or insufficient permissions."
28+
exit 1
29+
fi
30+
echo "✅ Azure subscription set successfully."
31+
32+
# Define models and their minimum required capacities
33+
declare -A MIN_CAPACITY=(
34+
["OpenAI.Standard.gpt-4o"]=$GPT_MIN_CAPACITY
35+
)
36+
37+
VALID_REGION=""
38+
for REGION in "${REGIONS[@]}"; do
39+
echo "----------------------------------------"
40+
echo "🔍 Checking region: $REGION"
41+
42+
QUOTA_INFO=$(az cognitiveservices usage list --location "$REGION" --output json)
43+
if [ -z "$QUOTA_INFO" ]; then
44+
echo "⚠️ WARNING: Failed to retrieve quota for region $REGION. Skipping."
45+
continue
46+
fi
47+
48+
INSUFFICIENT_QUOTA=false
49+
for MODEL in "${!MIN_CAPACITY[@]}"; do
50+
MODEL_INFO=$(echo "$QUOTA_INFO" | awk -v model="\"value\": \"$MODEL\"" '
51+
BEGIN { RS="},"; FS="," }
52+
$0 ~ model { print $0 }
53+
')
54+
55+
if [ -z "$MODEL_INFO" ]; then
56+
echo "⚠️ WARNING: No quota information found for model: $MODEL in $REGION. Skipping."
57+
continue
58+
fi
59+
60+
CURRENT_VALUE=$(echo "$MODEL_INFO" | awk -F': ' '/"currentValue"/ {print $2}' | tr -d ',' | tr -d ' ')
61+
LIMIT=$(echo "$MODEL_INFO" | awk -F': ' '/"limit"/ {print $2}' | tr -d ',' | tr -d ' ')
62+
63+
CURRENT_VALUE=${CURRENT_VALUE:-0}
64+
LIMIT=${LIMIT:-0}
65+
66+
CURRENT_VALUE=$(echo "$CURRENT_VALUE" | cut -d'.' -f1)
67+
LIMIT=$(echo "$LIMIT" | cut -d'.' -f1)
68+
69+
AVAILABLE=$((LIMIT - CURRENT_VALUE))
70+
71+
echo "✅ Model: $MODEL | Used: $CURRENT_VALUE | Limit: $LIMIT | Available: $AVAILABLE"
72+
73+
if [ "$AVAILABLE" -lt "${MIN_CAPACITY[$MODEL]}" ]; then
74+
echo "❌ ERROR: $MODEL in $REGION has insufficient quota."
75+
INSUFFICIENT_QUOTA=true
76+
break
77+
fi
78+
done
79+
80+
if [ "$INSUFFICIENT_QUOTA" = false ]; then
81+
VALID_REGION="$REGION"
82+
break
83+
fi
84+
85+
done
86+
87+
if [ -z "$VALID_REGION" ]; then
88+
echo "❌ No region with sufficient quota found. Blocking deployment."
89+
echo "QUOTA_FAILED=true" >> "$GITHUB_ENV"
90+
exit 0
91+
else
92+
echo "✅ Final Region: $VALID_REGION"
93+
echo "VALID_REGION=$VALID_REGION" >> "$GITHUB_ENV"
94+
exit 0
95+
fi

documentation/LocalDeployment.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ The files for the dev container are located in `/.devcontainer/` folder.
8080
```bash
8181
az ad signed-in-user show --query id -o tsv
8282
```
83-
You will also be prompted for locations for Cosmos and Open AI services. This is to allow separate regions where there may be service quota restrictions.
83+
You will also be prompted for locations for Cosmos and OpenAI services. This is to allow separate regions where there may be service quota restrictions.
8484
8585
- **Additional Notes**:
8686
187 KB
Loading

0 commit comments

Comments
 (0)