@@ -68,6 +68,10 @@ export function tmpNameSync(options?: tmp.TmpNameOptions): string {
68
68
return tmp . tmpNameSync ( options ) ;
69
69
}
70
70
71
+ export function provenanceBuilderID ( ) : string {
72
+ return `${ process . env . GITHUB_SERVER_URL || 'https://github.com' } /${ github . context . repo . owner } /${ github . context . repo . repo } /actions/runs/${ github . context . runId } ` ;
73
+ }
74
+
71
75
export async function getInputs ( defaultContext : string ) : Promise < Inputs > {
72
76
return {
73
77
addHosts : await getInputList ( 'add-hosts' ) ,
@@ -88,7 +92,7 @@ export async function getInputs(defaultContext: string): Promise<Inputs> {
88
92
noCacheFilters : await getInputList ( 'no-cache-filters' ) ,
89
93
outputs : await getInputList ( 'outputs' , true ) ,
90
94
platforms : await getInputList ( 'platforms' ) ,
91
- provenance : core . getInput ( 'provenance' ) ,
95
+ provenance : getProvenanceInput ( 'provenance' ) ,
92
96
pull : core . getBooleanInput ( 'pull' ) ,
93
97
push : core . getBooleanInput ( 'push' ) ,
94
98
sbom : core . getInput ( 'sbom' ) ,
@@ -162,22 +166,19 @@ async function getBuildArgs(inputs: Inputs, defaultContext: string, context: str
162
166
args . push ( '--platform' , inputs . platforms . join ( ',' ) ) ;
163
167
}
164
168
if ( buildx . satisfies ( buildxVersion , '>=0.10.0' ) ) {
165
- const prvBuilderID = `${ process . env . GITHUB_SERVER_URL || 'https://github.com' } /${ github . context . repo . owner } /${ github . context . repo . repo } /actions/runs/${ github . context . runId } ` ;
166
169
if ( inputs . provenance ) {
167
- args . push ( '--provenance' , getProvenanceAttrs ( inputs . provenance , prvBuilderID ) ) ;
170
+ args . push ( '--provenance' , inputs . provenance ) ;
168
171
} else if ( ( await buildx . satisfiesBuildKitVersion ( inputs . builder , '>=0.11.0' , standalone ) ) && ! hasDockerExport ( inputs ) ) {
169
172
// if provenance not specified and BuildKit version compatible for
170
173
// attestation, set default provenance. Also needs to make sure user
171
174
// doesn't want to explicitly load the image to docker.
172
175
if ( fromPayload ( 'repository.private' ) !== false ) {
173
176
// if this is a private repository, we set the default provenance
174
177
// attributes being set in buildx: https://github.com/docker/buildx/blob/fb27e3f919dcbf614d7126b10c2bc2d0b1927eb6/build/build.go#L603
175
- // along the builder-id attribute.
176
- args . push ( '--provenance' , `mode=min,inline-only=true,builder-id=${ prvBuilderID } ` ) ;
178
+ args . push ( '--provenance' , getProvenanceAttrs ( `mode=min,inline-only=true` ) ) ;
177
179
} else {
178
- // for a public repository, we set max provenance mode and the
179
- // builder-id attribute.
180
- args . push ( '--provenance' , `mode=max,builder-id=${ prvBuilderID } ` ) ;
180
+ // for a public repository, we set max provenance mode.
181
+ args . push ( '--provenance' , getProvenanceAttrs ( `mode=max` ) ) ;
181
182
}
182
183
}
183
184
if ( inputs . sbom ) {
@@ -298,7 +299,24 @@ function select(obj: any, path: string): any {
298
299
return select ( obj [ key ] , path . slice ( i + 1 ) ) ;
299
300
}
300
301
301
- function getProvenanceAttrs ( input : string , builderID : string ) : string {
302
+ function getProvenanceInput ( name : string ) : string {
303
+ const input = core . getInput ( name ) ;
304
+ if ( ! input ) {
305
+ // if input is not set, default values will be set later.
306
+ return input ;
307
+ }
308
+ const builderID = provenanceBuilderID ( ) ;
309
+ try {
310
+ return core . getBooleanInput ( name ) ? `builder-id=${ builderID } ` : 'false' ;
311
+ } catch ( err ) {
312
+ // not a valid boolean, so we assume it's a string
313
+ return getProvenanceAttrs ( input ) ;
314
+ }
315
+ }
316
+
317
+ function getProvenanceAttrs ( input : string ) : string {
318
+ const builderID = provenanceBuilderID ( ) ;
319
+ // parse attributes from input
302
320
const fields = parse ( input , {
303
321
relaxColumnCount : true ,
304
322
skipEmptyLines : true
0 commit comments