1
1
import { beforeEach , describe , expect , jest , test } from '@jest/globals' ;
2
2
import * as fs from 'fs' ;
3
3
import * as path from 'path' ;
4
+
4
5
import { Builder } from '@docker/actions-toolkit/lib/buildx/builder' ;
5
6
import { Buildx } from '@docker/actions-toolkit/lib/buildx/buildx' ;
7
+ import { Build } from '@docker/actions-toolkit/lib/buildx/build' ;
6
8
import { Context } from '@docker/actions-toolkit/lib/context' ;
7
9
import { Docker } from '@docker/actions-toolkit/lib/docker/docker' ;
8
10
import { GitHub } from '@docker/actions-toolkit/lib/github' ;
9
11
import { Toolkit } from '@docker/actions-toolkit/lib/toolkit' ;
12
+
10
13
import { BuilderInfo } from '@docker/actions-toolkit/lib/types/builder' ;
11
14
import { GitHubRepo } from '@docker/actions-toolkit/lib/types/github' ;
12
15
@@ -35,6 +38,16 @@ jest.spyOn(Docker, 'isAvailable').mockImplementation(async (): Promise<boolean>
35
38
return true ;
36
39
} ) ;
37
40
41
+ const metadataJson = path . join ( tmpDir , 'metadata.json' ) ;
42
+ jest . spyOn ( Build . prototype , 'getMetadataFilePath' ) . mockImplementation ( ( ) : string => {
43
+ return metadataJson ;
44
+ } ) ;
45
+
46
+ const imageIDFilePath = path . join ( tmpDir , 'iidfile.txt' ) ;
47
+ jest . spyOn ( Build . prototype , 'getImageIDFilePath' ) . mockImplementation ( ( ) : string => {
48
+ return imageIDFilePath ;
49
+ } ) ;
50
+
38
51
jest . spyOn ( Builder . prototype , 'inspect' ) . mockImplementation ( async ( ) : Promise < BuilderInfo > => {
39
52
return {
40
53
name : 'builder2' ,
@@ -78,7 +91,7 @@ describe('getArgs', () => {
78
91
] ) ,
79
92
[
80
93
'build' ,
81
- '--iidfile' , path . join ( tmpDir , 'iidfile' ) ,
94
+ '--iidfile' , imageIDFilePath ,
82
95
'.'
83
96
]
84
97
] ,
@@ -101,7 +114,7 @@ ccc"`],
101
114
'--build-arg' , 'MY_ARG=val1,val2,val3' ,
102
115
'--build-arg' , 'ARG=val' ,
103
116
'--build-arg' , `MULTILINE=aaaa\nbbbb\nccc` ,
104
- '--iidfile' , path . join ( tmpDir , 'iidfile' ) ,
117
+ '--iidfile' , imageIDFilePath ,
105
118
'https://github.com/docker/build-push-action.git#refs/heads/master'
106
119
]
107
120
] ,
@@ -117,7 +130,7 @@ ccc"`],
117
130
] ) ,
118
131
[
119
132
'build' ,
120
- '--iidfile' , path . join ( tmpDir , 'iidfile' ) ,
133
+ '--iidfile' , imageIDFilePath ,
121
134
'--tag' , 'name/app:7.4' ,
122
135
'--tag' , 'name/app:latest' ,
123
136
'https://github.com/docker/build-push-action.git#refs/heads/master'
@@ -172,7 +185,7 @@ ccc"`],
172
185
] ) ,
173
186
[
174
187
'build' ,
175
- '--iidfile' , path . join ( tmpDir , 'iidfile' ) ,
188
+ '--iidfile' , imageIDFilePath ,
176
189
'.'
177
190
]
178
191
] ,
@@ -189,7 +202,7 @@ ccc"`],
189
202
] ) ,
190
203
[
191
204
'build' ,
192
- '--iidfile' , path . join ( tmpDir , 'iidfile' ) ,
205
+ '--iidfile' , imageIDFilePath ,
193
206
'--secret' , `id=GIT_AUTH_TOKEN,src=${ tmpName } ` ,
194
207
'.'
195
208
]
@@ -230,7 +243,7 @@ ccc"`],
230
243
[
231
244
'build' ,
232
245
'--file' , './test/Dockerfile' ,
233
- '--iidfile' , path . join ( tmpDir , 'iidfile' ) ,
246
+ '--iidfile' , imageIDFilePath ,
234
247
'--platform' , 'linux/amd64,linux/arm64' ,
235
248
'--secret' , `id=GIT_AUTH_TOKEN,src=${ tmpName } ` ,
236
249
'--builder' , 'builder-git-context-2' ,
@@ -264,7 +277,7 @@ ccc"`],
264
277
[
265
278
'build' ,
266
279
'--file' , './test/Dockerfile' ,
267
- '--iidfile' , path . join ( tmpDir , 'iidfile' ) ,
280
+ '--iidfile' , imageIDFilePath ,
268
281
'--platform' , 'linux/amd64,linux/arm64' ,
269
282
'--secret' , `id=GIT_AUTH_TOKEN,src=${ tmpName } ` ,
270
283
'--secret' , `id=MYSECRET,src=${ tmpName } ` ,
@@ -301,7 +314,7 @@ ccc`],
301
314
[
302
315
'build' ,
303
316
'--file' , './test/Dockerfile' ,
304
- '--iidfile' , path . join ( tmpDir , 'iidfile' ) ,
317
+ '--iidfile' , imageIDFilePath ,
305
318
'--platform' , 'linux/amd64,linux/arm64' ,
306
319
'--secret' , `id=GIT_AUTH_TOKEN,src=${ tmpName } ` ,
307
320
'--secret' , `id=MYSECRET,src=${ tmpName } ` ,
@@ -330,7 +343,7 @@ ccc`],
330
343
[
331
344
'build' ,
332
345
'--file' , './test/Dockerfile' ,
333
- '--iidfile' , path . join ( tmpDir , 'iidfile' ) ,
346
+ '--iidfile' , imageIDFilePath ,
334
347
'--secret' , `id=MY_SECRET,src=${ tmpName } ` ,
335
348
'--builder' , 'builder-git-context-2' ,
336
349
'--network' , 'host' ,
@@ -377,8 +390,8 @@ ccc`],
377
390
'--add-host' , 'docker:10.180.0.1' ,
378
391
'--add-host' , 'foo:10.0.0.1' ,
379
392
'--file' , './test/Dockerfile' ,
380
- '--iidfile' , path . join ( tmpDir , 'iidfile' ) ,
381
- '--metadata-file' , path . join ( tmpDir , 'metadata-file' ) ,
393
+ '--iidfile' , imageIDFilePath ,
394
+ '--metadata-file' , metadataJson ,
382
395
'--network' , 'host' ,
383
396
'--push' ,
384
397
'.'
@@ -406,11 +419,11 @@ nproc=3`],
406
419
'--add-host' , 'foo:10.0.0.1' ,
407
420
'--cgroup-parent' , 'foo' ,
408
421
'--file' , './test/Dockerfile' ,
409
- '--iidfile' , path . join ( tmpDir , 'iidfile' ) ,
422
+ '--iidfile' , imageIDFilePath ,
410
423
'--shm-size' , '2g' ,
411
424
'--ulimit' , 'nofile=1024:1024' ,
412
425
'--ulimit' , 'nproc=3' ,
413
- '--metadata-file' , path . join ( tmpDir , 'metadata-file' ) ,
426
+ '--metadata-file' , metadataJson ,
414
427
'.'
415
428
]
416
429
] ,
@@ -426,8 +439,8 @@ nproc=3`],
426
439
] ) ,
427
440
[
428
441
'build' ,
429
- '--iidfile' , path . join ( tmpDir , 'iidfile' ) ,
430
- '--metadata-file' , path . join ( tmpDir , 'metadata-file' ) ,
442
+ '--iidfile' , imageIDFilePath ,
443
+ '--metadata-file' , metadataJson ,
431
444
'https://github.com/docker/build-push-action.git#refs/heads/master:docker'
432
445
]
433
446
] ,
@@ -444,9 +457,9 @@ nproc=3`],
444
457
] ) ,
445
458
[
446
459
'build' ,
447
- '--iidfile' , path . join ( tmpDir , 'iidfile' ) ,
460
+ '--iidfile' , imageIDFilePath ,
448
461
'--secret' , `id=GIT_AUTH_TOKEN,src=${ tmpName } ` ,
449
- '--metadata-file' , path . join ( tmpDir , 'metadata-file' ) ,
462
+ '--metadata-file' , metadataJson ,
450
463
'https://github.com/docker/build-push-action.git#refs/heads/master:subdir'
451
464
]
452
465
] ,
@@ -463,8 +476,8 @@ nproc=3`],
463
476
] ) ,
464
477
[
465
478
'build' ,
466
- '--iidfile' , path . join ( tmpDir , 'iidfile' ) ,
467
- '--metadata-file' , path . join ( tmpDir , 'metadata-file' ) ,
479
+ '--iidfile' , imageIDFilePath ,
480
+ '--metadata-file' , metadataJson ,
468
481
'.'
469
482
]
470
483
] ,
@@ -480,9 +493,9 @@ nproc=3`],
480
493
] ) ,
481
494
[
482
495
'build' ,
483
- '--iidfile' , path . join ( tmpDir , 'iidfile' ) ,
496
+ '--iidfile' , imageIDFilePath ,
484
497
'--attest' , `type=provenance,mode=min,inline-only=true,builder-id=https://github.com/docker/build-push-action/actions/runs/123456789` ,
485
- '--metadata-file' , path . join ( tmpDir , 'metadata-file' ) ,
498
+ '--metadata-file' , metadataJson ,
486
499
'.'
487
500
]
488
501
] ,
@@ -499,9 +512,9 @@ nproc=3`],
499
512
] ) ,
500
513
[
501
514
'build' ,
502
- '--iidfile' , path . join ( tmpDir , 'iidfile' ) ,
515
+ '--iidfile' , imageIDFilePath ,
503
516
'--attest' , `type=provenance,builder-id=https://github.com/docker/build-push-action/actions/runs/123456789` ,
504
- '--metadata-file' , path . join ( tmpDir , 'metadata-file' ) ,
517
+ '--metadata-file' , metadataJson ,
505
518
'.'
506
519
]
507
520
] ,
@@ -518,9 +531,9 @@ nproc=3`],
518
531
] ) ,
519
532
[
520
533
'build' ,
521
- '--iidfile' , path . join ( tmpDir , 'iidfile' ) ,
534
+ '--iidfile' , imageIDFilePath ,
522
535
'--attest' , `type=provenance,mode=max,builder-id=https://github.com/docker/build-push-action/actions/runs/123456789` ,
523
- '--metadata-file' , path . join ( tmpDir , 'metadata-file' ) ,
536
+ '--metadata-file' , metadataJson ,
524
537
'.'
525
538
]
526
539
] ,
@@ -537,9 +550,9 @@ nproc=3`],
537
550
] ) ,
538
551
[
539
552
'build' ,
540
- '--iidfile' , path . join ( tmpDir , 'iidfile' ) ,
553
+ '--iidfile' , imageIDFilePath ,
541
554
'--attest' , 'type=provenance,disabled=true' ,
542
- '--metadata-file' , path . join ( tmpDir , 'metadata-file' ) ,
555
+ '--metadata-file' , metadataJson ,
543
556
'.'
544
557
]
545
558
] ,
@@ -556,9 +569,9 @@ nproc=3`],
556
569
] ) ,
557
570
[
558
571
'build' ,
559
- '--iidfile' , path . join ( tmpDir , 'iidfile' ) ,
572
+ '--iidfile' , imageIDFilePath ,
560
573
'--attest' , 'type=provenance,builder-id=foo' ,
561
- '--metadata-file' , path . join ( tmpDir , 'metadata-file' ) ,
574
+ '--metadata-file' , metadataJson ,
562
575
'.'
563
576
]
564
577
] ,
@@ -575,9 +588,9 @@ nproc=3`],
575
588
] ) ,
576
589
[
577
590
'build' ,
578
- '--iidfile' , path . join ( tmpDir , 'iidfile' ) ,
591
+ '--iidfile' , imageIDFilePath ,
579
592
"--output" , 'type=docker' ,
580
- '--metadata-file' , path . join ( tmpDir , 'metadata-file' ) ,
593
+ '--metadata-file' , metadataJson ,
581
594
'.'
582
595
]
583
596
] ,
@@ -593,9 +606,9 @@ nproc=3`],
593
606
] ) ,
594
607
[
595
608
'build' ,
596
- '--iidfile' , path . join ( tmpDir , 'iidfile' ) ,
609
+ '--iidfile' , imageIDFilePath ,
597
610
'--load' ,
598
- '--metadata-file' , path . join ( tmpDir , 'metadata-file' ) ,
611
+ '--metadata-file' , metadataJson ,
599
612
'.'
600
613
]
601
614
] ,
@@ -613,9 +626,9 @@ nproc=3`],
613
626
[
614
627
'build' ,
615
628
'--build-arg' , 'FOO=bar#baz' ,
616
- '--iidfile' , path . join ( tmpDir , 'iidfile' ) ,
629
+ '--iidfile' , imageIDFilePath ,
617
630
'--load' ,
618
- '--metadata-file' , path . join ( tmpDir , 'metadata-file' ) ,
631
+ '--metadata-file' , metadataJson ,
619
632
'.'
620
633
]
621
634
] ,
@@ -635,9 +648,9 @@ ANOTHER_SECRET=ANOTHER_SECRET_ENV`]
635
648
'build' ,
636
649
'--secret' , 'id=MY_SECRET,env=MY_SECRET_ENV' ,
637
650
'--secret' , 'id=ANOTHER_SECRET,env=ANOTHER_SECRET_ENV' ,
638
- '--iidfile' , path . join ( tmpDir , 'iidfile' ) ,
651
+ '--iidfile' , imageIDFilePath ,
639
652
'--load' ,
640
- '--metadata-file' , path . join ( tmpDir , 'metadata-file' ) ,
653
+ '--metadata-file' , metadataJson ,
641
654
'.'
642
655
]
643
656
] ,
@@ -656,9 +669,9 @@ ANOTHER_SECRET=ANOTHER_SECRET_ENV`]
656
669
'build' ,
657
670
'--secret' , 'id=MY_SECRET,env=MY_SECRET_ENV' ,
658
671
'--secret' , 'id=ANOTHER_SECRET,env=ANOTHER_SECRET_ENV' ,
659
- '--iidfile' , path . join ( tmpDir , 'iidfile' ) ,
672
+ '--iidfile' , imageIDFilePath ,
660
673
'--load' ,
661
- '--metadata-file' , path . join ( tmpDir , 'metadata-file' ) ,
674
+ '--metadata-file' , metadataJson ,
662
675
'.'
663
676
]
664
677
] ,
@@ -678,7 +691,7 @@ ANOTHER_SECRET=ANOTHER_SECRET_ENV`]
678
691
'build' ,
679
692
'--output' , 'type=local,dest=./release-out' ,
680
693
'--attest' , `type=provenance,mode=min,inline-only=true,builder-id=https://github.com/docker/build-push-action/actions/runs/123456789` ,
681
- '--metadata-file' , path . join ( tmpDir , 'metadata-file' ) ,
694
+ '--metadata-file' , metadataJson ,
682
695
'.'
683
696
]
684
697
] ,
@@ -702,7 +715,7 @@ ANOTHER_SECRET=ANOTHER_SECRET_ENV`]
702
715
'--annotation' , 'manifest-descriptor[linux/amd64]:example4=zzz' ,
703
716
'--output' , 'type=local,dest=./release-out' ,
704
717
'--attest' , `type=provenance,mode=min,inline-only=true,builder-id=https://github.com/docker/build-push-action/actions/runs/123456789` ,
705
- '--metadata-file' , path . join ( tmpDir , 'metadata-file' ) ,
718
+ '--metadata-file' , metadataJson ,
706
719
'.'
707
720
]
708
721
] ,
@@ -719,10 +732,10 @@ ANOTHER_SECRET=ANOTHER_SECRET_ENV`]
719
732
] ) ,
720
733
[
721
734
'build' ,
722
- '--iidfile' , path . join ( tmpDir , 'iidfile' ) ,
735
+ '--iidfile' , imageIDFilePath ,
723
736
"--output" , `type=image,"name=localhost:5000/name/app:latest,localhost:5000/name/app:foo",push-by-digest=true,name-canonical=true,push=true` ,
724
737
'--attest' , `type=provenance,mode=min,inline-only=true,builder-id=https://github.com/docker/build-push-action/actions/runs/123456789` ,
725
- '--metadata-file' , path . join ( tmpDir , 'metadata-file' ) ,
738
+ '--metadata-file' , metadataJson ,
726
739
'.'
727
740
]
728
741
] ,
@@ -740,10 +753,10 @@ ANOTHER_SECRET=ANOTHER_SECRET_ENV`]
740
753
] ) ,
741
754
[
742
755
'build' ,
743
- '--iidfile' , path . join ( tmpDir , 'iidfile' ) ,
756
+ '--iidfile' , imageIDFilePath ,
744
757
'--attest' , `type=provenance,mode=max,builder-id=https://github.com/docker/build-push-action/actions/runs/123456789` ,
745
758
'--attest' , `type=sbom,disabled=false` ,
746
- '--metadata-file' , path . join ( tmpDir , 'metadata-file' ) ,
759
+ '--metadata-file' , metadataJson ,
747
760
'.'
748
761
]
749
762
] ,
@@ -761,9 +774,9 @@ ANOTHER_SECRET=ANOTHER_SECRET_ENV`]
761
774
] ) ,
762
775
[
763
776
'build' ,
764
- '--iidfile' , path . join ( tmpDir , 'iidfile' ) ,
777
+ '--iidfile' , imageIDFilePath ,
765
778
'--attest' , `type=provenance,mode=max,builder-id=https://github.com/docker/build-push-action/actions/runs/123456789` ,
766
- '--metadata-file' , path . join ( tmpDir , 'metadata-file' ) ,
779
+ '--metadata-file' , metadataJson ,
767
780
'.'
768
781
]
769
782
] ,
@@ -780,9 +793,9 @@ ANOTHER_SECRET=ANOTHER_SECRET_ENV`]
780
793
] ) ,
781
794
[
782
795
'build' ,
783
- '--iidfile' , path . join ( tmpDir , 'iidfile' ) ,
796
+ '--iidfile' , imageIDFilePath ,
784
797
'--attest' , `type=provenance,mode=min,builder-id=https://github.com/docker/build-push-action/actions/runs/123456789` ,
785
- '--metadata-file' , path . join ( tmpDir , 'metadata-file' ) ,
798
+ '--metadata-file' , metadataJson ,
786
799
'.'
787
800
]
788
801
] ,
0 commit comments