1
1
use std:: process:: Command ;
2
2
3
- use clap:: builder:: BoolishValueParser ;
3
+ use clap:: builder:: { BoolishValueParser , PossibleValuesParser } ;
4
4
use clap:: Parser ;
5
5
use cross:: { shell:: Verbosity , CommandExt } ;
6
6
use serde:: { Deserialize , Serialize } ;
@@ -61,6 +61,7 @@ impl TargetMatrix {
61
61
none : false ,
62
62
has_image : true ,
63
63
verbose : false ,
64
+ tests : vec ! [ "all" . to_owned( ) ] ,
64
65
} ,
65
66
) ,
66
67
TargetMatrix {
@@ -83,7 +84,7 @@ impl TargetMatrix {
83
84
}
84
85
) || is_default_try
85
86
{
86
- apply_ci_target_labels ( & prs, & mut app) ?
87
+ apply_ci_labels ( & prs, & mut app) ?
87
88
}
88
89
89
90
app. filter ( & mut matrix) ;
@@ -108,13 +109,15 @@ impl TargetMatrix {
108
109
. collect :: < Vec < _ > > ( ) ;
109
110
110
111
let json = serde_json:: to_string ( & matrix) ?;
111
- gha_print ( & json) ;
112
112
gha_output ( "matrix" , & json) ?;
113
+ let tests = serde_json:: to_string ( & app. tests ( ) ?) ?;
114
+ gha_output ( "tests" , & tests) ?;
113
115
Ok ( ( ) )
114
116
}
115
117
}
116
118
117
- fn apply_ci_target_labels ( prs : & [ & str ] , app : & mut TargetMatrixArgs ) -> Result < ( ) , eyre:: Error > {
119
+ fn apply_ci_labels ( prs : & [ & str ] , app : & mut TargetMatrixArgs ) -> Result < ( ) , eyre:: Error > {
120
+ apply_has_no_ci_tests ( prs, app) ?;
118
121
apply_has_no_ci_target ( prs, app) ?;
119
122
120
123
let mut to_add = vec ! [ ] ;
@@ -135,10 +138,22 @@ fn apply_ci_target_labels(prs: &[&str], app: &mut TargetMatrixArgs) -> Result<()
135
138
Ok ( ( ) )
136
139
}
137
140
141
+ fn apply_has_no_ci_tests ( prs : & [ & str ] , app : & mut TargetMatrixArgs ) -> Result < ( ) , eyre:: Error > {
142
+ if !prs. is_empty ( )
143
+ && prs. iter ( ) . try_fold ( true , |b, pr| {
144
+ Ok :: < _ , eyre:: Report > ( b && has_no_ci_tests_label ( pr) ?)
145
+ } ) ?
146
+ {
147
+ app. none = true ;
148
+ app. tests . push ( "none" . to_owned ( ) ) ;
149
+ }
150
+ Ok ( ( ) )
151
+ }
152
+
138
153
fn apply_has_no_ci_target ( prs : & [ & str ] , app : & mut TargetMatrixArgs ) -> Result < ( ) , eyre:: Error > {
139
154
if !prs. is_empty ( )
140
155
&& prs. iter ( ) . try_fold ( true , |b, pr| {
141
- Ok :: < _ , eyre:: Report > ( b && has_no_ci_target ( pr) ?)
156
+ Ok :: < _ , eyre:: Report > ( b && has_no_ci_target_label ( pr) ?)
142
157
} ) ?
143
158
{
144
159
app. none = true ;
@@ -168,10 +183,14 @@ fn parse_gh_labels(pr: &str) -> cross::Result<Vec<String>> {
168
183
Ok ( pr_info. labels . into_iter ( ) . map ( |l| l. name ) . collect ( ) )
169
184
}
170
185
171
- fn has_no_ci_target ( pr : & str ) -> cross:: Result < bool > {
186
+ fn has_no_ci_target_label ( pr : & str ) -> cross:: Result < bool > {
172
187
Ok ( parse_gh_labels ( pr) ?. contains ( & "no-ci-targets" . to_owned ( ) ) )
173
188
}
174
189
190
+ fn has_no_ci_tests_label ( pr : & str ) -> cross:: Result < bool > {
191
+ Ok ( parse_gh_labels ( pr) ?. contains ( & "no-ci-tests" . to_owned ( ) ) )
192
+ }
193
+
175
194
/// Convert a `GITHUB_REF` into it's merge group pr
176
195
fn process_merge_group ( ref_ : & str ) -> cross:: Result < & str > {
177
196
ref_. split ( '/' )
@@ -227,7 +246,7 @@ struct TargetMatrixElement<'a> {
227
246
verbose : bool ,
228
247
}
229
248
230
- #[ derive( Parser , Debug , Default , PartialEq , Eq ) ]
249
+ #[ derive( Parser , Debug , PartialEq , Eq ) ]
231
250
#[ clap( no_binary_name = true ) ]
232
251
struct TargetMatrixArgs {
233
252
#[ clap( long, short, num_args = 0 ..) ]
@@ -248,6 +267,37 @@ struct TargetMatrixArgs {
248
267
has_image : bool ,
249
268
#[ clap( long, short) ]
250
269
verbose : bool ,
270
+ #[ clap( long, value_parser = PossibleValuesParser :: new( & [
271
+ "remote" ,
272
+ "bisect" ,
273
+ "foreign" ,
274
+ "docker-in-docker" ,
275
+ "podman" ,
276
+ "none" ,
277
+ "all"
278
+ ] ) ,
279
+ num_args = 0 ..,
280
+ value_delimiter = ',' ,
281
+ default_value = "all"
282
+ ) ]
283
+ tests : Vec < String > ,
284
+ }
285
+
286
+ impl Default for TargetMatrixArgs {
287
+ fn default ( ) -> Self {
288
+ Self {
289
+ target : Vec :: new ( ) ,
290
+ std : None ,
291
+ cpp : None ,
292
+ dylib : None ,
293
+ run : None ,
294
+ runners : Vec :: new ( ) ,
295
+ none : false ,
296
+ has_image : false ,
297
+ verbose : false ,
298
+ tests : vec ! [ "all" . to_owned( ) ] ,
299
+ }
300
+ }
251
301
}
252
302
253
303
impl TargetMatrixArgs {
@@ -298,6 +348,42 @@ impl TargetMatrixArgs {
298
348
} ) ;
299
349
}
300
350
}
351
+
352
+ fn tests ( & self ) -> Result < serde_json:: Value , serde_json:: Error > {
353
+ use clap:: CommandFactory ;
354
+ use serde:: ser:: SerializeMap ;
355
+ struct Ser ( Vec < String > ) ;
356
+ impl serde:: Serialize for Ser {
357
+ fn serialize < S : serde:: Serializer > ( & self , serializer : S ) -> Result < S :: Ok , S :: Error > {
358
+ let mut map = serializer. serialize_map ( Some ( self . 0 . len ( ) ) ) ?;
359
+ for e in & self . 0 {
360
+ map. serialize_entry ( & e, & true ) ?;
361
+ }
362
+ map. end ( )
363
+ }
364
+ }
365
+ let tests = match (
366
+ self . tests . iter ( ) . any ( |t| t == "all" ) ,
367
+ self . tests . iter ( ) . any ( |t| t == "none" ) ,
368
+ ) {
369
+ ( _, true ) => vec ! [ ] ,
370
+ ( true , false ) => {
371
+ let mut possible: Vec < String > = Self :: command ( )
372
+ . get_arguments ( )
373
+ . find ( |arg| arg. get_id ( ) == "tests" )
374
+ . expect ( "a `tests` argument should exist" )
375
+ . get_possible_values ( )
376
+ . into_iter ( )
377
+ . map ( |p| p. get_name ( ) . to_owned ( ) )
378
+ . collect ( ) ;
379
+ possible. retain ( |p| p != "all" ) ;
380
+ possible. retain ( |p| p != "none" ) ;
381
+ possible
382
+ }
383
+ _ => self . tests . clone ( ) ,
384
+ } ;
385
+ serde_json:: to_value ( Ser ( tests) )
386
+ }
301
387
}
302
388
303
389
#[ cfg( test) ]
0 commit comments