Skip to content

Commit ed21b6a

Browse files
authored
feat: Add getHomeDir() for windows (#86)
1 parent 9f11da8 commit ed21b6a

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

.github/workflows/test-action.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,12 @@ jobs:
2323
runs-on: ${{ matrix.os }}
2424
if: contains(github.event.head_commit.message, '[skip ci]') == false
2525
strategy:
26+
max-parallel: 1
2627
matrix:
2728
os:
2829
- 'ubuntu-18.04'
29-
# - 'macos-latest'
30-
# - 'windows-latest'
30+
- 'macos-latest'
31+
- 'windows-latest'
3132
steps:
3233

3334
- uses: actions/checkout@v2
@@ -66,7 +67,7 @@ jobs:
6667
with:
6768
deploy_key: ${{ secrets.ACTIONS_DEPLOY_KEY }}
6869
# github_token: ${{ secrets.GITHUB_TOKEN }}
69-
# publish_branch: master
70+
# publish_branch: gh-pages
7071
publish_dir: ./test_projects/mdbook/book
7172
# external_repository: ''
7273
allow_empty_commit: true

src/set-tokens.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,24 @@ import * as github from '@actions/github';
44
import * as io from '@actions/io';
55
import path from 'path';
66
import fs from 'fs';
7+
const cpSpawnSync = require('child_process').spawnSync;
78
const cpexec = require('child_process').execFileSync;
89
import {Inputs} from './interfaces';
910

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+
1025
export function setPublishRepo(insp: Inputs): string {
1126
if (insp.ExternalRepository) {
1227
return insp.ExternalRepository;
@@ -20,7 +35,8 @@ export async function setSSHKey(
2035
): Promise<string> {
2136
core.info('[INFO] setup SSH deploy key');
2237

23-
const sshDir = path.join(`${process.env.HOME}`, '.ssh');
38+
const homeDir = getHomeDir();
39+
const sshDir = path.join(homeDir, '.ssh');
2440
await io.mkdirP(sshDir);
2541
await exec.exec('chmod', ['700', sshDir]);
2642

@@ -50,6 +66,12 @@ Host github
5066
core.info(`[INFO] wrote ${sshConfigPath}`);
5167
await exec.exec('chmod', ['600', sshConfigPath]);
5268

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+
}
5375
await cpexec('ssh-agent', ['-a', '/tmp/ssh-auth.sock']);
5476
core.exportVariable('SSH_AUTH_SOCK', '/tmp/ssh-auth.sock');
5577
await exec.exec('ssh-add', [idRSA]);

0 commit comments

Comments
 (0)