Skip to content

Commit 79d3ac5

Browse files
committed
fix image delete logic
1 parent 02fa0b6 commit 79d3ac5

File tree

1 file changed

+23
-13
lines changed

1 file changed

+23
-13
lines changed

.github/workflows/fatimage.yml

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -100,24 +100,13 @@ jobs:
100100
echo "image-name=${IMAGE_NAME}" >> "$GITHUB_OUTPUT"
101101
echo "image-id=$IMAGE_ID" >> "$GITHUB_OUTPUT"
102102
103-
- name: Delete old latest image
104-
run: |
105-
. venv/bin/activate
106-
IMAGE_COUNT=$(openstack image list --name ${{ steps.manifest.outputs.image-name }} -f value -c ID | wc -l)
107-
if [ "$IMAGE_COUNT" -gt 1 ]; then
108-
OLD_IMAGE_ID=$(openstack image list --sort created_at:asc --name "${{ steps.manifest.outputs.image-name }}" -f value -c ID | head -n 1)
109-
openstack image delete "$OLD_IMAGE_ID"
110-
else
111-
echo "Only one image exists, skipping deletion."
112-
fi
113-
114103
- name: Download image
115104
run: |
116105
. venv/bin/activate
117106
sudo mkdir /mnt/images
118107
sudo chmod 777 /mnt/images
119-
openstack image unset --property signature_verified "${{ steps.manifest.outputs.image-name }}"
120-
openstack image save --file /mnt/images/${{ steps.manifest.outputs.image-name }}.qcow2 ${{ steps.manifest.outputs.image-name }}
108+
openstack image unset --property signature_verified "${{ steps.manifest.outputs.image-id }}"
109+
openstack image save --file /mnt/images/${{ steps.manifest.outputs.image-name }}.qcow2 ${{ steps.manifest.outputs.image-id }}
121110
122111
- name: Set up QEMU
123112
uses: docker/setup-qemu-action@v3
@@ -152,6 +141,7 @@ jobs:
152141
category: "${{ matrix.os_version }}-${{ matrix.build }}"
153142

154143
- name: Fail if scan has CRITICAL vulnerabilities
144+
id: trivy_critical_check
155145
uses: aquasecurity/[email protected]
156146
with:
157147
scan-type: fs
@@ -161,6 +151,26 @@ jobs:
161151
exit-code: '1'
162152
severity: 'CRITICAL'
163153
ignore-unfixed: true
154+
155+
- name: Delete new image if Trivy scan fails
156+
if: steps.trivy_critical_check.outcome == 'failure' # Runs if the Trivy scan found CRITICAL vulnerabilities
157+
run: |
158+
. venv/bin/activate
159+
echo "Deleting new image due to critical vulnerabilities..."
160+
openstack image delete "${{ steps.manifest.outputs.image-id }}"
161+
162+
- name: Delete old latest image
163+
if: steps.trivy_critical_check.outcome == 'success' # Runs only if Trivy scan passed
164+
run: |
165+
. venv/bin/activate
166+
IMAGE_COUNT=$(openstack image list --name ${{ steps.manifest.outputs.image-name }} -f value -c ID | wc -l)
167+
if [ "$IMAGE_COUNT" -gt 1 ]; then
168+
OLD_IMAGE_ID=$(openstack image list --sort created_at:asc --name "${{ steps.manifest.outputs.image-name }}" -f value -c ID | head -n 1)
169+
echo "Deleting old image ID: $OLD_IMAGE_ID"
170+
openstack image delete "$OLD_IMAGE_ID"
171+
else
172+
echo "Only one image exists, skipping deletion."
173+
fi
164174
165175
upload:
166176
name: upload-nightly-targets

0 commit comments

Comments
 (0)