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)"
@@ -181,6 +185,7 @@ jobs:
181185 INPUT_TARGET : ${{ inputs.target }}
182186 INPUT_OUTPUT : ${{ inputs.output }}
183187 INPUT_CACHE : ${{ inputs.cache }}
188+ INPUT_CACHE-SCOPE : ${{ inputs.cache-scope }}
184189 INPUT_CACHE-MODE : ${{ inputs.cache-mode }}
185190 INPUT_META-IMAGES : ${{ inputs.meta-images }}
186191 INPUT_SET-META-ANNOTATIONS : ${{ inputs.set-meta-annotations }}
@@ -205,6 +210,7 @@ jobs:
205210 const inpTarget = core.getInput('target');
206211 const inpOutput = core.getInput('output');
207212 const inpCache = core.getBooleanInput('cache');
213+ const inpCacheScope = core.getInput('cache-scope');
208214 const inpCacheMode = core.getInput('cache-mode');
209215 const inpMetaImages = core.getMultilineInput('meta-images');
210216 const inpSetMetaAnnotations = core.getBooleanInput('set-meta-annotations');
@@ -226,6 +232,29 @@ jobs:
226232 core.setOutput('source', bakeSource);
227233 });
228234
235+ let target;
236+ await core.group(`Validating definition`, async () => {
237+ const bake = new Bake();
238+ const def = await bake.getDefinition({
239+ allow: inpBakeAllow,
240+ files: inpBakeFiles,
241+ overrides: inpBakeSet,
242+ sbom: inpBakeSbom,
243+ source: bakeSource,
244+ targets: [inpTarget],
245+ githubToken: inpGitHubToken
246+ });
247+ if (!def) {
248+ throw new Error('Bake definition not set');
249+ }
250+ const targets = Object.keys(def.target);
251+ if (targets.length > 1) {
252+ throw new Error(`Only one target can be built at once, found: ${targets.join(', ')}`);
253+ }
254+ target = targets[0];
255+ core.setOutput('target', target);
256+ });
257+
229258 let bakeFiles = inpBakeFiles;
230259 await core.group(`Set bake files`, async () => {
231260 if (bakeFiles.length === 0) {
@@ -266,34 +295,12 @@ jobs:
266295 await core.group(`Set bake overrides`, async () => {
267296 bakeOverrides.push('*.attest=type=provenance,mode=max,version=v1', '*.tags=');
268297 if (inpCache) {
269- bakeOverrides.push(`*.cache-from=type=gha,scope=docker-github-builder `);
270- bakeOverrides.push(`*.cache-to=type=gha,scope=docker-github-builder ,mode=${inpCacheMode}`);
298+ bakeOverrides.push(`*.cache-from=type=gha,scope=${inpCacheScope || target} `);
299+ bakeOverrides.push(`*.cache-to=type=gha,scope=${inpCacheScope || target} ,mode=${inpCacheMode}`);
271300 }
272301 core.info(JSON.stringify(bakeOverrides, null, 2));
273302 core.setOutput('overrides', bakeOverrides.join(os.EOL));
274303 });
275-
276- let def;
277- await core.group(`Validating definition`, async () => {
278- const bake = new Bake();
279- def = await bake.getDefinition({
280- allow: inpBakeAllow,
281- files: bakeFiles,
282- overrides: bakeOverrides,
283- sbom: inpBakeSbom,
284- source: bakeSource,
285- targets: [inpTarget],
286- githubToken: inpGitHubToken
287- });
288- if (!def) {
289- throw new Error('Bake definition not set');
290- }
291- const targets = Object.keys(def.target);
292- if (targets.length > 1) {
293- throw new Error(`Only one target can be built at once, found: ${targets.join(', ')}`);
294- }
295- core.setOutput('target', targets[0]);
296- });
297304 -
298305 name : Login to registry
299306 if : ${{ inputs.output == 'registry' }}
0 commit comments