@@ -139,21 +139,25 @@ try {
139
139
fs . appendFileSync ( `${ homeSsh } /known_hosts` , '\ngithub.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOMqqnkVzrm0SdG6UOoqKLsabgH5C9okWi0dh2l9GKJl\n' ) ;
140
140
fs . appendFileSync ( `${ homeSsh } /known_hosts` , '\ngithub.com ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ==\n' ) ;
141
141
142
- console . log ( "Starting ssh-agent" ) ;
143
-
144
142
const authSock = core . getInput ( 'ssh-auth-sock' ) ;
145
143
const sshAgentArgs = ( authSock && authSock . length > 0 ) ? [ '-a' , authSock ] : [ ] ;
146
144
147
- // Extract auth socket path and agent pid and set them as job variables
148
- child_process . execFileSync ( sshAgent , sshAgentArgs ) . toString ( ) . split ( "\n" ) . forEach ( function ( line ) {
149
- const matches = / ^ ( S S H _ A U T H _ S O C K | S S H _ A G E N T _ P I D ) = ( .* ) ; e x p o r t \1/ . exec ( line ) ;
150
-
151
- if ( matches && matches . length > 0 ) {
152
- // This will also set process.env accordingly, so changes take effect for this script
153
- core . exportVariable ( matches [ 1 ] , matches [ 2 ] )
154
- console . log ( `${ matches [ 1 ] } =${ matches [ 2 ] } ` ) ;
155
- }
156
- } ) ;
145
+ if ( child_process . spawnSync ( sshAdd , [ '-l' ] , { env : { ...process . env , SSH_AUTH_SOCK : authSock || process . env . SSH_AUTH_SOCK } } ) === 0 ) {
146
+ console . log ( 'ssh-agent is already running, not starting a new one' )
147
+ } else {
148
+ console . log ( "Starting ssh-agent" ) ;
149
+
150
+ // Extract auth socket path and agent pid and set them as job variables
151
+ child_process . execFileSync ( sshAgent , sshAgentArgs ) . toString ( ) . split ( "\n" ) . forEach ( function ( line ) {
152
+ const matches = / ^ ( S S H _ A U T H _ S O C K | S S H _ A G E N T _ P I D ) = ( .* ) ; e x p o r t \1/ . exec ( line ) ;
153
+
154
+ if ( matches && matches . length > 0 ) {
155
+ // This will also set process.env accordingly, so changes take effect for this script
156
+ core . exportVariable ( matches [ 1 ] , matches [ 2 ] )
157
+ console . log ( `${ matches [ 1 ] } =${ matches [ 2 ] } ` ) ;
158
+ }
159
+ } ) ;
160
+ }
157
161
158
162
console . log ( "Adding private key(s) to agent" ) ;
159
163
0 commit comments