Skip to content

Commit cfe7180

Browse files
Merge pull request #85 from microsoft/PSL-BUG-17086
fix: Update deploy.yml - Replace solution prefix logic, add createdDate tag and enforce cleanup with always()
2 parents ebe9067 + ef66b67 commit cfe7180

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

.github/workflows/deploy.yml

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ jobs:
7676
echo "Generating a unique resource group name..."
7777
TIMESTAMP=$(date +%Y%m%d%H%M)
7878
# Define the common part and add a "cps-" prefix
79-
COMMON_PART="pslautomation"
79+
COMMON_PART="automation"
8080
UNIQUE_RG_NAME="cps-${COMMON_PART}${TIMESTAMP}"
8181
echo "RESOURCE_GROUP_NAME=${UNIQUE_RG_NAME}" >> $GITHUB_ENV
8282
echo "Generated Resource_GROUP_PREFIX: ${UNIQUE_RG_NAME}"
@@ -89,26 +89,29 @@ jobs:
8989
rg_exists=$(az group exists --name ${{ env.RESOURCE_GROUP_NAME }})
9090
if [ "$rg_exists" = "false" ]; then
9191
echo "Resource group does not exist. Creating..."
92+
93+
# Generate current timestamp in desired format: YYYY-MM-DDTHH:MM:SS.SSSSSSSZ
94+
current_date=$(date -u +"%Y-%m-%dT%H:%M:%S.%7NZ")
9295
az group create --name ${{ env.RESOURCE_GROUP_NAME }} \
9396
--location ${{ env.AZURE_LOCATION }} \
9497
--tags "CreatedBy=Deployment Lifecycle Automation Pipeline" \
9598
"Purpose=Deploying and Cleaning Up Resources for Validation" \
99+
"CreatedDate=$current_date" \
96100
"ApplicationName=Content Processing Accelerator" \
97101
|| { echo "Error creating resource group"; exit 1; }
98102
else
99103
echo "Resource group already exists."
100104
fi
101105
102-
- name: Generate Unique Solution Prefix
103-
id: generate_solution_prefix
106+
- name: Generate Environment Name
107+
id: generate_environment_name
104108
run: |
105109
set -e
106-
COMMON_PART="pslr"
107-
TIMESTAMP=$(date +%s)
108-
UPDATED_TIMESTAMP=$(echo $TIMESTAMP | tail -c 3)
109-
UNIQUE_SOLUTION_PREFIX="${COMMON_PART}${UPDATED_TIMESTAMP}"
110-
echo "SOLUTION_PREFIX=${UNIQUE_SOLUTION_PREFIX}" >> $GITHUB_ENV
111-
echo "Generated SOLUTION_PREFIX: ${UNIQUE_SOLUTION_PREFIX}"
110+
TIMESTAMP_SHORT=$(date +%s | tail -c 5) # Last 4-5 digits of epoch seconds
111+
RANDOM_SUFFIX=$(head /dev/urandom | tr -dc 'a-z0-9' | head -c 8) # 8 random alphanum chars
112+
UNIQUE_ENV_NAME="${TIMESTAMP_SHORT}${RANDOM_SUFFIX}" # Usually ~12-13 chars
113+
echo "ENVIRONMENT_NAME=${UNIQUE_ENV_NAME}" >> $GITHUB_ENV
114+
echo "Generated ENVIRONMENT_NAME: ${UNIQUE_ENV_NAME}"
112115
113116
- name: Deploy Bicep Template
114117
id: deploy
@@ -118,7 +121,7 @@ jobs:
118121
--resource-group ${{ env.RESOURCE_GROUP_NAME }} \
119122
--template-file infra/main.json \
120123
--parameters \
121-
environmentName="${{ env.SOLUTION_PREFIX }}" \
124+
environmentName="${{ env.ENVIRONMENT_NAME }}" \
122125
secondaryLocation="EastUs2" \
123126
contentUnderstandingLocation="WestUS" \
124127
deploymentType="GlobalStandard" \
@@ -134,7 +137,7 @@ jobs:
134137
useLocalBuild="false"
135138
136139
- name: Delete Bicep Deployment
137-
if: success()
140+
if: always() # This ensures that resource group deletion happens regardless of success or failure
138141
run: |
139142
set -e
140143
echo "Checking if resource group exists..."
@@ -151,6 +154,7 @@ jobs:
151154
fi
152155
153156
- name: Wait for Resource Deletion to Complete
157+
if: always()
154158
run: |
155159
echo "Fetching resources in the resource group: ${{ env.RESOURCE_GROUP_NAME }}"
156160
@@ -220,7 +224,7 @@ jobs:
220224
done
221225
222226
- name: Purging the Resources
223-
if: success()
227+
if: always()
224228
run: |
225229
set -e
226230

0 commit comments

Comments
 (0)