2020 # Set this to the mainline branch you are using
2121 branches :
2222 - main
23+ pull_request :
24+ # Run when pull requests are opened or updated
25+ branches :
26+ - main
27+
2328# GitHub Actions workflow to deploy to Azure using azd
29+ # Ensure only one deployment runs at a time to prevent conflicts
30+ concurrency :
31+ group : ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
32+ cancel-in-progress : false
2433
2534permissions :
2635 actions : read # Needed for uploading SARIF reports
2736 security-events : write # Needed for uploading SARIF reports
28- id-token : write
37+ id-token : write # Needed for OIDC Authentication
2938 contents : read
3039
3140
3241jobs :
3342 build :
3443 runs-on : ${{ fromJson(vars.ACTIONS_RUNNER_NAME || '["ubuntu-latest"]') }}
3544 env :
36- AZURE_ENV_NAME : ${{ github.event.inputs.azd_environment_name || 'CICD' }}
45+ AZURE_ENV_NAME : ${{ github.event.inputs.azd_environment_name || (github.event_name == 'pull_request' && format('pr-{0}', github.event.pull_request.number)) || 'CICD' }}
3746 AZURE_LOCATION : ${{ github.event.inputs.azure_location || 'eastus' }}
3847
3948 steps :
40- - name : Checkout the branch ${{ github.ref_name }}
41- uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
49+ - name : Checkout code
50+ uses : actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
4251 with :
43- ref : ${{ github.ref_name }}
52+ persist-credentials : false
4453
4554 - name : Install azd
46- uses : Azure/setup-azd@ae0f8b5482eeac61e940f447327d84c73beb8b1e # v2.1 .0
55+ uses : Azure/setup-azd@cf638ffd167fc81e1851241a478a723c05fa9cb3 # v2.2 .0
4756 with :
4857 version : ' 1.20.0' # Specify your desired azd version here
4958
5059 - name : Setup Node.js
51- uses : actions/setup-node@v4
60+ uses : actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0
5261 with :
5362 node-version : ' 18.x'
5463
5564 - name : Install Terraform
5665 uses : hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd # v3.1.2
5766 with :
58- terraform_version : 1.13.3
67+ terraform_version : 1.13.3
5968
6069 - name : Install TFLint
61- uses : terraform-linters/setup-tflint@90f302c255ef959cbfb4bd10581afecdb7ece3e6 # v4.1.1
70+ uses : terraform-linters/setup-tflint@acd1575d3c037258ce5b2dd01379dc49ce24c6b7 # v6.2.0
6271 with :
6372 tflint_version : v0.58.1
6473 github_token : ${{ secrets.GITHUB_TOKEN }} # Used to avoid rate
@@ -113,7 +122,7 @@ jobs:
113122 pac help
114123
115124 - name : Set Up Python
116- uses : actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # 5.6 .0
125+ uses : actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c # 6.0 .0
117126 with :
118127 python-version : " 3.x"
119128
@@ -193,8 +202,8 @@ jobs:
193202 with :
194203 sarif_file : ./checkov-results.sarif/results_sarif.sarif
195204
196- - name : Azd down
197- if : ${{ github.event.inputs.run_azd_down == 'true' }}
205+ - name : Destroy Infrastructure
206+ if : ${{ github.event.inputs.run_azd_down == 'true' || github.event_name == 'pull_request' }}
198207 env :
199208 POWER_PLATFORM_CLIENT_ID : ${{ vars.AZURE_CLIENT_ID }}
200209 POWER_PLATFORM_TENANT_ID : ${{ vars.AZURE_TENANT_ID }}
@@ -212,6 +221,7 @@ jobs:
212221 RS_CONTAINER_NAME : ${{ vars.RS_CONTAINER_NAME }}
213222 RS_RESOURCE_GROUP : ${{ vars.RS_RESOURCE_GROUP }}
214223 RESOURCE_SHARE_USER : ${{ vars.RESOURCE_SHARE_USER }}
224+ RESOURCE_TAGS : ${{ vars.RESOURCE_TAGS }}
215225
216226 shell : bash
217227 run : |
@@ -222,4 +232,26 @@ jobs:
222232 azd env set RESOURCE_TAGS "$RESOURCE_TAGS"
223233
224234 azd env select "$AZURE_ENV_NAME"
225- azd down --no-prompt --force --purge
235+ azd down --no-prompt --force --purge
236+
237+ - name : Purge Soft-Deleted Azure OpenAI Resources
238+ if : ${{ github.event.inputs.run_azd_down == 'true' || github.event_name == 'pull_request' }}
239+ shell : bash
240+ run : |
241+ # Get the OpenAI resource name and location from environment outputs
242+ OPENAI_RESOURCE_NAME=$(azd env get-values --output json | jq -r '.openai_resource_name // empty')
243+ AZURE_REGION=$(azd env get-values --output json | jq -r '.primary_azure_region // empty')
244+ RESOURCE_GROUP=$(azd env get-values --output json | jq -r '.resource_group_name // empty')
245+
246+ # Only attempt to purge if we have the required information
247+ if [[ -n "$OPENAI_RESOURCE_NAME" && -n "$AZURE_REGION" ]]; then
248+ echo "Attempting to purge soft-deleted Azure OpenAI resource: $OPENAI_RESOURCE_NAME in $AZURE_REGION"
249+
250+ # Purge the soft-deleted Cognitive Services account (continue on error if resource not found)
251+ az cognitiveservices account purge \
252+ --location "$AZURE_REGION" \
253+ --resource-group "$RESOURCE_GROUP" \
254+ --name "$OPENAI_RESOURCE_NAME" || echo "Resource may not be in soft-delete state or already purged"
255+ else
256+ echo "OpenAI resource information not found in environment outputs. Skipping purge."
257+ fi
0 commit comments