@@ -27,7 +27,7 @@ inputs:
27
27
28
28
# ## Usually a bad idea / not recommended
29
29
build_args :
30
- description : A list of build-time variables, generally not adviseable
30
+ description : A list of build-time variables, generally not advisable
31
31
value : " BUILDKIT_INLINE_CACHE=1"
32
32
diff_branch :
33
33
description : Branch to diff against
@@ -44,8 +44,12 @@ inputs:
44
44
45
45
outputs :
46
46
digest :
47
- description : ' Digest of the built image. for ex: sha256:1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef'
48
- value : ${{ steps.get_digest.outputs.digest }}
47
+ description : ' Digest of the built image; e.g. sha256:1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef'
48
+ value : ${{ steps.digest_new.outputs.digest }}
49
+
50
+ digest_old :
51
+ description : ' Digest of the previous image, if one existed'
52
+ value : ${{ steps.digest_old.outputs.digest }}
49
53
50
54
triggered :
51
55
description : Did a deployment trigger? [true|false]
@@ -54,6 +58,16 @@ outputs:
54
58
runs :
55
59
using : composite
56
60
steps :
61
+ # Cleanup if inputs.keep_versions provided
62
+ - name : GHCR Cleanup
63
+ if : ${{ inputs.keep_versions }}
64
+ uses : actions/delete-package-versions@v5.0.0
65
+ with :
66
+ package-name : " ${{ github.event.repository.name }}/${{ inputs.package }}"
67
+ package-type : " container"
68
+ min-versions-to-keep : ${{ inputs.keep_versions }}
69
+ ignore-versions : " ${{ inputs.keep_regex }}"
70
+
57
71
# Process variables and inputs
58
72
- id : vars
59
73
shell : bash
@@ -119,6 +133,14 @@ runs:
119
133
target : ${{ inputs.tag_fallback }}
120
134
tags : ${{ inputs.tag }}
121
135
136
+ # If a build is required and replaces a previous image, save its SHA
137
+ - name : Check for a previous SHA
138
+ id : digest_old
139
+ shell : bash
140
+ run : |
141
+ DIGEST=$(docker manifest inspect ${{ steps.vars.outputs.tags }} || echo | jq '.manifests[0].digest')
142
+ echo "digest=${DIGEST}" >> $GITHUB_OUTPUT
143
+
122
144
# If a build is required, then checkout, login, build and push!
123
145
- uses : actions/checkout@v4
124
146
with :
@@ -148,25 +170,23 @@ runs:
148
170
cache-to : type=gha,mode=max
149
171
build-args : ${{ inputs.build_args }}
150
172
151
- # Cleanup if inputs.keep_versions provided
152
- - name : GHCR Cleanup
153
- if : ${{ inputs.keep_versions }}
154
- uses : actions/delete-package-versions@v5.0.0
155
- with :
156
- package-name : " ${{ github.event.repository.name }}/${{ inputs.package }}"
157
- package-type : " container"
158
- min-versions-to-keep : ${{ inputs.keep_versions }}
159
- ignore-versions : " ${{ inputs.keep_regex }}"
160
-
161
173
# Action repo needs to be present for cleanup/tests
162
174
- name : Checkout local repo to make sure action.yml is present
163
175
if : ${{ github.repository }} != ${{ inputs.repository }}
164
176
uses : actions/checkout@v4
165
177
166
178
# Get the digest of the built image
167
179
- name : Return digest of the built image
168
- id : get_digest
180
+ id : digest_new
169
181
shell : bash
170
182
run : |
171
183
DIGEST=$(docker manifest inspect ${{ steps.vars.outputs.tags }} | jq '.manifests[0].digest')
172
184
echo "digest=${DIGEST}" >> $GITHUB_OUTPUT
185
+
186
+ # Bug - fail if old and new digests match (e.g. no new image was built)
187
+ - name : SHA Double-check
188
+ if : steps.build.outputs.triggered == 'true' && steps.digest_new.outputs.digest == steps.digest_old.outputs.digest
189
+ shell : bash
190
+ run : |
191
+ echo "SHA collision! New: ${{ steps.digest_new.outputs.digest }}, Old: ${{ steps.digest_old.outputs.digest }}"
192
+ exit 1
0 commit comments