Skip to content

Commit

Permalink
feat(shell): checks only the shell name and allows any argument (#118)
Browse files Browse the repository at this point in the history
Co-authored-by: ureciocais <urecio@caisgroup.com>
Co-authored-by: Nick Fields <46869826+nick-fields@users.noreply.github.com>
  • Loading branch information
3 people committed Sep 26, 2023
1 parent 1d41e5d commit 1139f99
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
11 changes: 6 additions & 5 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -948,7 +948,8 @@ function getExecutable(inputs) {
return OS === 'win32' ? 'powershell' : 'bash';
}
var executable;
switch (inputs.shell) {
var shellName = inputs.shell.split(' ')[0];
switch (shellName) {
case 'bash':
case 'python':
case 'pwsh': {
Expand All @@ -957,21 +958,21 @@ function getExecutable(inputs) {
}
case 'sh': {
if (OS === 'win32') {
throw new Error("Shell ".concat(inputs.shell, " not allowed on OS ").concat(OS));
throw new Error("Shell ".concat(shellName, " not allowed on OS ").concat(OS));
}
executable = inputs.shell;
break;
}
case 'cmd':
case 'powershell': {
if (OS !== 'win32') {
throw new Error("Shell ".concat(inputs.shell, " not allowed on OS ").concat(OS));
throw new Error("Shell ".concat(shellName, " not allowed on OS ").concat(OS));
}
executable = inputs.shell + '.exe';
executable = shellName + '.exe' + inputs.shell.replace(shellName, '');
break;
}
default: {
throw new Error("Shell ".concat(inputs.shell, " not supported. See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsshell for supported shells"));
throw new Error("Shell ".concat(shellName, " not supported. See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsshell for supported shells"));
}
}
return executable;
Expand Down
12 changes: 7 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ function getExecutable(inputs: Inputs): string {
}

let executable: string;
switch (inputs.shell) {
const shellName = inputs.shell.split(' ')[0];

switch (shellName) {
case 'bash':
case 'python':
case 'pwsh': {
Expand All @@ -29,22 +31,22 @@ function getExecutable(inputs: Inputs): string {
}
case 'sh': {
if (OS === 'win32') {
throw new Error(`Shell ${inputs.shell} not allowed on OS ${OS}`);
throw new Error(`Shell ${shellName} not allowed on OS ${OS}`);
}
executable = inputs.shell;
break;
}
case 'cmd':
case 'powershell': {
if (OS !== 'win32') {
throw new Error(`Shell ${inputs.shell} not allowed on OS ${OS}`);
throw new Error(`Shell ${shellName} not allowed on OS ${OS}`);
}
executable = inputs.shell + '.exe';
executable = shellName + '.exe' + inputs.shell.replace(shellName, '');
break;
}
default: {
throw new Error(
`Shell ${inputs.shell} not supported. See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsshell for supported shells`
`Shell ${shellName} not supported. See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsshell for supported shells`
);
}
}
Expand Down

0 comments on commit 1139f99

Please sign in to comment.