Skip to content

Commit e8991fe

Browse files
committed
feat: run step from a script file
1 parent 3c4d9be commit e8991fe

File tree

2 files changed

+57
-56
lines changed

2 files changed

+57
-56
lines changed

.github/workflows/stage-3-build-images.yaml

Lines changed: 2 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -258,66 +258,12 @@ jobs:
258258
if: github.ref == 'refs/heads/main'
259259
run: az acr login --name ${{ secrets.ACR_NAME }}
260260

261-
- name: Tag All Repositories with new short commit hash
261+
- name: Tag all repositories with new short commit hash
262262
env:
263263
ACR_NAME: ${{ secrets.ACR_NAME }}
264264
SHORT_COMMIT_HASH: ${{ needs.build-and-push.outputs.short_commit_hash }}
265265
ENVIRONMENT_TAG: ${{ inputs.environment_tag }}
266-
267-
run: |
268-
echo "Attempting to tag all repositories in ACR $ACR_NAME with short commit hash: $SHORT_COMMIT_HASH"
269-
echo "Source tag for import will be: $ENVIRONMENT_TAG"
270-
271-
# Get list of repositories
272-
repo_list=$(az acr repository list --name "$ACR_NAME" --output tsv)
273-
274-
if [ -z "$repo_list" ]; then
275-
echo "No repositories found in ACR $ACR_NAME. Nothing to tag."
276-
exit 0
277-
fi
278-
279-
echo "Found repositories: $(echo $repo_list | wc -w)"
280-
echo "---"
281-
282-
exit_code=0
283-
284-
for repo_name in $repo_list; do
285-
source_image="${ACR_NAME}.azurecr.io/${repo_name}:${ENVIRONMENT_TAG}"
286-
target_image="${repo_name}:${SHORT_COMMIT_HASH}"
287-
288-
echo "Processing repository: $repo_name"
289-
290-
echo " Checking for existing target tag: $SHORT_COMMIT_HASH"
291-
target_tag_check_output=$(az acr manifest list-metadata --registry "$ACR_NAME" --name "$repo_name" --query "[?tags.contains(@, '${SHORT_COMMIT_HASH}')]" --output tsv)
292-
target_tag_check_status=$?
293-
294-
if [ $target_tag_check_status -eq 0 ] && [ -n "$target_tag_check_output" ]; then
295-
echo " Target tag '$SHORT_COMMIT_HASH' already exists. Skipping import for this repository."
296-
echo "---"
297-
continue
298-
fi
299-
300-
echo " Proceeding with import attempt: $source_image -> $target_image"
301-
302-
az acr import \
303-
--name "$ACR_NAME" \
304-
--source "$source_image" \
305-
--image "$target_image" \
306-
--force
307-
308-
import_status=$?
309-
310-
if [ $import_status -ne 0 ]; then
311-
echo " ⚠️ Warning: ACR import command failed for repository '$repo_name' (Exit Code: $import_status)."
312-
exit_code=1 # Record import failure
313-
else
314-
echo " Import successful for '$repo_name'."
315-
fi
316-
echo "---"
317-
done
318-
319-
echo "Finished processing all repositories."
320-
exit $exit_code
266+
run: bash ./templates/scripts/deployments/append-commit-hash.sh
321267

322268
aggregate-json:
323269
runs-on: ubuntu-latest
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/bin/bash
2+
3+
echo "Attempting to tag all repositories in ACR $ACR_NAME with short commit hash: $SHORT_COMMIT_HASH"
4+
echo "Source tag for import will be: $ENVIRONMENT_TAG"
5+
6+
# Get list of repositories
7+
repo_list=$(az acr repository list --name "$ACR_NAME" --output tsv)
8+
9+
if [ -z "$repo_list" ]; then
10+
echo "No repositories found in ACR $ACR_NAME. Nothing to tag."
11+
exit 0
12+
fi
13+
14+
echo "Found repositories: $(echo $repo_list | wc -w)"
15+
echo "---"
16+
17+
exit_code=0
18+
19+
for repo_name in $repo_list; do
20+
source_image="${ACR_NAME}.azurecr.io/${repo_name}:${ENVIRONMENT_TAG}"
21+
target_image="${repo_name}:${SHORT_COMMIT_HASH}"
22+
23+
echo "Processing repository: $repo_name"
24+
25+
echo " Checking for existing target tag: $SHORT_COMMIT_HASH"
26+
target_tag_check_output=$(az acr manifest list-metadata --registry "$ACR_NAME" --name "$repo_name" --query "[?tags.contains(@, '${SHORT_COMMIT_HASH}')]" --output tsv)
27+
target_tag_check_status=$?
28+
29+
if [ $target_tag_check_status -eq 0 ] && [ -n "$target_tag_check_output" ]; then
30+
echo " Target tag '$SHORT_COMMIT_HASH' already exists. Skipping import for this repository."
31+
echo "---"
32+
continue
33+
fi
34+
35+
echo " Proceeding with import attempt: $source_image -> $target_image"
36+
37+
az acr import \
38+
--name "$ACR_NAME" \
39+
--source "$source_image" \
40+
--image "$target_image" \
41+
--force
42+
43+
import_status=$?
44+
45+
if [ $import_status -ne 0 ]; then
46+
echo " ⚠️ Warning: ACR import command failed for repository '$repo_name' (Exit Code: $import_status)."
47+
exit_code=1 # Record import failure
48+
else
49+
echo " Import successful for '$repo_name'."
50+
fi
51+
echo "---"
52+
done
53+
54+
echo "Finished processing all repositories."
55+
exit $exit_code

0 commit comments

Comments
 (0)