Skip to content

Commit 02959a4

Browse files
committed
perf: separate delete branch logic
1 parent 3d90a0b commit 02959a4

File tree

3 files changed

+83
-21
lines changed

3 files changed

+83
-21
lines changed

.github/workflows/az_acr_delete.yml

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,9 @@ name: 'ACR: Delete Docker Image'
22

33
on:
44
workflow_call:
5-
inputs:
6-
image_tag:
7-
description: 'Image Tag'
8-
required: true
9-
type: string
105

116
jobs:
12-
az-acr-delete:
7+
az-acr-delete-test:
138
name: "ACR: Delete Test Image"
149
runs-on: ubuntu-latest
1510
environment: dev
@@ -27,13 +22,46 @@ jobs:
2722

2823
- name: Configure branch name
2924
id: branch_name
30-
run: echo "GH_REF_NAME=$(echo ${{ inputs.image_tag }} | sed 's|/|-|g')" >> $GITHUB_OUTPUT
25+
run: echo "GH_REF_NAME=$(echo "test-${{ github.event.ref }}" | sed 's|/|-|g')" >> $GITHUB_OUTPUT
3126

32-
- name: Delete Test Container Image
27+
- name: Delete Container Image
3328
uses: azure/cli@v2
3429
with:
3530
inlineScript: |
3631
az acr repository delete \
3732
--name ${{ env.AZURE_CONTAINER_REGISTRY }} \
3833
--image ${{ github.event.repository.name }}:${{ steps.branch_name.outputs.GH_REF_NAME }} \
39-
--yes || true
34+
--yes || true
35+
36+
az-acr-delete-matrix:
37+
name: 'ACR: Delete Branch Images'
38+
runs-on: ubuntu-latest
39+
environment: dev
40+
env:
41+
AZURE_CONTAINER_REGISTRY: ${{ vars.AZURE_CONTAINER_REGISTRY }}
42+
ACR_LOGIN_USERNAME: ${{ secrets.ACR_LOGIN_USERNAME }}
43+
ACR_LOGIN_PASSWORD: ${{ secrets.ACR_LOGIN_PASSWORD }}
44+
strategy:
45+
matrix:
46+
platform: [amd64, arm64]
47+
steps:
48+
- name: Azure Cloud Login
49+
uses: azure/login@v2
50+
with:
51+
client-id: ${{ secrets.AZURE_CLIENT_ID }}
52+
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
53+
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
54+
55+
- name: Configure branch name
56+
id: branch_name
57+
run: echo "GH_REF_NAME=$(echo "${{ github.event.ref }}" | sed 's|/|-|g')" >> $GITHUB_OUTPUT
58+
59+
- name: Delete Branch Container Image
60+
uses: azure/cli@v2
61+
with:
62+
inlineScript: |
63+
az acr repository delete \
64+
--name ${{ env.AZURE_CONTAINER_REGISTRY }} \
65+
--image ${{ github.event.repository.name }}:${{ matrix.platform}}-${{ steps.branch_name.outputs.GH_REF_NAME }} \
66+
--yes
67+

.github/workflows/gh_delete_branch.yml

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,36 @@ on:
44
workflow_call:
55

66
jobs:
7-
call-az-acr-delete:
8-
uses: code-kern-ai/cicd-deployment-scripts/.github/workflows/az_acr_delete.yml@dev
9-
secrets: inherit
10-
with:
11-
image_tag: "test-${{ github.event.pull_request.head.ref }}"
7+
az-acr-delete-test:
8+
name: "ACR: Delete Test Image"
9+
runs-on: ubuntu-latest
10+
environment: dev
11+
env:
12+
AZURE_CONTAINER_REGISTRY: ${{ vars.AZURE_CONTAINER_REGISTRY }}
13+
ACR_LOGIN_USERNAME: ${{ secrets.ACR_LOGIN_USERNAME }}
14+
ACR_LOGIN_PASSWORD: ${{ secrets.ACR_LOGIN_PASSWORD }}
15+
steps:
16+
- name: Azure Cloud Login
17+
uses: azure/login@v2
18+
with:
19+
client-id: ${{ secrets.AZURE_CLIENT_ID }}
20+
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
21+
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
22+
23+
- name: Configure branch name
24+
id: branch_name
25+
run: echo "GH_REF_NAME=$(echo "test-${{ github.event.pull_request.head.ref }}" | sed 's|/|-|g')" >> $GITHUB_OUTPUT
26+
27+
- name: Delete Container Image
28+
uses: azure/cli@v2
29+
with:
30+
inlineScript: |
31+
az acr repository delete \
32+
--name ${{ env.AZURE_CONTAINER_REGISTRY }} \
33+
--image ${{ github.event.repository.name }}:${{ steps.branch_name.outputs.GH_REF_NAME }} \
34+
--yes || true
1235
13-
az-acr-delete:
36+
az-acr-delete-matrix:
1437
name: 'ACR: Delete Branch Images'
1538
runs-on: ubuntu-latest
1639
environment: dev
@@ -29,14 +52,17 @@ jobs:
2952
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
3053
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
3154

55+
- name: Configure branch name
56+
id: branch_name
57+
run: echo "GH_REF_NAME=$(echo "${{ github.event.pull_request.head.ref }}" | sed 's|/|-|g')" >> $GITHUB_OUTPUT
58+
3259
- name: Delete Branch Container Image
3360
uses: azure/cli@v2
3461
with:
3562
inlineScript: |
36-
GH_REF_NAME=$(echo ${{ github.event.pull_request.head.ref }} | sed 's|/|-|g')
3763
az acr repository delete \
3864
--name ${{ env.AZURE_CONTAINER_REGISTRY }} \
39-
--image ${{ github.event.repository.name }}:${{ matrix.platform}}-${GH_REF_NAME} \
65+
--image ${{ github.event.repository.name }}:${{ matrix.platform}}-${{ steps.branch_name.outputs.GH_REF_NAME }} \
4066
--yes
4167
4268
gh-delete-branch:

.github/workflows/k8s_release.yml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,17 @@ jobs:
4545
deployment_status: "success"
4646
# deployment_status: ${{ needs.call-k8-deploy.outputs.deployment_status }}
4747

48-
call-gh-delete-branch:
49-
# needs: [call-k8-deploy]
48+
gh-delete-branch:
49+
name: 'GitHub: Delete Branch'
50+
runs-on: ubuntu-latest
5051
needs: [call-k8-edit]
5152
if: github.event_name == 'pull_request' && github.event.pull_request.merged && !failure() && !cancelled()
52-
uses: code-kern-ai/cicd-deployment-scripts/.github/workflows/gh_delete_branch.yml@dev
53-
secrets: inherit
53+
steps:
54+
- name: Checkout repository
55+
uses: actions/checkout@v4
56+
with:
57+
token: ${{ secrets.GH_TOKEN }}
58+
59+
- name: Delete Branch
60+
shell: bash
61+
run: git push origin --delete ${{ github.head_ref }}

0 commit comments

Comments
 (0)