Skip to content

Commit

Permalink
feat: Add getHomeDir() for windows (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
peaceiris committed Feb 5, 2020
1 parent 9f11da8 commit ed21b6a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/test-action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ jobs:
runs-on: ${{ matrix.os }}
if: contains(github.event.head_commit.message, '[skip ci]') == false
strategy:
max-parallel: 1
matrix:
os:
- 'ubuntu-18.04'
# - 'macos-latest'
# - 'windows-latest'
- 'macos-latest'
- 'windows-latest'
steps:

- uses: actions/checkout@v2
Expand Down Expand Up @@ -66,7 +67,7 @@ jobs:
with:
deploy_key: ${{ secrets.ACTIONS_DEPLOY_KEY }}
# github_token: ${{ secrets.GITHUB_TOKEN }}
# publish_branch: master
# publish_branch: gh-pages
publish_dir: ./test_projects/mdbook/book
# external_repository: ''
allow_empty_commit: true
Expand Down
24 changes: 23 additions & 1 deletion src/set-tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,24 @@ import * as github from '@actions/github';
import * as io from '@actions/io';
import path from 'path';
import fs from 'fs';
const cpSpawnSync = require('child_process').spawnSync;
const cpexec = require('child_process').execFileSync;
import {Inputs} from './interfaces';

export function getHomeDir(): string {
let homedir = '';

if (process.platform === 'win32') {
homedir = process.env['USERPROFILE'] || 'C:\\';
} else {
homedir = `${process.env.HOME}`;
}

core.debug(`homeDir: ${homedir}`);

return homedir;
}

export function setPublishRepo(insp: Inputs): string {
if (insp.ExternalRepository) {
return insp.ExternalRepository;
Expand All @@ -20,7 +35,8 @@ export async function setSSHKey(
): Promise<string> {
core.info('[INFO] setup SSH deploy key');

const sshDir = path.join(`${process.env.HOME}`, '.ssh');
const homeDir = getHomeDir();
const sshDir = path.join(homeDir, '.ssh');
await io.mkdirP(sshDir);
await exec.exec('chmod', ['700', sshDir]);

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

if (process.platform === 'win32') {
await cpSpawnSync('Start-Process', ['powershell.exe', '-Verb', 'runas']);
await cpSpawnSync('sh', ['-c', '\'eval "$(ssh-agent)"\''], {shell: true});
await exec.exec('sc', ['config', 'ssh-agent', 'start=auto']);
await exec.exec('sc', ['start', 'ssh-agent']);
}
await cpexec('ssh-agent', ['-a', '/tmp/ssh-auth.sock']);
core.exportVariable('SSH_AUTH_SOCK', '/tmp/ssh-auth.sock');
await exec.exec('ssh-add', [idRSA]);
Expand Down

0 comments on commit ed21b6a

Please sign in to comment.