1- use std:: path:: PathBuf ;
1+ use std:: { os :: unix :: fs :: PermissionsExt , path:: PathBuf } ;
22
33use anyhow:: { Context , Result } ;
4- use ghactions_core:: repository:: reference:: RepositoryReference as Repository ;
4+ use ghactions_core:: { repository:: reference:: RepositoryReference as Repository , toolcache :: tool } ;
55use octocrab:: models:: repos:: { Asset , Release } ;
66
77async fn fetch_releases ( client : & octocrab:: Octocrab , repository : & Repository ) -> Result < Release > {
@@ -104,7 +104,14 @@ pub async fn fetch_extractor(
104104 match glob {
105105 Ok ( path) => {
106106 log:: debug!( "Extractor Path :: {path:?}" ) ;
107- return Ok ( path. parent ( ) . unwrap ( ) . to_path_buf ( ) . canonicalize ( ) ?) ;
107+ let full_path = path. parent ( ) . unwrap ( ) . to_path_buf ( ) . canonicalize ( ) ?;
108+ // Linux and Macos
109+ #[ cfg( unix) ]
110+ {
111+ update_tools_permisisons ( & full_path) ?;
112+ }
113+
114+ return Ok ( full_path) ;
108115 }
109116 Err ( e) => {
110117 log:: error!( "Failed to find extractor: {e}" ) ;
@@ -114,3 +121,43 @@ pub async fn fetch_extractor(
114121 }
115122 Ok ( extractor_pack)
116123}
124+
125+ /// Update the permissions for tool scripts (*.sh) and the extractor (extractor)
126+ fn update_tools_permisisons ( path : & PathBuf ) -> Result < ( ) > {
127+ let tools_path = path. join ( "tools" ) ;
128+ log:: info!( "Tools :: {tools_path:?}" ) ;
129+
130+ if tools_path. exists ( ) {
131+ log:: debug!( "Found tools directory at {tools_path:?}" ) ;
132+
133+ // Linux
134+ let linux_extractor = tools_path. join ( "linux64" ) . join ( "extractor" ) ;
135+ if linux_extractor. exists ( ) {
136+ set_permissions ( & linux_extractor) ?;
137+ }
138+ // Macos
139+ let macos_extractor = tools_path. join ( "osx64" ) . join ( "extractor" ) ;
140+ if macos_extractor. exists ( ) {
141+ set_permissions ( & macos_extractor) ?;
142+ }
143+
144+ for file in std:: fs:: read_dir ( & tools_path) ? {
145+ let file = file?;
146+ let path = file. path ( ) ;
147+
148+ if path. is_file ( ) && path. extension ( ) . map_or ( false , |ext| ext == "sh" ) {
149+ log:: debug!( "Setting executable permissions for {path:?}" ) ;
150+ set_permissions ( & path) ?;
151+ }
152+ }
153+ }
154+ Ok ( ( ) )
155+ }
156+
157+ /// Sets the file permissions to be executable
158+ fn set_permissions ( path : & PathBuf ) -> Result < ( ) > {
159+ log:: info!( "Setting permissions for :: {:?}" , path) ;
160+ let perms = std:: fs:: Permissions :: from_mode ( 0o555 ) ;
161+ std:: fs:: set_permissions ( & path, perms) ?;
162+ Ok ( ( ) )
163+ }
0 commit comments