11use clap:: { Parser , Subcommand } ;
22use std:: {
3- env, panic,
4- process:: { Command , Stdio } ,
3+ env,
4+ io:: Write ,
5+ panic,
6+ path:: Path ,
7+ process:: { self , Stdio } ,
58} ;
69
710#[ derive( Parser ) ]
811#[ command( arg_required_else_help = true ) ]
912struct Cli {
1013 #[ command( subcommand) ]
11- command : Option < Commands > ,
14+ command : Option < Command > ,
1215}
1316
1417#[ derive( Subcommand ) ]
15- enum Commands {
18+ enum Command {
1619 Check ,
1720 Clippy ,
1821 Fmt ,
@@ -28,7 +31,7 @@ enum Commands {
2831}
2932
3033fn run ( program : & str , args : & [ & str ] ) {
31- let mut command = Command :: new ( program) ;
34+ let mut command = process :: Command :: new ( program) ;
3235 command
3336 . stdout ( Stdio :: inherit ( ) )
3437 . stderr ( Stdio :: inherit ( ) )
@@ -67,6 +70,46 @@ fn build(target: &str) {
6770 "cargo" ,
6871 & [ "build" , "-p" , "kill_tree_cli" , "-r" , "--target" , target] ,
6972 ) ;
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+ }
70113}
71114
72115fn test ( target : Option < String > ) {
@@ -88,12 +131,12 @@ fn pre_push() {
88131fn main ( ) {
89132 let cli = Cli :: parse ( ) ;
90133 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 ( ) ,
97140 None => {
98141 panic ! ( "No command" ) ;
99142 }
0 commit comments