Skip to content

Commit 5124e2e

Browse files
authored
Add shell input (#5)
* Add miniconda-setup to workflow for testing * Testing own shell impl * Debug shell input * Add tests for shell input
1 parent e5be7d1 commit 5124e2e

File tree

6 files changed

+95
-7
lines changed

6 files changed

+95
-7
lines changed

.github/workflows/test.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,34 @@ jobs:
1717
npm run all
1818
1919
test: # make sure the action works on a clean machine without building
20+
21+
defaults:
22+
run:
23+
shell: bash -l {0} # for setup-miniconda
24+
2025
strategy:
2126
matrix:
2227
os: [ubuntu-latest, windows-latest, macos-latest]
2328
runs-on: ${{ matrix.os }}
29+
2430
steps:
2531
- uses: actions/checkout@v2
2632

33+
- uses: conda-incubator/setup-miniconda@v2
34+
with:
35+
mamba-version: "*"
36+
channels: conda-forge
37+
channel-priority: strict
38+
python-version: '3.10'
39+
2740
- uses: ./
2841
name: "Run action from local source (./)"
2942
with:
43+
shell: bash -el {0}
3044
run: |
45+
env
46+
which python
47+
conda run which python
3148
echo "this is where your commands would run"
3249
echo "multiple commands are entered as multi-line input"
3350
linux-setup-delay: 500

__tests__/main.test.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,36 @@ test("test working dir", () => {
6868
);
6969
});
7070

71+
test("test shell input", () => {
72+
const env: { [key: string]: string } = { ...process.env } as {
73+
[key: string]: string;
74+
};
75+
env["INPUT_RUN"] = "shopt -q login_shell && echo 'login shell'";
76+
env["INPUT_SHELL"] = "bash -l {0}";
77+
const options: ExecFileSyncOptions = {
78+
env: env,
79+
};
80+
81+
const np = process.execPath;
82+
const ip = path.join(__dirname, "..", "lib", "main.js");
83+
expect(execFileSync(np, [ip], options).toString()).toContain("login shell");
84+
});
85+
86+
test("test shell input middle", () => {
87+
const env: { [key: string]: string } = { ...process.env } as {
88+
[key: string]: string;
89+
};
90+
env["INPUT_RUN"] = "shopt -q login_shell && echo 'login shell'";
91+
env["INPUT_SHELL"] = "bash -l {0} -e";
92+
const options: ExecFileSyncOptions = {
93+
env: env,
94+
};
95+
96+
const np = process.execPath;
97+
const ip = path.join(__dirname, "..", "lib", "main.js");
98+
expect(execFileSync(np, [ip], options).toString()).toContain("login shell");
99+
});
100+
71101
test("test failing command", () => {
72102
const env: { [key: string]: string } = { ...process.env } as {
73103
[key: string]: string;

action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ inputs:
44
run:
55
description: 'commands to execute'
66
required: true
7+
shell:
8+
description: 'shell in which to execute commands from `run` input'
9+
required: false
10+
default: ""
711
linux-pkgs:
812
description: 'additional packages to install on linux runner'
913
required: false

dist/index.js

Lines changed: 22 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,12 @@ async function startXvfb(env: { [key: string]: string }): Promise<string[]> {
8181
const result = output.stdout.split("\n");
8282
console.log("sleep for 1000ms");
8383
await sleep(1000);
84+
console.log("::endgroup::");
8485
return [result[0], result[1]];
8586
} else {
87+
console.log("::endgroup::");
8688
throw new Error(`failed to start Xvfb, exit code '${output.exitCode}'`);
8789
}
88-
console.log("::endgroup::");
8990
}
9091

9192
async function killAllXvfb(sig = 15) {
@@ -100,8 +101,25 @@ async function runCommands(commands: string[], env: { [key: string]: string }) {
100101
options.cwd = working_dir;
101102
}
102103

103-
for (const command of commands) {
104-
await exec.exec(command, [], options);
104+
const shell = core.getInput("shell");
105+
if (shell) {
106+
const [shell_bin, ...shell_args] = shell.split(" ");
107+
const placeholderIndex = shell_args.indexOf("{0}");
108+
109+
for (const command of commands) {
110+
const args = [...shell_args];
111+
if (placeholderIndex > 0) {
112+
args.splice(placeholderIndex, 1, "-c", command);
113+
} else {
114+
args.push("-c", command);
115+
}
116+
core.debug(`exec: args: ${shell_bin}, args: ${args}`);
117+
await exec.exec(shell_bin, args, options);
118+
}
119+
} else {
120+
for (const command of commands) {
121+
await exec.exec(command, [], options);
122+
}
105123
}
106124
}
107125

0 commit comments

Comments
 (0)