@@ -93,10 +93,12 @@ jobs:
9393 env :
9494 DOCKER_CLI_EXPERIMENTAL : enabled
9595 run : |
96+ exists='false'
9697 if docker manifest inspect '${{ steps.action.outputs.image }}'
9798 then
98- echo " exists=true" >>$GITHUB_OUTPUT
99+ exists=' true'
99100 fi
101+ echo "exists=$exists" >>$GITHUB_OUTPUT
100102 shell : bash
101103
102104 deploy :
@@ -108,6 +110,10 @@ jobs:
108110 runs-on : ubuntu-latest
109111 permissions :
110112 packages : write
113+ outputs :
114+ image : ${{ steps.image.outputs.image }}
115+ digest : ${{ steps.build.outputs.digest }}
116+ should_push : ${{ steps.check_conditions.outputs.should_push }}
111117 steps :
112118 - name : Docker meta
113119 id : docker-meta
@@ -137,23 +143,52 @@ jobs:
137143 username : ${{ github.actor }}
138144 password : ${{ secrets.GITHUB_TOKEN }}
139145
146+ - name : Check Conditions
147+ id : check_conditions
148+ run : |
149+ should_push_value='false'
150+ if [[ '${{ github.event_name }}' == 'push' ]]; then
151+ if [[ ${{ startsWith(github.ref, 'refs/heads/main') }} && '${{ needs.config-deploy.outputs.image-exists }}' != 'true' ]]; then
152+ should_push_value='true'
153+ fi
154+ fi
155+ echo "should_push=$should_push_value" >> "$GITHUB_OUTPUT"
156+
157+
140158 - name : Build and push Docker image
141159 uses : docker/build-push-action@v4
160+ id : build
142161 with :
143162 tags : ${{ steps.docker-meta.outputs.tags }}
144163 labels : ${{ steps.docker-meta.outputs.labels }}
145164 platforms : linux/amd64,linux/arm64
146165 pull : true
147166 # deploy image actions from commits pushed to main and
148167 # deploy Dockerfile actions from pushed version tags (no major versions)
149- push : |
150- ${{
151- github.event_name == 'push' && (
152- needs.config-deploy.outputs.image != 'Dockerfile' && startsWith(github.ref, 'refs/heads/main') && needs.config-deploy.outputs.image-exists != 'true' ||
153- needs.config-deploy.outputs.image == 'Dockerfile' && startsWith(github.ref, 'refs/tags/v') && contains(github.ref, '.')
154- )
155- }}
156-
168+ push : ${{ steps.check_conditions.outputs.should_push }}
169+ - name : Output image
170+ id : image
171+ run : |
172+ # NOTE: Set the image as an output because the `env` context is not
173+ # available to the inputs of a reusable workflow call.
174+ image_name="${IMAGE_REGISTRY}/${IMAGE_NAME}"
175+ echo "image=$image_name" >> "$GITHUB_OUTPUT"
176+
177+ provenance :
178+ needs : [deploy]
179+ permissions :
180+ actions : read # for detecting the Github Actions environment.
181+ id-token : write # for creating OIDC tokens for signing.
182+ packages : write # for uploading attestations.
183+ if : ${{ needs.deploy.outputs.should_push == 'true' }}
184+ uses : slsa-framework/slsa-github-generator/.github/workflows/generator_container_slsa3.yml@v1.9.0
185+ with :
186+ image : ${{ needs.deploy.outputs.image }}
187+ digest : ${{ needs.deploy.outputs.digest }}
188+ registry-username : ${{ github.actor }}
189+ secrets :
190+ registry-password : ${{ secrets.GITHUB_TOKEN }}
191+
157192 event_file :
158193 name : " Event File"
159194 runs-on : ubuntu-latest
0 commit comments