Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Allow different shell for post #10

Merged
merged 10 commits into from
Jun 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,11 @@ jobs:
echo "bar"
echo baz \ blah \
boom

- name: Change post shell
uses: ./
with:
run: if [ "$0" = "/usr/bin/sh" ]; then echo "Test passed"; else exit 1; fi
shell: sh
post: if [ "$0" = "/usr/bin/bash" ]; then echo "Test passed"; else exit 1; fi
post-shell: bash
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,13 @@ This above configuration will produce the following:

Following inputs can be used as `step.with` keys:

| Name | Type | Default | Required | Description |
|---------------------|:------------------:|:-------:|:--------:|----------------------------------------------------------------|
| `run` | `string` or `list` | | no | A commands that needs to be run in place. |
| `post` | `string` or `list` | | yes | A commands that needs to be run once a workflow job has ended. |
| `working-directory` | `string` | | no | A working directory from which the command needs to be run. |
| `shell` | `string` | `bash` | no | A shell to use for executing commands. |
| Name | Type | Default | Required | Description |
|---------------------|:------------------:|:-------:|:--------:|-----------------------------------------------------------------------------|
| `run` | `string` or `list` | | no | A commands that needs to be run in place. |
| `post` | `string` or `list` | | yes | A commands that needs to be run once a workflow job has ended. |
| `working-directory` | `string` | | no | A working directory from which the command needs to be run. |
| `shell` | `string` | `bash` | no | A shell to use for executing `run` commands. |
| `post-shell` | `string` | | no | A shell to use for executing `post` commands. Defaults to value of `shell`. |

## Releasing

Expand Down
5 changes: 4 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@ inputs:
description: A working directory from which the command needs to be run.
required: false
shell:
description: A shell to use for executing commands. Set to empty string to use the direct command call.
description: A shell to use for executing run commands. Set to empty string to use the direct command call.
required: false
default: bash
post-shell:
description: A shell to use for executing post commands. Defaults to value of shell input.
required: false

runs:
using: 'node16'
Expand Down
2 changes: 1 addition & 1 deletion dist/main/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/post/index.js

Large diffs are not rendered by default.

12 changes: 7 additions & 5 deletions src/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ const input = {
post: core.getMultilineInput('post', {required: true}),
workingDirectory: core.getInput('working-directory'),
shell: core.getInput('shell'),
postShell: core.getInput('post-shell'),
};

export async function run() {
return runCommands(joinMultilineCommands(input.run))
return runCommands(joinMultilineCommands(input.run), input.shell)
}

export async function post() {
return runCommands(joinMultilineCommands(input.post))
return runCommands(joinMultilineCommands(input.post), input.postShell ? input.postShell : input.shell)
}

/**
Expand All @@ -42,8 +43,9 @@ function joinMultilineCommands(commands) {

/**
* @param {String[]} commands
* @param {String[]} shell
*/
async function runCommands(commands) {
async function runCommands(commands, shell) {
/** @type {import('@actions/exec/lib/interfaces').ExecOptions} */
const options = {
cwd: input.workingDirectory,
Expand All @@ -60,9 +62,9 @@ async function runCommands(commands) {
if (command !== "") {
core.info(`\x1b[1m$ ${command}\x1b[0m`)

let exitCode = input.shell === ""
let exitCode = shell === ""
? await exec.exec(command, [], options)
: await exec.exec(input.shell, ['-c', command], options)
: await exec.exec(shell, ['-c', command], options)

if (exitCode !== 0) {
core.setFailed(`Command failed with exit code ${exitCode}`)
Expand Down