Skip to content

Commit 212fb80

Browse files
committed
cache: sign and verify only if oidc token available
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
1 parent 2ba0b6d commit 212fb80

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

.github/workflows/bake.yml

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ jobs:
152152
outputs:
153153
includes: ${{ steps.set.outputs.includes }}
154154
sign: ${{ steps.set.outputs.sign }}
155-
privateRepo: ${{ steps.set.outputs.privateRepo }}
155+
ghaCacheSign: ${{ steps.set.outputs.ghaCacheSign }}
156156
steps:
157157
-
158158
name: Install @docker/actions-toolkit
@@ -162,13 +162,17 @@ jobs:
162162
with:
163163
script: |
164164
await exec.exec('npm', ['install', '--prefer-offline', '--ignore-scripts', core.getInput('dat-module')]);
165+
-
166+
name: Expose GitHub Runtime
167+
uses: crazy-max/ghaction-github-runtime@3cb05d89e1f492524af3d41a1c98c83bc3025124 # v3.1.0
165168
-
166169
name: Set outputs
167170
id: set
168171
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
169172
env:
170173
INPUT_SBOM-IMAGE: ${{ env.SBOM_IMAGE }}
171174
INPUT_MATRIX-SIZE-LIMIT: ${{ env.MATRIX_SIZE_LIMIT }}
175+
INPUT_ACTIONS-ID-TOKEN-SET: ${{ env.ACTIONS_ID_TOKEN_REQUEST_TOKEN != '' && env.ACTIONS_ID_TOKEN_REQUEST_URL != '' }}
172176
INPUT_RUNNER: ${{ inputs.runner }}
173177
INPUT_ARTIFACT-UPLOAD: ${{ inputs.artifact-upload }}
174178
INPUT_CONTEXT: ${{ inputs.context }}
@@ -189,6 +193,7 @@ jobs:
189193
190194
const inpSbomImage = core.getInput('sbom-image');
191195
const inpMatrixSizeLimit = parseInt(core.getInput('matrix-size-limit'), 10);
196+
const inpActionsIdTokenSet = core.getBooleanInput('actions-id-token-set');
192197
193198
const inpRunner = core.getInput('runner');
194199
const inpArtifactUpload = core.getBooleanInput('artifact-upload');
@@ -294,6 +299,11 @@ jobs:
294299
core.info(`sign: ${sign}`);
295300
core.setOutput('sign', sign);
296301
});
302+
await core.group(`Set ghaCacheSign output`, async () => {
303+
const ghaCacheSign = inpActionsIdTokenSet ? 'true' : 'false';
304+
core.info(`ghaCacheSign: ${ghaCacheSign}`);
305+
core.setOutput('ghaCacheSign', ghaCacheSign);
306+
});
297307
298308
build:
299309
runs-on: ${{ matrix.runner }}
@@ -373,9 +383,9 @@ jobs:
373383
[cache]
374384
[cache.gha]
375385
[cache.gha.sign]
376-
command = ["ghacache-sign-script.sh"]
386+
command = [${{ needs.prepare.outputs.ghaCacheSign == 'true' && '"ghacache-sign-script.sh"' || '' }}]
377387
[cache.gha.verify]
378-
required = true
388+
required = ${{ needs.prepare.outputs.ghaCacheSign }}
379389
[cache.gha.verify.policy]
380390
timestampThreshold = 1
381391
tlogThreshold = ${{ needs.prepare.outputs.privateRepo == 'true' && '0' || '1' }}

.github/workflows/build.yml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ jobs:
160160
includes: ${{ steps.set.outputs.includes }}
161161
sign: ${{ steps.set.outputs.sign }}
162162
privateRepo: ${{ steps.set.outputs.privateRepo }}
163+
ghaCacheSign: ${{ steps.set.outputs.ghaCacheSign }}
163164
steps:
164165
-
165166
name: Install @docker/actions-toolkit
@@ -169,12 +170,16 @@ jobs:
169170
with:
170171
script: |
171172
await exec.exec('npm', ['install', '--prefer-offline', '--ignore-scripts', core.getInput('dat-module')]);
173+
-
174+
name: Expose GitHub Runtime
175+
uses: crazy-max/ghaction-github-runtime@3cb05d89e1f492524af3d41a1c98c83bc3025124 # v3.1.0
172176
-
173177
name: Set outputs
174178
id: set
175179
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
176180
env:
177181
INPUT_MATRIX-SIZE-LIMIT: ${{ env.MATRIX_SIZE_LIMIT }}
182+
INPUT_ACTIONS-ID-TOKEN-SET: ${{ env.ACTIONS_ID_TOKEN_REQUEST_TOKEN != '' && env.ACTIONS_ID_TOKEN_REQUEST_URL != '' }}
178183
INPUT_RUNNER: ${{ inputs.runner }}
179184
INPUT_ARTIFACT-UPLOAD: ${{ inputs.artifact-upload }}
180185
INPUT_OUTPUT: ${{ inputs.output }}
@@ -187,6 +192,7 @@ jobs:
187192
const { Util } = require('@docker/actions-toolkit/lib/util');
188193
189194
const inpMatrixSizeLimit = parseInt(core.getInput('matrix-size-limit'), 10);
195+
const inpActionsIdTokenSet = core.getBooleanInput('actions-id-token-set');
190196
191197
const inpRunner = core.getInput('runner');
192198
const inpArtifactUpload = core.getBooleanInput('artifact-upload');
@@ -254,6 +260,11 @@ jobs:
254260
core.info(`sign: ${sign}`);
255261
core.setOutput('sign', sign);
256262
});
263+
await core.group(`Set ghaCacheSign output`, async () => {
264+
const ghaCacheSign = inpActionsIdTokenSet ? 'true' : 'false';
265+
core.info(`ghaCacheSign: ${ghaCacheSign}`);
266+
core.setOutput('ghaCacheSign', ghaCacheSign);
267+
});
257268
258269
build:
259270
runs-on: ${{ matrix.runner }}
@@ -332,9 +343,9 @@ jobs:
332343
[cache]
333344
[cache.gha]
334345
[cache.gha.sign]
335-
command = ["ghacache-sign-script.sh"]
346+
command = [${{ needs.prepare.outputs.ghaCacheSign == 'true' && '"ghacache-sign-script.sh"' || '' }}]
336347
[cache.gha.verify]
337-
required = true
348+
required = ${{ needs.prepare.outputs.ghaCacheSign }}
338349
[cache.gha.verify.policy]
339350
timestampThreshold = 1
340351
tlogThreshold = ${{ needs.prepare.outputs.privateRepo == 'true' && '0' || '1' }}

0 commit comments

Comments
 (0)