feat: Add getHomeDir() for windows (#86)
This commit is contained in:
parent
9f11da81ae
commit
ed21b6a594
|
@ -23,11 +23,12 @@ jobs:
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
if: contains(github.event.head_commit.message, '[skip ci]') == false
|
if: contains(github.event.head_commit.message, '[skip ci]') == false
|
||||||
strategy:
|
strategy:
|
||||||
|
max-parallel: 1
|
||||||
matrix:
|
matrix:
|
||||||
os:
|
os:
|
||||||
- 'ubuntu-18.04'
|
- 'ubuntu-18.04'
|
||||||
# - 'macos-latest'
|
- 'macos-latest'
|
||||||
# - 'windows-latest'
|
- 'windows-latest'
|
||||||
steps:
|
steps:
|
||||||
|
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
|
@ -66,7 +67,7 @@ jobs:
|
||||||
with:
|
with:
|
||||||
deploy_key: ${{ secrets.ACTIONS_DEPLOY_KEY }}
|
deploy_key: ${{ secrets.ACTIONS_DEPLOY_KEY }}
|
||||||
# github_token: ${{ secrets.GITHUB_TOKEN }}
|
# github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
# publish_branch: master
|
# publish_branch: gh-pages
|
||||||
publish_dir: ./test_projects/mdbook/book
|
publish_dir: ./test_projects/mdbook/book
|
||||||
# external_repository: ''
|
# external_repository: ''
|
||||||
allow_empty_commit: true
|
allow_empty_commit: true
|
||||||
|
|
|
@ -4,9 +4,24 @@ import * as github from '@actions/github';
|
||||||
import * as io from '@actions/io';
|
import * as io from '@actions/io';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
|
const cpSpawnSync = require('child_process').spawnSync;
|
||||||
const cpexec = require('child_process').execFileSync;
|
const cpexec = require('child_process').execFileSync;
|
||||||
import {Inputs} from './interfaces';
|
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 {
|
export function setPublishRepo(insp: Inputs): string {
|
||||||
if (insp.ExternalRepository) {
|
if (insp.ExternalRepository) {
|
||||||
return insp.ExternalRepository;
|
return insp.ExternalRepository;
|
||||||
|
@ -20,7 +35,8 @@ export async function setSSHKey(
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
core.info('[INFO] setup SSH deploy key');
|
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 io.mkdirP(sshDir);
|
||||||
await exec.exec('chmod', ['700', sshDir]);
|
await exec.exec('chmod', ['700', sshDir]);
|
||||||
|
|
||||||
|
@ -50,6 +66,12 @@ Host github
|
||||||
core.info(`[INFO] wrote ${sshConfigPath}`);
|
core.info(`[INFO] wrote ${sshConfigPath}`);
|
||||||
await exec.exec('chmod', ['600', 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']);
|
await cpexec('ssh-agent', ['-a', '/tmp/ssh-auth.sock']);
|
||||||
core.exportVariable('SSH_AUTH_SOCK', '/tmp/ssh-auth.sock');
|
core.exportVariable('SSH_AUTH_SOCK', '/tmp/ssh-auth.sock');
|
||||||
await exec.exec('ssh-add', [idRSA]);
|
await exec.exec('ssh-add', [idRSA]);
|
||||||
|
|
Loading…
Reference in New Issue