Skip to content

Commit

Permalink
Add possibility to use run-step script inline in the wsl-shell-command
Browse files Browse the repository at this point in the history
  • Loading branch information
Vampire committed Nov 27, 2020
1 parent 9ecc193 commit 545d2e0
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 8 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/template/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,21 @@ jobs:
whoami
[ "$(whoami)" == 'test' ]
- <<: *execute_action
name: Set wsl-bash wrapper to use user test by default with inline script usage
id: execute_action6
with:
distribution: ${{ matrix.distribution.id }}
wsl-shell-command: bash -c "sudo -u test bash --noprofile --norc -euo pipefail '{0}'"

- name: Test - wsl-bash should use test as default user with inline script usage
if: always()
&& (steps.execute_action6.outcome == 'success')
shell: wsl-bash {0}
run: |
whoami
[ "$(whoami)" == 'test' ]
strategy: &distributions_matrix
fail-fast: false
matrix:
Expand Down
11 changes: 11 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,17 @@ jobs:
name: "Test - wsl-bash should use test as default user"
run: "whoami\n[ \"$(whoami)\" == 'test' ]\n"
shell: "wsl-bash {0}"
- id: "execute_action6"
name: "Set wsl-bash wrapper to use user test by default with inline script usage"
uses: "./"
with:
"distribution": "${{ matrix.distribution.id }}"
"wsl-shell-command": "bash -c \"sudo -u test bash --noprofile --norc -euo\
\ pipefail '{0}'\""
- if: "always() && (steps.execute_action6.outcome == 'success')"
name: "Test - wsl-bash should use test as default user with inline script usage"
run: "whoami\n[ \"$(whoami)\" == 'test' ]\n"
shell: "wsl-bash {0}"
strategy:
matrix:
"distribution":
Expand Down
8 changes: 6 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,12 @@ inputs:
The command that is used in the wsl-shell wrapper scripts to execute the run-step script.
The name of the wrapper scripts will be derived from the first word in this input prefixed with 'wsl-'.
This means that for the default value, the wrapper scripts will start with 'wsl-bash'.
The run-step script will be given as additional parameter after the given string.
This can also be used if the distribution is installed already to change the wrapper scripts or generate
The run-step script file will be given as additional parameter in single quotes after the given string,
separated with one space character. The latter point is important, if you need to escape this space character.
If the given string contains at least once the sequence '{0}', all occurrences of it will be replaced by the
run-step script file without any quotes or anything and it will not be given as additional parameter.
This can be used if the script file is needed within the shell command opposed to as additional parameter.
This input can also be used if the distribution is installed already to change the wrapper scripts or generate
additional ones for other shells.
required: false
default: bash --noprofile --norc -euo pipefail
Expand Down
23 changes: 18 additions & 5 deletions readme/README_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,19 @@ _**Example:**_

#### wsl-shell-command

The command that is used in the wsl-shell wrapper scripts to execute the `run`-step script.
The command that is used in the wsl-shell wrapper scripts to execute the `run`-step script file.
The name of the wrapper scripts will be derived from the first word in this input prefixed with `wsl-`.
This means that for the default value, the wrapper scripts will start with `wsl-bash`.
The `run`-step script will be given as additional parameter after the given string,
separated with one space character. The latter point is important,
if you need to escape this space character as shown in the examples.
This can also be used if the distribution is installed already to change the wrapper scripts or generate

The `run`-step script file will be given as additional parameter in single quotes after the given string,
separated with one space character. The latter point is important, if you need to escape this space character
as shown in the examples.

If the given string contains at least once the sequence `{0}`, all occurrences of it will be replaced by the
`run`-step script file without any quotes or anything and it will not be given as additional parameter.
This can be used if the script file is needed within the shell command opposed to as additional parameter.

This input can also be used if the distribution is installed already to change the wrapper scripts or generate
additional ones for other shells.

**Default value:** `bash --noprofile --norc -euo pipefail`
Expand All @@ -237,6 +243,13 @@ _**Examples:**_
with:
wsl-shell-command: bash -c "sudo -u test bash --noprofile --norc -euo pipefail "\
- shell: wsl-bash {0}
run: id
- uses: Vampire/setup-wsl@v$majorVersion
with:
wsl-shell-command: bash -c "sudo -u test bash --noprofile --norc -euo pipefail '{0}'"
- shell: wsl-bash {0}
run: id
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,13 @@ suspend fun writeWslShellWrapper() {
)
FOR /F "tokens=* usebackq" %%F IN (`wsl <wsl distribution parameter> wslpath '%~1'`) DO SET wsl_script=%%F
wsl <wsl distribution parameter> sed -i 's/\r$//' '%wsl_script%'
wsl <wsl distribution parameter> $wslShellCommand '%wsl_script%'
wsl <wsl distribution parameter> ${
if (wslShellCommand.contains("{0}")) {
wslShellCommand.replace("{0}", "%wsl_script%")
} else {
"$wslShellCommand '%wsl_script%'"
}
}
""").trimIndent().lines().joinToString("\r\n")

writeFileSync(
Expand Down

0 comments on commit 545d2e0

Please sign in to comment.