Skip to content

Commit

Permalink
Set wsl-shell wrapper paths as action outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
Vampire committed Nov 28, 2020
1 parent b2fa99b commit 32a3fcc
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 18 deletions.
30 changes: 22 additions & 8 deletions .github/workflows/template/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,13 @@ jobs:
run: |
wsl sh -euc "[ '${{ steps.no_default_bash_provocation.outcome }}' = 'failure' ]"
- name: Delete wsl-bash
if: always()
&& (matrix.distribution.id == 'Alpine')
&& (steps.execute_action1.outcome == 'success')
shell: cmd
run: DEL /F "${{ steps.execute_action1.outputs.wsl-shell-wrapper-path }}"

- <<: *execute_action
name: Install Bash on Alpine
if: always()
Expand All @@ -387,7 +394,6 @@ jobs:
with:
distribution: ${{ matrix.distribution.id }}
additional-packages: bash
wsl-shell-command: bash --noprofile --norc -euo pipefail

- <<: *test_wsl-bash_should_be_available_as_custom_shell
if: always()
Expand Down Expand Up @@ -510,11 +516,11 @@ jobs:
ps -o pid='' -o comm='' | grep "^\s\+$$\s\+" | grep -o '\S\+$'
[ "$(ps -o pid='' -o comm='' 2>/dev/null | grep "^\s\+$$\s\+" | grep -o '\S\+$')" = 'sh' ]
- name: Test - delete wsl-bash
- name: Delete wsl-bash
if: always()
&& (steps.execute_action3.outcome == 'success')
shell: wsl-sh {0}
run: find "`wslpath '${{ runner.temp }}'`" -name wsl-bash.bat -print -delete 2>/dev/null
shell: cmd
run: DEL /F "${{ steps.execute_action1.outputs.wsl-shell-wrapper-path }}"

- name: Test - wsl-bash should not be present (provocation)
id: wsl-bash_absent_provocation
Expand All @@ -537,7 +543,6 @@ jobs:
id: execute_action4
with:
distribution: ${{ matrix.distribution.id }}
wsl-shell-command: bash --noprofile --norc -euo pipefail

- name: Test - wsl-bash should be present
if: always()
Expand Down Expand Up @@ -598,12 +603,15 @@ jobs:
whoami
[ "$(whoami)" == 'test' ]
- name: Delete wsl-bash
shell: cmd
run: DEL /F "${{ steps.execute_action6.outputs.wsl-shell-wrapper-path }}"

- <<: *execute_action
name: Set wsl-bash wrapper to use default user by default
id: execute_action7
with:
distribution: ${{ matrix.distribution.id }}
wsl-shell-command: bash --noprofile --norc -euo pipefail

- name: Test - wsl-bash should use root as default user
if: always()
Expand All @@ -620,13 +628,16 @@ jobs:
run: |
id -u test
- name: Delete wsl-bash
shell: cmd
run: DEL /F "${{ steps.execute_action7.outputs.wsl-shell-wrapper-path }}"

- <<: *execute_action
name: Set wsl-bash wrapper to use existing user test by default with extra parameter
id: execute_action8
with:
distribution: ${{ matrix.distribution.id }}
wsl-shell-user: test
wsl-shell-command: bash --noprofile --norc -euo pipefail

- name: Test - wsl-bash should use existing user test as default user with extra parameter
if: always()
Expand All @@ -643,13 +654,16 @@ jobs:
run: |
! id -u test2
- name: Delete wsl-bash
shell: cmd
run: DEL /F "${{ steps.execute_action8.outputs.wsl-shell-wrapper-path }}"

- <<: *execute_action
name: Set wsl-bash wrapper to use non-existing user test2 by default with extra parameter
id: execute_action9
with:
distribution: ${{ matrix.distribution.id }}
wsl-shell-user: test2
wsl-shell-command: bash --noprofile --norc -euo pipefail

- name: Test - wsl-bash should use auto-generated user test2 as default user
if: always()
Expand Down
26 changes: 17 additions & 9 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,11 @@ jobs:
name: "Test - wsl-bash should fail if bash is not present by default (verification)"
run: "wsl sh -euc \"[ '${{ steps.no_default_bash_provocation.outcome }}' = 'failure'\
\ ]\"\n"
- if: "always() && (matrix.distribution.id == 'Alpine') && (steps.execute_action1.outcome\
\ == 'success')"
name: "Delete wsl-bash"
run: "DEL /F \"${{ steps.execute_action1.outputs.wsl-shell-wrapper-path }}\""
shell: "cmd"
- id: "execute_action2"
if: "always() && (matrix.distribution.id == 'Alpine') && (steps.execute_action1.outcome\
\ == 'success')"
Expand All @@ -284,7 +289,6 @@ jobs:
with:
"distribution": "${{ matrix.distribution.id }}"
"additional-packages": "bash"
"wsl-shell-command": "bash --noprofile --norc -euo pipefail"
- if: "always() && (steps.execute_action1.outcome == 'success')"
name: "Test - wsl-bash should be available as custom shell"
run: ":\n"
Expand Down Expand Up @@ -408,10 +412,9 @@ jobs:
\ -o '\\S\\+$')\" = 'sh' ]\n"
shell: "wsl-sh {0}"
- if: "always() && (steps.execute_action3.outcome == 'success')"
name: "Test - delete wsl-bash"
run: "find \"`wslpath '${{ runner.temp }}'`\" -name wsl-bash.bat -print -delete\
\ 2>/dev/null"
shell: "wsl-sh {0}"
name: "Delete wsl-bash"
run: "DEL /F \"${{ steps.execute_action1.outputs.wsl-shell-wrapper-path }}\""
shell: "cmd"
- id: "wsl-bash_absent_provocation"
if: "always() && (steps.execute_action3.outcome == 'success')"
name: "Test - wsl-bash should not be present (provocation)"
Expand All @@ -427,7 +430,6 @@ jobs:
uses: "./"
with:
"distribution": "${{ matrix.distribution.id }}"
"wsl-shell-command": "bash --noprofile --norc -euo pipefail"
- if: "always() && (steps.execute_action4.outcome == 'success')"
name: "Test - wsl-bash should be present"
run: ":\n"
Expand Down Expand Up @@ -468,12 +470,14 @@ jobs:
name: "Test - wsl-bash should use test as default user with inline script usage"
run: "whoami\n[ \"$(whoami)\" == 'test' ]\n"
shell: "wsl-bash {0}"
- name: "Delete wsl-bash"
run: "DEL /F \"${{ steps.execute_action6.outputs.wsl-shell-wrapper-path }}\""
shell: "cmd"
- id: "execute_action7"
name: "Set wsl-bash wrapper to use default user by default"
uses: "./"
with:
"distribution": "${{ matrix.distribution.id }}"
"wsl-shell-command": "bash --noprofile --norc -euo pipefail"
- if: "always() && (steps.execute_action7.outcome == 'success')"
name: "Test - wsl-bash should use root as default user"
run: "whoami\n[ \"$(whoami)\" == 'root' ]\n"
Expand All @@ -482,14 +486,16 @@ jobs:
name: "Test - test user does already exist"
run: "id -u test\n"
shell: "wsl-bash {0}"
- name: "Delete wsl-bash"
run: "DEL /F \"${{ steps.execute_action7.outputs.wsl-shell-wrapper-path }}\""
shell: "cmd"
- id: "execute_action8"
name: "Set wsl-bash wrapper to use existing user test by default with extra\
\ parameter"
uses: "./"
with:
"distribution": "${{ matrix.distribution.id }}"
"wsl-shell-user": "test"
"wsl-shell-command": "bash --noprofile --norc -euo pipefail"
- if: "always() && (steps.execute_action8.outcome == 'success')"
name: "Test - wsl-bash should use existing user test as default user with extra\
\ parameter"
Expand All @@ -499,14 +505,16 @@ jobs:
name: "Test - test2 user does not exist"
run: "! id -u test2\n"
shell: "wsl-bash {0}"
- name: "Delete wsl-bash"
run: "DEL /F \"${{ steps.execute_action8.outputs.wsl-shell-wrapper-path }}\""
shell: "cmd"
- id: "execute_action9"
name: "Set wsl-bash wrapper to use non-existing user test2 by default with extra\
\ parameter"
uses: "./"
with:
"distribution": "${{ matrix.distribution.id }}"
"wsl-shell-user": "test2"
"wsl-shell-command": "bash --noprofile --norc -euo pipefail"
- if: "always() && (steps.execute_action9.outcome == 'success')"
name: "Test - wsl-bash should use auto-generated user test2 as default user"
run: "whoami\n[ \"$(whoami)\" == 'test2' ]\n"
Expand Down
13 changes: 13 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,19 @@ inputs:
additional ones for other shells.
required: false

outputs:
wsl-shell-wrapper-path:
description: |
The path to the wsl-shell wrapper that is generated by the current action invocation.
Even if the current action invocation does not actually generate the script, because
wsl-shell-command is not set explicitly and the script already exists, this output will be set.
wsl-shell-distribution-wrapper-path:
description: |
The path to the distribution-specific wsl-shell wrapper that is generated by the current action invocation.
Even if the current action invocation does not actually generate the script, because
wsl-shell-command is not set explicitly and the script already exists, this output will be set.
runs:
using: node12
main: build/distributions/index.js
26 changes: 25 additions & 1 deletion readme/README_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ Table of Contents
* [additional-packages](#additional-packages)
* [wsl-shell-user](#wsl-shell-user)
* [wsl-shell-command](#wsl-shell-command)
* [Outputs](#outputs)
* [wsl-shell-wrapper-path](#wsl-shell-wrapper-path)
* [wsl-shell-distribution-wrapper-path](#wsl-shell-distribution-wrapper-path)
* [Version Numbers](#version-numbers)
* [License](#license)

Expand Down Expand Up @@ -251,7 +254,9 @@ This input can also be used if the distribution is installed already to change t
additional ones for other shells. Already existing wsl-shell wrapper scripts are only overwritten, if this input
is set to a value explicitly. Non-existing wrapper scripts are always generated. So if you want to change the
default user using the [`wsl-shell-user` input](#wsl-shell-user), you either have to first delete the wrapper script
or scripts that should be regenerated or specify a value for this input explicitly.
or scripts that should be regenerated or specify a value for this input explicitly. To delete the wsl-shell wrapper
scripts, the [`wsl-shell-wrapper-path` output](#wsl-shell-wrapper-path) and
[`wsl-shell-distribution-wrapper-path` output](#wsl-shell-distribution-wrapper-path) can be used.

**Default value:** `bash --noprofile --norc -euo pipefail`

Expand Down Expand Up @@ -281,10 +286,29 @@ _**Examples:**_
- shell: wsl-bash {0}
run: id
- shell: cmd
run: DEL /F "\${{ steps.execute_action.outputs.wsl-shell-wrapper-path }}"
```



### Outputs

#### wsl-shell-wrapper-path

The path to the wsl-shell wrapper that is generated by the current action invocation.
Even if the current action invocation does not actually generate the script, because
wsl-shell-command is not set explicitly and the script already exists, this output will be set.

#### wsl-shell-distribution-wrapper-path

The path to the distribution-specific wsl-shell wrapper that is generated by the current action invocation.
Even if the current action invocation does not actually generate the script, because
wsl-shell-command is not set explicitly and the script already exists, this output will be set.



Version Numbers
---------------

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import process
import restoreCache
import saveCache
import setFailed
import setOutput
import startGroup
import warning
import which
Expand Down Expand Up @@ -244,6 +245,9 @@ suspend fun main() {
|| !existsSync(wslShellDistributionWrapperPath)) {
group("Write WSL Shell Wrapper", ::writeWslShellWrapper)
}

setOutput("wsl-shell-wrapper-path", wslShellWrapperPath)
setOutput("wsl-shell-distribution-wrapper-path", wslShellDistributionWrapperPath)
}.onFailure {
debug(it.stackTraceToString())
setFailed(it.message ?: "$it")
Expand Down

0 comments on commit 32a3fcc

Please sign in to comment.