1
1
import * as core from '@actions/core' ;
2
- import { parse } from 'csv-parse/sync' ;
3
2
import * as handlebars from 'handlebars' ;
4
3
import { Context } from '@docker/actions-toolkit/lib/context' ;
5
4
import { GitHub } from '@docker/actions-toolkit/lib/github' ;
@@ -40,7 +39,7 @@ export interface Inputs {
40
39
githubToken : string ;
41
40
}
42
41
43
- export async function getInputs ( ) : Promise < Inputs > {
42
+ export async function getInputs ( toolkit : Toolkit ) : Promise < Inputs > {
44
43
return {
45
44
addHosts : Util . getInputList ( 'add-hosts' ) ,
46
45
allow : Util . getInputList ( 'allow' ) ,
@@ -60,7 +59,7 @@ export async function getInputs(): Promise<Inputs> {
60
59
noCacheFilters : Util . getInputList ( 'no-cache-filters' ) ,
61
60
outputs : Util . getInputList ( 'outputs' , { ignoreComma : true } ) ,
62
61
platforms : Util . getInputList ( 'platforms' ) ,
63
- provenance : getProvenanceInput ( 'provenance' ) ,
62
+ provenance : toolkit . buildx . inputs . getProvenanceInput ( 'provenance' ) ,
64
63
pull : core . getBooleanInput ( 'pull' ) ,
65
64
push : core . getBooleanInput ( 'push' ) ,
66
65
sbom : core . getInput ( 'sbom' ) ,
@@ -145,10 +144,10 @@ async function getBuildArgs(inputs: Inputs, context: string, toolkit: Toolkit):
145
144
if ( GitHub . context . payload . repository ?. private ?? false ) {
146
145
// if this is a private repository, we set the default provenance
147
146
// attributes being set in buildx: https://github.com/docker/buildx/blob/fb27e3f919dcbf614d7126b10c2bc2d0b1927eb6/build/build.go#L603
148
- args . push ( '--provenance' , getProvenanceAttrs ( `mode=min,inline-only=true` ) ) ;
147
+ args . push ( '--provenance' , toolkit . buildx . inputs . resolveProvenanceAttrs ( `mode=min,inline-only=true` ) ) ;
149
148
} else {
150
149
// for a public repository, we set max provenance mode.
151
- args . push ( '--provenance' , getProvenanceAttrs ( `mode=max` ) ) ;
150
+ args . push ( '--provenance' , toolkit . buildx . inputs . resolveProvenanceAttrs ( `mode=max` ) ) ;
152
151
}
153
152
}
154
153
if ( inputs . sbom ) {
@@ -215,37 +214,3 @@ async function getCommonArgs(inputs: Inputs, toolkit: Toolkit): Promise<Array<st
215
214
}
216
215
return args ;
217
216
}
218
-
219
- function getProvenanceInput ( name : string ) : string {
220
- const input = core . getInput ( name ) ;
221
- if ( ! input ) {
222
- // if input is not set, default values will be set later.
223
- return input ;
224
- }
225
- try {
226
- return core . getBooleanInput ( name ) ? `builder-id=${ Context . provenanceBuilderID ( ) } ` : 'false' ;
227
- } catch ( err ) {
228
- // not a valid boolean, so we assume it's a string
229
- return getProvenanceAttrs ( input ) ;
230
- }
231
- }
232
-
233
- function getProvenanceAttrs ( input : string ) : string {
234
- // parse attributes from input
235
- const fields = parse ( input , {
236
- relaxColumnCount : true ,
237
- skipEmptyLines : true
238
- } ) [ 0 ] ;
239
- // check if builder-id attribute exists in the input
240
- for ( const field of fields ) {
241
- const parts = field
242
- . toString ( )
243
- . split ( / (?< = ^ [ ^ = ] + ?) = / )
244
- . map ( item => item . trim ( ) ) ;
245
- if ( parts [ 0 ] == 'builder-id' ) {
246
- return input ;
247
- }
248
- }
249
- // if not add builder-id attribute
250
- return `${ input } ,builder-id=${ Context . provenanceBuilderID ( ) } ` ;
251
- }
0 commit comments