@@ -82,17 +82,19 @@ jobs:
8282 echo "registry=${{ env.REGISTRY }}"
8383 } >> "$GITHUB_OUTPUT"
8484
85- # Check if the image tarball already exists or not, if yes, then skip building the image
86- - name : Check artifact exists
87- uses : ./.github/actions/check-artifact-exists
85+ # Check if the image was already built for this SHA using cache
86+ - name : Check if already built
87+ id : cache-check
8888 if : ${{ github.ref_name != github.event.repository.default_branch }}
89+ uses : actions/cache@v5
8990 with :
90- artifact_name : ${{ env.ARTIFACT_NAME }}
91- id : artifact-check
91+ path : .build-marker-${{ matrix.image }}
92+ key : image-built-${{ matrix.image }}-${{ github.sha }}
93+ lookup-only : true
9294
9395 - name : Set up Docker Buildx
9496 uses : docker/setup-buildx-action@v3
95- if : ${{ steps.artifact -check.outputs.exists == 'false ' || github.ref_name == github.event.repository.default_branch }}
97+ if : ${{ steps.cache -check.outputs.cache-hit != 'true ' || github.ref_name == github.event.repository.default_branch }}
9698 id : setup-buildx
9799
98100 - name : Build and save Docker image
@@ -125,4 +127,15 @@ jobs:
125127 path : ${{ env.ARTIFACTS_PATH }}/${{ env.ARTIFACT_NAME }}.tar
126128 retention-days : 1
127129 # Continue the workflow even if the upload failed, because upload can fail if other jobs were able to upload artifact first before the current one
128- continue-on-error : true
130+ continue-on-error : true
131+
132+ - name : Create build marker
133+ if : ${{ steps.save-image.outcome == 'success' || steps.rebuild.outcome == 'success' }}
134+ run : echo "built" > .build-marker-${{ matrix.image }}
135+
136+ - name : Save build marker to cache
137+ if : ${{ steps.save-image.outcome == 'success' || steps.rebuild.outcome == 'success' }}
138+ uses : actions/cache/save@v5
139+ with :
140+ path : .build-marker-${{ matrix.image }}
141+ key : image-built-${{ matrix.image }}-${{ github.sha }}
0 commit comments