Skip to content

Commit 2e1ce4f

Browse files
committed
feat: enhance cleanup workflow to include purged image count and summary reporting
1 parent b999cc1 commit 2e1ce4f

1 file changed

Lines changed: 32 additions & 5 deletions

File tree

.github/workflows/cleanup-container-images.yml

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,14 @@ jobs:
6666
fi
6767
6868
- name: Cleanup Old Container Images
69+
id: cleanup
6970
run: |
7071
acr_name="${{ steps.get-acr.outputs.acr_name }}"
7172
dry_run="${{ github.event.inputs.dry_run || 'false' }}"
7273
7374
if [ -z "$acr_name" ]; then
7475
echo "No Azure Container Registry found. Skipping cleanup."
76+
echo "purged_count=0" >> $GITHUB_OUTPUT
7577
exit 0
7678
fi
7779
@@ -83,6 +85,7 @@ jobs:
8385
8486
if [ -z "$repositories" ]; then
8587
echo "No repositories found in ACR. Nothing to clean up."
88+
echo "purged_count=0" >> $GITHUB_OUTPUT
8689
exit 0
8790
fi
8891
@@ -94,7 +97,7 @@ jobs:
9497
PURGE_FILTERS="$PURGE_FILTERS --filter '$repo:.*'"
9598
done
9699
97-
# Construct the purge command
100+
# Construct the purge command and capture the output
98101
PURGE_CMD="acr purge $PURGE_FILTERS --ago 0d --keep 5 --untagged"
99102
100103
if [ "$dry_run" = "true" ]; then
@@ -103,18 +106,42 @@ jobs:
103106
fi
104107
105108
echo "Running purge command..."
106-
# Set longer timeout (1 hour) for large registries
107-
az acr run \
109+
# Run the purge command and capture output
110+
purge_output=$(az acr run \
108111
--cmd "$PURGE_CMD" \
109112
--registry "$acr_name" \
110113
--timeout 3600 \
111-
/dev/null
114+
/dev/null)
112115
113116
exit_code=$?
114117
118+
# Count purged images by looking for lines with "Deleted manifest" in the output
119+
purged_count=$(echo "$purge_output" | grep -c "Deleted manifest" || echo 0)
120+
echo "purged_count=$purged_count" >> $GITHUB_OUTPUT
121+
115122
if [ $exit_code -eq 0 ]; then
116123
echo "✅ Cleanup process completed successfully!"
124+
echo "🧹 Images purged: $purged_count"
117125
else
118126
echo "❌ Cleanup process failed with exit code $exit_code"
119127
exit $exit_code
120-
fi
128+
fi
129+
130+
- name: Create Summary
131+
run: |
132+
purged_count="${{ steps.cleanup.outputs.purged_count }}"
133+
dry_run="${{ github.event.inputs.dry_run || 'false' }}"
134+
135+
echo "## Container Registry Cleanup Summary" >> $GITHUB_STEP_SUMMARY
136+
echo "- Registry: \`${{ steps.get-acr.outputs.acr_name }}\`" >> $GITHUB_STEP_SUMMARY
137+
echo "- Date: $(date -u '+%Y-%m-%d %H:%M:%S UTC')" >> $GITHUB_STEP_SUMMARY
138+
139+
if [ "$dry_run" = "true" ]; then
140+
echo "- Mode: 🔍 **DRY RUN** (no images were actually deleted)" >> $GITHUB_STEP_SUMMARY
141+
echo "- Images that would be purged: **$purged_count**" >> $GITHUB_STEP_SUMMARY
142+
else
143+
echo "- Mode: ✅ **Production Run**" >> $GITHUB_STEP_SUMMARY
144+
echo "- Images purged: **$purged_count**" >> $GITHUB_STEP_SUMMARY
145+
fi
146+
147+
echo "- Retention Policy: Keep 5 most recent images per repository" >> $GITHUB_STEP_SUMMARY

0 commit comments

Comments
 (0)