Skip to content

Commit 151671b

Browse files
2 parents c931adf + 25cfbd9 commit 151671b

File tree

12 files changed

+484
-145
lines changed

12 files changed

+484
-145
lines changed

.github/workflows/bicep_deploy.yml

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

15+
- name: Run Quota Check
16+
id: quota-check
17+
run: |
18+
export AZURE_CLIENT_ID=${{ secrets.AZURE_CLIENT_ID }}
19+
export AZURE_TENANT_ID=${{ secrets.AZURE_TENANT_ID }}
20+
export AZURE_CLIENT_SECRET=${{ secrets.AZURE_CLIENT_SECRET }}
21+
export AZURE_SUBSCRIPTION_ID="${{ secrets.AZURE_SUBSCRIPTION_ID }}"
22+
export GPT_MIN_CAPACITY="30"
23+
export AZURE_REGIONS="${{ vars.AZURE_REGIONS }}"
24+
25+
chmod +x infra/scripts/checkquota_ckmv2.sh
26+
if ! infra/scripts/checkquota_ckmv2.sh; then
27+
# If quota check fails due to insufficient quota, set the flag
28+
if grep -q "No region with sufficient quota found" infra/scripts/checkquota_ckmv2.sh; then
29+
echo "QUOTA_FAILED=true" >> $GITHUB_ENV
30+
fi
31+
exit 1 # Fail the pipeline if any other failure occurs
32+
fi
33+
34+
- name: Send Notification on Quota Failure
35+
if: env.QUOTA_FAILED == 'true'
36+
run: |
37+
RUN_URL="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
38+
EMAIL_BODY=$(cat <<EOF
39+
{
40+
"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>"
41+
}
42+
EOF
43+
)
44+
45+
curl -X POST "${{ secrets.LOGIC_APP_URL }}" \
46+
-H "Content-Type: application/json" \
47+
-d "$EMAIL_BODY" || echo "Failed to send notification"
48+
49+
- name: Fail Pipeline if Quota Check Fails
50+
if: env.QUOTA_FAILED == 'true'
51+
run: exit 1
52+
53+
- name: Set Deployment Region
54+
run: |
55+
echo "Selected Region: $VALID_REGION"
56+
echo "AZURE_LOCATION=$VALID_REGION" >> $GITHUB_ENV
57+
1558
- name: Setup Azure CLI
1659
run: |
1760
curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
@@ -36,7 +79,7 @@ jobs:
3679
3780
- name: Create Resource Group
3881
run: |
39-
az group create --name ${{ env.RESOURCE_GROUP_NAME }} --location eastus
82+
az group create --name ${{ env.RESOURCE_GROUP_NAME }} --location ${{ env.AZURE_LOCATION }}
4083
4184
- name: Generate Unique Solution Prefix
4285
id: generate_solution_prefix
@@ -56,7 +99,7 @@ jobs:
5699
az deployment group create \
57100
--resource-group ${{ env.RESOURCE_GROUP_NAME }} \
58101
--template-file infra/main.bicep \
59-
--parameters solutionPrefix=${{ env.SOLUTION_PREFIX }} location=eastus
102+
--parameters solutionPrefix=${{ env.SOLUTION_PREFIX }} location=${{ env.AZURE_LOCATION }}
60103
61104
- name: Delete Bicep Deployment
62105
if: success()

.github/workflows/deploy-KMGeneric.yml

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,50 @@ jobs:
1919
- name: Checkout Code
2020
uses: actions/checkout@v3
2121

22+
- name: Run Quota Check
23+
id: quota-check
24+
run: |
25+
export AZURE_CLIENT_ID=${{ secrets.AZURE_CLIENT_ID }}
26+
export AZURE_TENANT_ID=${{ secrets.AZURE_TENANT_ID }}
27+
export AZURE_CLIENT_SECRET=${{ secrets.AZURE_CLIENT_SECRET }}
28+
export AZURE_SUBSCRIPTION_ID="${{ secrets.AZURE_SUBSCRIPTION_ID }}"
29+
export GPT_MIN_CAPACITY="100"
30+
export TEXT_EMBEDDING_MIN_CAPACITY="80"
31+
export AZURE_REGIONS="${{ vars.AZURE_REGIONS_KM }}"
32+
33+
chmod +x infra/scripts/checkquota_km.sh
34+
if ! infra/scripts/checkquota_km.sh; then
35+
# If quota check fails due to insufficient quota, set the flag
36+
if grep -q "No region with sufficient quota found" infra/scripts/checkquota_km.sh; then
37+
echo "QUOTA_FAILED=true" >> $GITHUB_ENV
38+
fi
39+
exit 1 # Fail the pipeline if any other failure occurs
40+
fi
41+
42+
- name: Send Notification on Quota Failure
43+
if: env.QUOTA_FAILED == 'true'
44+
run: |
45+
RUN_URL="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
46+
EMAIL_BODY=$(cat <<EOF
47+
{
48+
"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>"
49+
}
50+
EOF
51+
)
52+
53+
curl -X POST "${{ secrets.LOGIC_APP_URL }}" \
54+
-H "Content-Type: application/json" \
55+
-d "$EMAIL_BODY" || echo "Failed to send notification"
56+
57+
- name: Fail Pipeline if Quota Check Fails
58+
if: env.QUOTA_FAILED == 'true'
59+
run: exit 1
60+
61+
- name: Set Deployment Region
62+
run: |
63+
echo "Selected Region: $VALID_REGION"
64+
echo "AZURE_LOCATION=$VALID_REGION" >> $GITHUB_ENV
65+
2266
- name: Setup Azure CLI
2367
run: |
2468
curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
@@ -43,7 +87,7 @@ jobs:
4387
4488
- name: Create Resource Group
4589
run: |
46-
az group create --name ${{ env.RESOURCE_GROUP_NAME }} --location eastus2
90+
az group create --name ${{ env.RESOURCE_GROUP_NAME }} --location ${{ env.AZURE_LOCATION }}
4791
4892
- name: Generate Unique Solution Prefix
4993
id: generate_solution_prefix
@@ -68,7 +112,7 @@ jobs:
68112
az deployment group create \
69113
--resource-group ${{ env.RESOURCE_GROUP_NAME }} \
70114
--template-file infra/main.bicep \
71-
--parameters environmentName=${{env.SOLUTION_PREFIX}} contentUnderstandingLocation="West US" secondaryLocation="eastus2" imageTag=${{ steps.determine_tag.outputs.tagname }}
115+
--parameters environmentName=${{env.SOLUTION_PREFIX}} contentUnderstandingLocation="westus" secondaryLocation="${{ env.AZURE_LOCATION }}" imageTag=${{ steps.determine_tag.outputs.tagname }}
72116
73117

74118
- name: Extract AI Services and Key Vault Names

.github/workflows/stale-bot.yml

Lines changed: 58 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
name: 'Stale Bot'
1+
name: "Manage Stale Issues, PRs & Unmerged Branches"
2+
23
on:
34
schedule:
4-
- cron: '30 1 * * *'
5+
- cron: '30 1 * * *' # Runs daily at 1:30 AM UTC
6+
workflow_dispatch: # Allows manual triggering
57

68
permissions:
79
contents: write
@@ -12,8 +14,60 @@ jobs:
1214
stale:
1315
runs-on: ubuntu-latest
1416
steps:
15-
- uses: actions/stale@v9
17+
- name: Mark Stale Issues and PRs
18+
uses: actions/stale@v9
1619
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.'
20+
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."
21+
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."
1822
days-before-stale: 180
1923
days-before-close: 30
24+
exempt-issue-labels: "keep"
25+
exempt-pr-labels: "keep"
26+
27+
cleanup-branches:
28+
runs-on: ubuntu-latest
29+
steps:
30+
- name: Checkout Repository
31+
uses: actions/checkout@v4
32+
with:
33+
fetch-depth: 0 # Fetch full history for accurate branch checks
34+
35+
- name: Fetch All Branches
36+
run: git fetch --all --prune
37+
38+
- name: Create CSV File
39+
run: echo "Branch,Last Commit Date,Merged Into,Status" > stale-branches-report.csv
40+
41+
- name: Identify & List Stale Merged Branches with No Activity in Last 3 Months
42+
run: |
43+
echo "Checking merged branches with no activity in the last 3 months..."
44+
for branch_info 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","$2}'); do
45+
branch=$(echo $branch_info | cut -d',' -f1)
46+
last_commit_date=$(git log -1 --format=%ci origin/$branch || echo "Unknown")
47+
merged_into=$(git branch -r --contains $branch | grep -E 'origin/main|origin/dev' | awk -F'/' '{print $2}' | tr '\n' ',' | sed 's/,$//')
48+
merged_into=${merged_into:-"Unknown"}
49+
50+
echo "$branch,$last_commit_date,$merged_into,Marked for Deletion" >> stale-branches-report.csv
51+
52+
done
53+
54+
- name: Identify & List PR Approved & Merged Branches (Older Than 30 Days)
55+
run: |
56+
echo "Checking PR branches that were approved and merged more than 30 days ago..."
57+
for branch_info 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, .merged_at, .base.ref] | @csv'); do
58+
branch=$(echo $branch_info | awk -F, '{print $1}' | tr -d '"')
59+
last_commit_date=$(git log -1 --format=%ci origin/$branch || echo "Unknown")
60+
merged_into=$(echo $branch_info | awk -F, '{print $3}' | tr -d '"')
61+
62+
echo "$branch,$last_commit_date,$merged_into,Marked for Deletion" >> stale-branches-report.csv
63+
64+
done
65+
env:
66+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
67+
68+
- name: Upload Stale Branch Report
69+
uses: actions/upload-artifact@v4
70+
with:
71+
name: stale-branches-report
72+
path: stale-branches-report.csv
73+
retention-days: 30

0 commit comments

Comments
 (0)