@@ -4,9 +4,24 @@ import * as github from '@actions/github';
4
4
import * as io from '@actions/io' ;
5
5
import path from 'path' ;
6
6
import fs from 'fs' ;
7
+ const cpSpawnSync = require ( 'child_process' ) . spawnSync ;
7
8
const cpexec = require ( 'child_process' ) . execFileSync ;
8
9
import { Inputs } from './interfaces' ;
9
10
11
+ export function getHomeDir ( ) : string {
12
+ let homedir = '' ;
13
+
14
+ if ( process . platform === 'win32' ) {
15
+ homedir = process . env [ 'USERPROFILE' ] || 'C:\\' ;
16
+ } else {
17
+ homedir = `${ process . env . HOME } ` ;
18
+ }
19
+
20
+ core . debug ( `homeDir: ${ homedir } ` ) ;
21
+
22
+ return homedir ;
23
+ }
24
+
10
25
export function setPublishRepo ( insp : Inputs ) : string {
11
26
if ( insp . ExternalRepository ) {
12
27
return insp . ExternalRepository ;
@@ -20,7 +35,8 @@ export async function setSSHKey(
20
35
) : Promise < string > {
21
36
core . info ( '[INFO] setup SSH deploy key' ) ;
22
37
23
- const sshDir = path . join ( `${ process . env . HOME } ` , '.ssh' ) ;
38
+ const homeDir = getHomeDir ( ) ;
39
+ const sshDir = path . join ( homeDir , '.ssh' ) ;
24
40
await io . mkdirP ( sshDir ) ;
25
41
await exec . exec ( 'chmod' , [ '700' , sshDir ] ) ;
26
42
@@ -50,6 +66,12 @@ Host github
50
66
core . info ( `[INFO] wrote ${ sshConfigPath } ` ) ;
51
67
await exec . exec ( 'chmod' , [ '600' , sshConfigPath ] ) ;
52
68
69
+ if ( process . platform === 'win32' ) {
70
+ await cpSpawnSync ( 'Start-Process' , [ 'powershell.exe' , '-Verb' , 'runas' ] ) ;
71
+ await cpSpawnSync ( 'sh' , [ '-c' , '\'eval "$(ssh-agent)"\'' ] , { shell : true } ) ;
72
+ await exec . exec ( 'sc' , [ 'config' , 'ssh-agent' , 'start=auto' ] ) ;
73
+ await exec . exec ( 'sc' , [ 'start' , 'ssh-agent' ] ) ;
74
+ }
53
75
await cpexec ( 'ssh-agent' , [ '-a' , '/tmp/ssh-auth.sock' ] ) ;
54
76
core . exportVariable ( 'SSH_AUTH_SOCK' , '/tmp/ssh-auth.sock' ) ;
55
77
await exec . exec ( 'ssh-add' , [ idRSA ] ) ;
0 commit comments