diff --git a/.github/workflows/template/test.yml b/.github/workflows/template/test.yml index dcf39214..e4507c05 100644 --- a/.github/workflows/template/test.yml +++ b/.github/workflows/template/test.yml @@ -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: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c12a1366..ae35a3a3 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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": diff --git a/action.yml b/action.yml index 60c8a594..fd09e729 100644 --- a/action.yml +++ b/action.yml @@ -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 diff --git a/readme/README_template.md b/readme/README_template.md index e1f8e160..3f52d324 100644 --- a/readme/README_template.md +++ b/readme/README_template.md @@ -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` @@ -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 ``` diff --git a/src/main/kotlin/net/kautler/github/action/setup_wsl/SetupWsl.kt b/src/main/kotlin/net/kautler/github/action/setup_wsl/SetupWsl.kt index 09c1f722..b83997a4 100644 --- a/src/main/kotlin/net/kautler/github/action/setup_wsl/SetupWsl.kt +++ b/src/main/kotlin/net/kautler/github/action/setup_wsl/SetupWsl.kt @@ -296,7 +296,13 @@ suspend fun writeWslShellWrapper() { ) FOR /F "tokens=* usebackq" %%F IN (`wsl wslpath '%~1'`) DO SET wsl_script=%%F wsl sed -i 's/\r$//' '%wsl_script%' - wsl $wslShellCommand '%wsl_script%' + wsl ${ + if (wslShellCommand.contains("{0}")) { + wslShellCommand.replace("{0}", "%wsl_script%") + } else { + "$wslShellCommand '%wsl_script%'" + } + } """).trimIndent().lines().joinToString("\r\n") writeFileSync(