Modifying js files to account for win support

pull/184/head
maishiroma 2022-05-16 12:01:51 -07:00
parent d95f760d49
commit 8e5895210d
6 changed files with 2749 additions and 2658 deletions

5329
dist/index.js generated vendored

File diff suppressed because it is too large Load Diff

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

View File

@ -4,8 +4,8 @@ import path from 'path';
describe('Action', () => { describe('Action', () => {
describe('compatibility check', () => { describe('compatibility check', () => {
it('throws for anything other than linux', () => { it('throws for anything other than linux or windows', () => {
if (process.platform !== 'linux') { if (process.platform !== 'linux' && process.platform !== 'win32') {
expect(() => Action.checkCompatibility()).toThrow(); expect(() => Action.checkCompatibility()).toThrow();
} else { } else {
expect(() => Action.checkCompatibility()).not.toThrow(); expect(() => Action.checkCompatibility()).not.toThrow();

View File

@ -2,7 +2,7 @@ import path from 'path';
const Action = { const Action = {
get supportedPlatforms() { get supportedPlatforms() {
return ['linux']; return ['linux', 'win32'];
}, },
get isRunningLocally() { get isRunningLocally() {

View File

@ -28,6 +28,44 @@ const Docker = {
testMode === 'all' ? ['playmode', 'editmode', 'COMBINE_RESULTS'] : [testMode] testMode === 'all' ? ['playmode', 'editmode', 'COMBINE_RESULTS'] : [testMode]
).join(';'); ).join(';');
const dockerPaths = new Map([
[
'linux',
new Map([
['shellCommand', '/bin/bash /dist/entrypoint.sh'],
['sshAgent', '/ssh-agent'],
['githubHome', '/root'],
['githubWorkflow', '/github/workflow'],
['githubWorkspace', '/github/workspace'],
['stepsPathParent', `${actionFolder}/steps`],
['stepsPathContainer', '/steps'],
['entrypointPathParent', `${actionFolder}/`],
['entrypointPathContainer', '/dist'],
['knownHostsParent', ' /home/runner/.ssh/known_hosts'],
['knownHostsContainer', '/root/.ssh/known_hosts'],
]),
],
[
'win32',
new Map([
['shellCommand', 'powershell C:\\dist\\entrypoint.ps1'],
['sshAgent', 'C:\\ssh-agent'],
['githubHome', 'C:\\root'],
['githubWorkflow', 'C:\\github\\workflow'],
['githubWorkspace', 'C:\\github\\workspace'],
['stepsPathParent', `${actionFolder}\\steps`],
['stepsPathContainer', 'C:\\steps'],
['entrypointPathParent', `${actionFolder}\\`],
['entrypointPathContainer', 'C:\\dist'],
['knownHostsParent', 'C:\\Users\\Administrator\\.ssh\\known_hosts'],
['knownHostsContainer', 'C:\\root\\.ssh\\known_hosts'],
]),
],
]);
const currentDockerPath = dockerPaths.get(process.platform);
const bindMountZ = process.platform === 'linux' ? ':z' : '';
const bindMountRO = process.platform === 'linux' ? ':ro' : '';
const command = `docker run \ const command = `docker run \
--workdir /github/workspace \ --workdir /github/workspace \
--rm \ --rm \
@ -51,7 +89,7 @@ const Docker = {
--env GITHUB_HEAD_REF \ --env GITHUB_HEAD_REF \
--env GITHUB_BASE_REF \ --env GITHUB_BASE_REF \
--env GITHUB_EVENT_NAME \ --env GITHUB_EVENT_NAME \
--env GITHUB_WORKSPACE=/github/workspace \ --env GITHUB_WORKSPACE="${currentDockerPath?.get('githubWorkspace')}" \
--env GITHUB_ACTION \ --env GITHUB_ACTION \
--env GITHUB_EVENT_PATH \ --env GITHUB_EVENT_PATH \
--env RUNNER_OS \ --env RUNNER_OS \
@ -59,18 +97,28 @@ const Docker = {
--env RUNNER_TEMP \ --env RUNNER_TEMP \
--env RUNNER_WORKSPACE \ --env RUNNER_WORKSPACE \
--env GIT_PRIVATE_TOKEN="${gitPrivateToken}" \ --env GIT_PRIVATE_TOKEN="${gitPrivateToken}" \
${sshAgent ? '--env SSH_AUTH_SOCK=/ssh-agent' : ''} \ ${sshAgent ? `--env SSH_AUTH_SOCK=${currentDockerPath?.get('sshAgent')}` : ''} \
--volume "${githubHome}":"/root:z" \ --volume "${githubHome}:${currentDockerPath?.get('githubHome')}${bindMountZ}" \
--volume "${githubWorkflow}":"/github/workflow:z" \ --volume "${githubWorkflow}:${currentDockerPath?.get('githubWorkflow')}${bindMountZ}" \
--volume "${workspace}":"/github/workspace:z" \ --volume "${workspace}:${currentDockerPath?.get('githubWorkspace')}${bindMountZ}" \
--volume "${actionFolder}/steps":"/steps:z" \ --volume "${currentDockerPath?.get('stepsPathParent')}:${currentDockerPath?.get(
--volume "${actionFolder}/entrypoint.sh":"/entrypoint.sh:z" \ 'stepsPathContainer',
${sshAgent ? `--volume ${sshAgent}:/ssh-agent` : ''} \ )}${bindMountZ}" \
${sshAgent ? '--volume /home/runner/.ssh/known_hosts:/root/.ssh/known_hosts:ro' : ''} \ --volume "${currentDockerPath?.get('entrypointPathParent')}:${currentDockerPath?.get(
'entrypointPathContainer',
)}${bindMountZ}" \
${sshAgent ? `--volume ${sshAgent}:${currentDockerPath?.get('sshAgent')}` : ''} \
${
sshAgent
? `--volume ${currentDockerPath?.get('knownHostParent')}${currentDockerPath?.get(
'knownHostContainer',
)}${bindMountRO}`
: ''
} \
${useHostNetwork ? '--net=host' : ''} \ ${useHostNetwork ? '--net=host' : ''} \
${githubToken ? '--env USE_EXIT_CODE=false' : '--env USE_EXIT_CODE=true'} \ ${githubToken ? '--env USE_EXIT_CODE=false' : '--env USE_EXIT_CODE=true'} \
${image} \ ${image} \
/bin/bash /entrypoint.sh`; ${currentDockerPath?.get('shellCommand')}`;
await exec(command, undefined, { silent }); await exec(command, undefined, { silent });
}, },

View File

@ -56,6 +56,8 @@ class ImageTag {
switch (platform) { switch (platform) {
case 'linux': case 'linux':
return 'ubuntu'; return 'ubuntu';
case 'win32':
return 'windows';
default: default:
throw new Error('The Operating System of this runner is not yet supported.'); throw new Error('The Operating System of this runner is not yet supported.');
} }