@@ -4,6 +4,7 @@ import * as os from 'os';
44import * as path from 'path' ;
55
66import { Bake } from '@docker/actions-toolkit/lib/buildx/bake.js' ;
7+ import { Build } from '@docker/actions-toolkit/lib/buildx/build.js' ;
78import { Builder } from '@docker/actions-toolkit/lib/buildx/builder.js' ;
89import { Buildx } from '@docker/actions-toolkit/lib/buildx/buildx.js' ;
910import { Docker } from '@docker/actions-toolkit/lib/docker/docker.js' ;
@@ -39,6 +40,55 @@ vi.spyOn(Bake.prototype, 'getDefinition').mockImplementation(async (): Promise<B
3940 return < BakeDefinition > JSON . parse ( fs . readFileSync ( path . join ( fixturesDir , 'bake-def.json' ) , { encoding : 'utf-8' } ) . trim ( ) ) ;
4041} ) ;
4142
43+ describe ( 'getInputs' , ( ) => {
44+ const originalEnv = process . env ;
45+
46+ beforeEach ( ( ) => {
47+ process . env = Object . keys ( process . env ) . reduce ( ( object , key ) => {
48+ if ( ! key . startsWith ( 'INPUT_' ) ) {
49+ object [ key ] = process . env [ key ] ;
50+ }
51+ return object ;
52+ } , { } ) ;
53+ } ) ;
54+
55+ afterEach ( ( ) => {
56+ process . env = originalEnv ;
57+ } ) ;
58+
59+ function setRequiredBooleanInputs ( ) : void {
60+ setInput ( 'no-cache' , 'false' ) ;
61+ setInput ( 'pull' , 'false' ) ;
62+ setInput ( 'load' , 'false' ) ;
63+ setInput ( 'push' , 'false' ) ;
64+ }
65+
66+ test ( 'uses Build git context when source input is empty' , async ( ) => {
67+ const gitContext = 'https://github.com/docker/bake-action.git?ref=refs/heads/master&checksum=0123456789abcdef' ;
68+ const gitContextSpy = vi . spyOn ( Build . prototype , 'gitContext' ) . mockResolvedValue ( gitContext ) ;
69+ setRequiredBooleanInputs ( ) ;
70+ const inputs = await context . getInputs ( ) ;
71+ expect ( inputs . source ) . toEqual ( {
72+ remoteRef : gitContext
73+ } ) ;
74+ expect ( gitContextSpy ) . toHaveBeenCalledTimes ( 1 ) ;
75+ gitContextSpy . mockRestore ( ) ;
76+ } ) ;
77+
78+ test ( 'renders defaultContext source templates from Build git context' , async ( ) => {
79+ const gitContext = 'https://github.com/docker/bake-action.git#refs/heads/master' ;
80+ const gitContextSpy = vi . spyOn ( Build . prototype , 'gitContext' ) . mockResolvedValue ( gitContext ) ;
81+ setRequiredBooleanInputs ( ) ;
82+ setInput ( 'source' , '{{defaultContext}}:subdir' ) ;
83+ const inputs = await context . getInputs ( ) ;
84+ expect ( inputs . source ) . toEqual ( {
85+ remoteRef : `${ gitContext } :subdir`
86+ } ) ;
87+ expect ( gitContextSpy ) . toHaveBeenCalledTimes ( 1 ) ;
88+ gitContextSpy . mockRestore ( ) ;
89+ } ) ;
90+ } ) ;
91+
4292describe ( 'getArgs' , ( ) => {
4393 const originalEnv = process . env ;
4494 beforeEach ( ( ) => {
@@ -343,6 +393,54 @@ describe('getArgs', () => {
343393 [ 'BUILDX_NO_DEFAULT_ATTESTATIONS' , '1' ]
344394 ] )
345395 ] ,
396+ [
397+ 15 ,
398+ '0.29.0' ,
399+ new Map < string , string > ( [
400+ [ 'load' , 'false' ] ,
401+ [ 'no-cache' , 'false' ] ,
402+ [ 'push' , 'false' ] ,
403+ [ 'pull' , 'false' ] ,
404+ [ 'files' , './foo.hcl' ] ,
405+ ] ) ,
406+ [
407+ 'bake' ,
408+ 'https://github.com/docker/bake-action.git?ref=refs/heads/master' ,
409+ '--allow' , 'fs=*' ,
410+ '--file' , './foo.hcl' ,
411+ '--metadata-file' , metadataJson ,
412+ '--set' , `lint.attest=type=provenance,mode=min,inline-only=true,builder-id=https://github.com/docker/bake-action/actions/runs/123456789/attempts/1` ,
413+ '--set' , `validate-docs.attest=type=provenance,mode=min,inline-only=true,builder-id=https://github.com/docker/bake-action/actions/runs/123456789/attempts/1` ,
414+ '--set' , `validate-vendor.attest=type=provenance,mode=min,inline-only=true,builder-id=https://github.com/docker/bake-action/actions/runs/123456789/attempts/1`
415+ ] ,
416+ new Map < string , string > ( [
417+ [ 'BUILDX_SEND_GIT_QUERY_AS_INPUT' , 'true' ]
418+ ] )
419+ ] ,
420+ [
421+ 16 ,
422+ '0.28.0' ,
423+ new Map < string , string > ( [
424+ [ 'load' , 'false' ] ,
425+ [ 'no-cache' , 'false' ] ,
426+ [ 'push' , 'false' ] ,
427+ [ 'pull' , 'false' ] ,
428+ [ 'files' , './foo.hcl' ] ,
429+ ] ) ,
430+ [
431+ 'bake' ,
432+ 'https://github.com/docker/bake-action.git#refs/heads/master' ,
433+ '--allow' , 'fs=*' ,
434+ '--file' , './foo.hcl' ,
435+ '--metadata-file' , metadataJson ,
436+ '--set' , `lint.attest=type=provenance,mode=min,inline-only=true,builder-id=https://github.com/docker/bake-action/actions/runs/123456789/attempts/1` ,
437+ '--set' , `validate-docs.attest=type=provenance,mode=min,inline-only=true,builder-id=https://github.com/docker/bake-action/actions/runs/123456789/attempts/1` ,
438+ '--set' , `validate-vendor.attest=type=provenance,mode=min,inline-only=true,builder-id=https://github.com/docker/bake-action/actions/runs/123456789/attempts/1`
439+ ] ,
440+ new Map < string , string > ( [
441+ [ 'BUILDX_SEND_GIT_QUERY_AS_INPUT' , 'true' ]
442+ ] )
443+ ] ,
346444 ] ) (
347445 '[%d] given %o with %o as inputs, returns %o' ,
348446 async ( num : number , buildxVersion : string , inputs : Map < string , string > , expected : Array < string > , envs : Map < string , string > | undefined ) => {
0 commit comments