3232 description : " Enable cache to GitHub Actions cache backend"
3333 required : false
3434 default : false
35+ cache-scope :
36+ type : string
37+ description : " Which scope cache object belongs to if cache enabled (default is target name)"
38+ required : false
3539 cache-mode :
3640 type : string
3741 description : " Cache layers to export if cache enabled (min or max)"
@@ -176,6 +180,7 @@ jobs:
176180 INPUT_TARGET : ${{ inputs.target }}
177181 INPUT_OUTPUT : ${{ inputs.output }}
178182 INPUT_CACHE : ${{ inputs.cache }}
183+ INPUT_CACHE-SCOPE : ${{ inputs.cache-scope }}
179184 INPUT_CACHE-MODE : ${{ inputs.cache-mode }}
180185 INPUT_META-IMAGES : ${{ inputs.meta-images }}
181186 INPUT_SET-META-ANNOTATIONS : ${{ inputs.set-meta-annotations }}
@@ -200,6 +205,7 @@ jobs:
200205 const inpTarget = core.getInput('target');
201206 const inpOutput = core.getInput('output');
202207 const inpCache = core.getBooleanInput('cache');
208+ const inpCacheScope = core.getInput('cache-scope');
203209 const inpCacheMode = core.getInput('cache-mode');
204210 const inpMetaImages = core.getMultilineInput('meta-images');
205211 const inpSetMetaAnnotations = core.getBooleanInput('set-meta-annotations');
@@ -221,6 +227,29 @@ jobs:
221227 core.setOutput('source', bakeSource);
222228 });
223229
230+ let target;
231+ await core.group(`Validating definition`, async () => {
232+ const bake = new Bake();
233+ const def = await bake.getDefinition({
234+ allow: inpBakeAllow,
235+ files: inpBakeFiles,
236+ overrides: inpBakeSet,
237+ sbom: inpBakeSbom,
238+ source: bakeSource,
239+ targets: [inpTarget],
240+ githubToken: inpGitHubToken
241+ });
242+ if (!def) {
243+ throw new Error('Bake definition not set');
244+ }
245+ const targets = Object.keys(def.target);
246+ if (targets.length > 1) {
247+ throw new Error(`Only one target can be built at once, found: ${targets.join(', ')}`);
248+ }
249+ target = targets[0];
250+ core.setOutput('target', target);
251+ });
252+
224253 let bakeFiles = inpBakeFiles;
225254 await core.group(`Set bake files`, async () => {
226255 if (bakeFiles.length === 0) {
@@ -261,34 +290,12 @@ jobs:
261290 await core.group(`Set bake overrides`, async () => {
262291 bakeOverrides.push('*.attest=type=provenance,mode=max,version=v1', '*.tags=');
263292 if (inpCache) {
264- bakeOverrides.push(`*.cache-from=type=gha,scope=docker-github-builder `);
265- bakeOverrides.push(`*.cache-to=type=gha,scope=docker-github-builder ,mode=${inpCacheMode}`);
293+ bakeOverrides.push(`*.cache-from=type=gha,scope=${inpCacheScope || target} `);
294+ bakeOverrides.push(`*.cache-to=type=gha,scope=${inpCacheScope || target} ,mode=${inpCacheMode}`);
266295 }
267296 core.info(JSON.stringify(bakeOverrides, null, 2));
268297 core.setOutput('overrides', bakeOverrides.join(os.EOL));
269298 });
270-
271- let def;
272- await core.group(`Validating definition`, async () => {
273- const bake = new Bake();
274- def = await bake.getDefinition({
275- allow: inpBakeAllow,
276- files: bakeFiles,
277- overrides: bakeOverrides,
278- sbom: inpBakeSbom,
279- source: bakeSource,
280- targets: [inpTarget],
281- githubToken: inpGitHubToken
282- });
283- if (!def) {
284- throw new Error('Bake definition not set');
285- }
286- const targets = Object.keys(def.target);
287- if (targets.length > 1) {
288- throw new Error(`Only one target can be built at once, found: ${targets.join(', ')}`);
289- }
290- core.setOutput('target', targets[0]);
291- });
292299 -
293300 name : Login to registry
294301 if : ${{ inputs.output == 'registry' }}
0 commit comments