72 lines (62 loc) · 1.86 KB
/
delete-acr-image.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
name: Delete - Docker image from ACR
on:
workflow_call:
inputs:
imageTags:
type: string
description: "Image Tags or PR numbers"
required: true
workflow_dispatch:
inputs:
imageTag:
description: "Image Tag or PR number"
required: true
defaults:
run:
shell: pwsh
env:
IMAGE_TAGS: ${{ inputs.imageTags || inputs.imageTag }}
PREFIX: pr-
permissions:
id-token: write
contents: read
jobs:
setting-up-img-tags:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Get image tags from input
id: set-matrix
run: |
$imageTags = '${{ env.IMAGE_TAGS }}'
echo "matrix=$imageTags" >> $env:GITHUB_OUTPUT
delete-acr-image:
runs-on: ubuntu-latest
needs: setting-up-img-tags
strategy:
matrix:
IMAGE_TAG: ${{ fromJson(needs.setting-up-img-tags.outputs.matrix) }}
steps:
- uses: actions/checkout@v4
- name: Load .env file
uses: xom9ikk/dotenv@v2
with:
path: ./.github
- name: Azure CLI - Login
uses: azure/login@v1
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: ACR - Delete image
run: |
if('${{ matrix.IMAGE_TAG }}'.Length -le 4) # PR tags consist of 4 digits (i.e pr-xxxx)
{
$imageTagWithPrefix = '${{ env.PREFIX }}${{ matrix.IMAGE_TAG}}'
}else{
$imageTagWithPrefix = '${{ matrix.IMAGE_TAG }}'
}
az acr repository delete --name ${{ env.ACR_NAME }} `
--image ${{ env.IMAGE_NAME }}:$imageTagWithPrefix --yes
Write-Output "✅ ACR - ${{ env.IMAGE_NAME }}:$imageTagWithPrefix image deleted successfully."