1
1
use clap:: { Parser , Subcommand } ;
2
2
use std:: {
3
- env, panic,
4
- process:: { Command , Stdio } ,
3
+ env,
4
+ io:: Write ,
5
+ panic,
6
+ path:: Path ,
7
+ process:: { self , Stdio } ,
5
8
} ;
6
9
7
10
#[ derive( Parser ) ]
8
11
#[ command( arg_required_else_help = true ) ]
9
12
struct Cli {
10
13
#[ command( subcommand) ]
11
- command : Option < Commands > ,
14
+ command : Option < Command > ,
12
15
}
13
16
14
17
#[ derive( Subcommand ) ]
15
- enum Commands {
18
+ enum Command {
16
19
Check ,
17
20
Clippy ,
18
21
Fmt ,
@@ -28,7 +31,7 @@ enum Commands {
28
31
}
29
32
30
33
fn run ( program : & str , args : & [ & str ] ) {
31
- let mut command = Command :: new ( program) ;
34
+ let mut command = process :: Command :: new ( program) ;
32
35
command
33
36
. stdout ( Stdio :: inherit ( ) )
34
37
. stderr ( Stdio :: inherit ( ) )
@@ -67,6 +70,46 @@ fn build(target: &str) {
67
70
"cargo" ,
68
71
& [ "build" , "-p" , "kill_tree_cli" , "-r" , "--target" , target] ,
69
72
) ;
73
+
74
+ if env:: var ( "GITHUB_ACTIONS" ) . is_ok ( ) {
75
+ match env:: var ( "GITHUB_OUTPUT" ) {
76
+ Ok ( output) => {
77
+ let windows_path = Path :: new ( "target" )
78
+ . join ( target)
79
+ . join ( "release" )
80
+ . join ( "kill_tree_cli.exe" ) ;
81
+ let file_path = if windows_path. exists ( ) {
82
+ windows_path
83
+ } else {
84
+ Path :: new ( "target" )
85
+ . join ( target)
86
+ . join ( "release" )
87
+ . join ( "kill_tree_cli" )
88
+ } ;
89
+ let zip_path = format ! ( "{}.zip" , target) ;
90
+ let zip_file = std:: fs:: File :: create ( zip_path. clone ( ) ) . unwrap ( ) ;
91
+ let mut zip = zip:: ZipWriter :: new ( zip_file) ;
92
+ let options = zip:: write:: FileOptions :: default ( )
93
+ . compression_method ( zip:: CompressionMethod :: Stored )
94
+ . unix_permissions ( 0o755 ) ;
95
+ let file_name = file_path. file_name ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) ;
96
+ zip. start_file ( file_name, options) . unwrap ( ) ;
97
+ let mut file = std:: fs:: File :: open ( file_path) . unwrap ( ) ;
98
+ std:: io:: copy ( & mut file, & mut zip) . unwrap ( ) ;
99
+ zip. finish ( ) . unwrap ( ) ;
100
+
101
+ let mut output_path = std:: fs:: OpenOptions :: new ( )
102
+ . write ( true )
103
+ . append ( true )
104
+ . open ( output)
105
+ . unwrap ( ) ;
106
+ writeln ! ( output_path, "ARTIFACT_PATH={}" , zip_path) . unwrap ( ) ;
107
+ }
108
+ Err ( _) => {
109
+ panic ! ( "No GITHUB_OUTPUT" ) ;
110
+ }
111
+ }
112
+ }
70
113
}
71
114
72
115
fn test ( target : Option < String > ) {
@@ -88,12 +131,12 @@ fn pre_push() {
88
131
fn main ( ) {
89
132
let cli = Cli :: parse ( ) ;
90
133
match cli. command {
91
- Some ( Commands :: Check ) => check ( ) ,
92
- Some ( Commands :: Clippy ) => clippy ( ) ,
93
- Some ( Commands :: Fmt ) => fmt ( ) ,
94
- Some ( Commands :: Build { target } ) => build ( & target) ,
95
- Some ( Commands :: Test { target } ) => test ( target) ,
96
- Some ( Commands :: PrePush ) => pre_push ( ) ,
134
+ Some ( Command :: Check ) => check ( ) ,
135
+ Some ( Command :: Clippy ) => clippy ( ) ,
136
+ Some ( Command :: Fmt ) => fmt ( ) ,
137
+ Some ( Command :: Build { target } ) => build ( & target) ,
138
+ Some ( Command :: Test { target } ) => test ( target) ,
139
+ Some ( Command :: PrePush ) => pre_push ( ) ,
97
140
None => {
98
141
panic ! ( "No command" ) ;
99
142
}
0 commit comments