@@ -25,13 +25,19 @@ fn install_targets() {
25
25
/// Install global dependencies
26
26
fn install_dependencies ( ) {
27
27
for dependency in DEPENDENCIES {
28
- let mut cargo = Command :: new ( "cargo" ) ;
29
- cargo. args ( & [ "install" , dependency] ) ;
30
- let status = cargo
31
- . status ( )
32
- . map_err ( |e| format ! ( "couldn't execute {:?}: {}" , cargo, e) )
33
- . unwrap ( ) ;
34
- assert ! ( status. success( ) , ) ;
28
+ let exists = Command :: new ( "which" )
29
+ . arg ( dependency)
30
+ . output ( )
31
+ . expect ( "failed to execute" ) ;
32
+ if !exists. status . success ( ) {
33
+ let mut cargo = Command :: new ( "cargo" ) ;
34
+ cargo. args ( & [ "install" , dependency] ) ;
35
+ let status = cargo
36
+ . status ( )
37
+ . map_err ( |e| format ! ( "couldn't execute {:?}: {}" , cargo, e) )
38
+ . unwrap ( ) ;
39
+ assert ! ( status. success( ) , ) ;
40
+ }
35
41
}
36
42
}
37
43
@@ -154,16 +160,35 @@ fn build_example(manifest_path: &path::PathBuf, feature: Option<String>, target:
154
160
) ;
155
161
}
156
162
163
+ fn start_group ( is_ci : bool , name : & str ) {
164
+ if is_ci {
165
+ println ! ( "::group::{}" , name) ;
166
+ }
167
+ }
168
+
169
+ fn end_group ( is_ci : bool ) {
170
+ if is_ci {
171
+ println ! ( "::endgroup::" ) ;
172
+ }
173
+ }
174
+
175
+ fn wrap_in_group ( is_ci : bool , name : & str , callable : & dyn Fn ( ) ) {
176
+ start_group ( is_ci, name) ;
177
+ callable ( ) ;
178
+ end_group ( is_ci) ;
179
+ }
180
+
157
181
pub fn ci ( ) {
158
- install_targets ( ) ;
159
- install_dependencies ( ) ;
182
+ let is_ci = env:: var ( "CI" ) . map_or ( false , |ci| ci == "true" ) ;
160
183
161
184
// move up if we're running from inside xtask
162
185
if env:: current_dir ( ) . unwrap ( ) . ends_with ( "xtask" ) {
163
186
env:: set_current_dir ( ".." ) . unwrap ( ) ;
164
187
}
165
188
166
- build_crates ( ) ;
167
- build_run_doc_tests ( ) ;
168
- build_examples ( ) ;
189
+ wrap_in_group ( is_ci, "install targets" , & install_targets) ;
190
+ wrap_in_group ( is_ci, "install dependencies" , & install_dependencies) ;
191
+ wrap_in_group ( is_ci, "build crates" , & build_crates) ;
192
+ wrap_in_group ( is_ci, "build examples" , & build_examples) ;
193
+ wrap_in_group ( is_ci, "run doc tests" , & build_run_doc_tests) ;
169
194
}
0 commit comments