Skip to content

Commit

Permalink
Add possibility to configure /etc/wsl.conf conveniently (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vampire committed Feb 7, 2022
1 parent fb56596 commit d8d69ee
Show file tree
Hide file tree
Showing 6 changed files with 351 additions and 6 deletions.
140 changes: 135 additions & 5 deletions .github/workflows/template/test.yml
Expand Up @@ -714,6 +714,140 @@ jobs:
match-pattern: '*Ubuntu*16.04*'
default-absent-tool: dos2unix

test_wsl-conf_on_initial_execution:
name: Test /etc/wsl.conf handling on initial execution for "${{ matrix.distribution.user-id }}" distribution on ${{ matrix.environment }}
needs: build
runs-on: ${{ matrix.environment }}
steps:
- name: Restore built artifacts from cache
<<: *built_artifacts_cache

- <<: *execute_action
id: execute_action1
with:
distribution: ${{ matrix.distribution.user-id }}
wsl-conf: |
[automount]
options = uid=1000
- name: Delete wsl-bash
if: always()
&& (matrix.distribution.user-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()
&& (matrix.distribution.user-id == 'Alpine')
&& (steps.execute_action1.outcome == 'success')
id: execute_action2
with:
distribution: ${{ matrix.distribution.user-id }}
additional-packages: bash

- name: Test - /etc/wsl.conf should exist
if: always()
&& (steps.execute_action1.outcome == 'success')
shell: wsl-bash {0}
run: |
[ -f /etc/wsl.conf ]
cat /etc/wsl.conf
- name: Test - /mnt/c should be mounted with uid 1000
if: always()
&& (steps.execute_action1.outcome == 'success')
shell: wsl-bash {0}
run: |
ls -alh /mnt
[[ "$(stat -c %u /mnt/c)" == 1000 ]]
strategy: *distributions_matrix

test_wsl-conf_on_subsequent_execution:
name: Test /etc/wsl.conf handling on subsequent execution for "${{ matrix.distribution.user-id }}" distribution on ${{ matrix.environment }}
needs: build
runs-on: ${{ matrix.environment }}
steps:
- name: Restore built artifacts from cache
<<: *built_artifacts_cache

- <<: *execute_action
id: execute_action1
with:
distribution: ${{ matrix.distribution.user-id }}

- name: Delete wsl-bash
if: always()
&& (matrix.distribution.user-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()
&& (matrix.distribution.user-id == 'Alpine')
&& (steps.execute_action1.outcome == 'success')
id: execute_action2
with:
distribution: ${{ matrix.distribution.user-id }}
additional-packages: bash

- name: Test - /etc/wsl.conf should not exist
if: always()
&& (steps.execute_action1.outcome == 'success')
shell: wsl-bash {0}
run: |
[ ! -f /etc/wsl.conf ]
- name: |
Test - C: should be mounted at /mnt/c
if: always()
&& (steps.execute_action1.outcome == 'success')
shell: wsl-bash {0}
run: |
mount
mount | grep 'C:.* on /mnt/c'
- name: Test - /mnt/c should be mounted with uid 0
if: always()
&& (steps.execute_action1.outcome == 'success')
shell: wsl-bash {0}
run: |
ls -alh /mnt
[[ "$(stat -c %u /mnt/c)" == 0 ]]
- <<: *execute_action
id: execute_action3
if: always()
&& (steps.execute_action1.outcome == 'success')
with:
distribution: ${{ matrix.distribution.user-id }}
wsl-conf: |
[automount]
root = /
- name: Test - /etc/wsl.conf should exist
if: always()
&& (steps.execute_action3.outcome == 'success')
shell: wsl-bash {0}
run: |
[ -f /etc/wsl.conf ]
cat /etc/wsl.conf
- name: |
Test - C: should be mounted at /c
if: always()
&& (steps.execute_action3.outcome == 'success')
shell: wsl-bash {0}
run: |
mount
mount | grep 'C:.* on /c'
strategy: *distributions_matrix

test_additional_packages:
name: Test additional packages for "${{ matrix.distribution.user-id }}" distribution on ${{ matrix.environment }}
needs: build
Expand All @@ -740,11 +874,7 @@ jobs:
&& (steps.execute_action.outcome == 'success')
shell: wsl-bash {0}
run: bash -c true
strategy:
<<: *distributions_matrix
matrix:
environment: *environments
distribution: *distributions
strategy: *distributions_matrix

test_multiple_usage_with_different_distributions:
name: Test multiple usage with different distributions
Expand Down
166 changes: 166 additions & 0 deletions .github/workflows/test.yml
Expand Up @@ -547,6 +547,172 @@ jobs:
"match-pattern": "*Ubuntu*16.04*"
"default-absent-tool": "dos2unix"
fail-fast: false
"test_wsl-conf_on_initial_execution":
name: "Test /etc/wsl.conf handling on initial execution for \"${{ matrix.distribution.user-id\
\ }}\" distribution on ${{ matrix.environment }}"
needs: "build"
runs-on: "${{ matrix.environment }}"
steps:
- name: "Restore built artifacts from cache"
uses: "actions/cache@v2"
with:
"path": "action.yml\nbuild/distributions/\n"
"key": "${{ github.run_id }}"
- id: "execute_action1"
name: "Execute action"
uses: "./"
with:
"distribution": "${{ matrix.distribution.user-id }}"
"wsl-conf": "[automount]\noptions = uid=1000\n"
- if: "always() && (matrix.distribution.user-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.user-id == 'Alpine') && (steps.execute_action1.outcome\
\ == 'success')"
name: "Install Bash on Alpine"
uses: "./"
with:
"distribution": "${{ matrix.distribution.user-id }}"
"additional-packages": "bash"
- if: "always() && (steps.execute_action1.outcome == 'success')"
name: "Test - /etc/wsl.conf should exist"
run: "[ -f /etc/wsl.conf ]\ncat /etc/wsl.conf\n"
shell: "wsl-bash {0}"
- if: "always() && (steps.execute_action1.outcome == 'success')"
name: "Test - /mnt/c should be mounted with uid 1000"
run: "ls -alh /mnt\n[[ \"$(stat -c %u /mnt/c)\" == 1000 ]]\n"
shell: "wsl-bash {0}"
strategy:
matrix:
"environment":
- "windows-2019"
- "windows-2022"
- "windows-latest"
"distribution":
- "wsl-id": "Debian"
"user-id": "Debian"
"match-pattern": "*Debian*"
"default-absent-tool": "dos2unix"
- "wsl-id": "Alpine"
"user-id": "Alpine"
"match-pattern": "*Alpine*"
"default-absent-tool": "dos2unix"
- "wsl-id": "kali-linux"
"user-id": "kali-linux"
"match-pattern": "*Kali*"
"default-absent-tool": "dos2unix"
- "wsl-id": "openSUSE-Leap-15.2"
"user-id": "openSUSE-Leap-15.2"
"match-pattern": "*openSUSE*Leap*15.2*"
"default-absent-tool": "which"
- "wsl-id": "Ubuntu"
"user-id": "Ubuntu-20.04"
"match-pattern": "*Ubuntu*20.04*"
"default-absent-tool": "dos2unix"
- "wsl-id": "Ubuntu-18.04"
"user-id": "Ubuntu-18.04"
"match-pattern": "*Ubuntu*18.04*"
"default-absent-tool": "dos2unix"
- "wsl-id": "Ubuntu-16.04"
"user-id": "Ubuntu-16.04"
"match-pattern": "*Ubuntu*16.04*"
"default-absent-tool": "dos2unix"
fail-fast: false
"test_wsl-conf_on_subsequent_execution":
name: "Test /etc/wsl.conf handling on subsequent execution for \"${{ matrix.distribution.user-id\
\ }}\" distribution on ${{ matrix.environment }}"
needs: "build"
runs-on: "${{ matrix.environment }}"
steps:
- name: "Restore built artifacts from cache"
uses: "actions/cache@v2"
with:
"path": "action.yml\nbuild/distributions/\n"
"key": "${{ github.run_id }}"
- id: "execute_action1"
name: "Execute action"
uses: "./"
with:
"distribution": "${{ matrix.distribution.user-id }}"
- if: "always() && (matrix.distribution.user-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.user-id == 'Alpine') && (steps.execute_action1.outcome\
\ == 'success')"
name: "Install Bash on Alpine"
uses: "./"
with:
"distribution": "${{ matrix.distribution.user-id }}"
"additional-packages": "bash"
- if: "always() && (steps.execute_action1.outcome == 'success')"
name: "Test - /etc/wsl.conf should not exist"
run: "[ ! -f /etc/wsl.conf ]\n"
shell: "wsl-bash {0}"
- if: "always() && (steps.execute_action1.outcome == 'success')"
name: "Test - C: should be mounted at /mnt/c\n"
run: "mount\nmount | grep 'C:.* on /mnt/c'\n"
shell: "wsl-bash {0}"
- if: "always() && (steps.execute_action1.outcome == 'success')"
name: "Test - /mnt/c should be mounted with uid 0"
run: "ls -alh /mnt\n[[ \"$(stat -c %u /mnt/c)\" == 0 ]]\n"
shell: "wsl-bash {0}"
- id: "execute_action3"
if: "always() && (steps.execute_action1.outcome == 'success')"
name: "Execute action"
uses: "./"
with:
"distribution": "${{ matrix.distribution.user-id }}"
"wsl-conf": "[automount]\nroot = /\n"
- if: "always() && (steps.execute_action3.outcome == 'success')"
name: "Test - /etc/wsl.conf should exist"
run: "[ -f /etc/wsl.conf ]\ncat /etc/wsl.conf\n"
shell: "wsl-bash {0}"
- if: "always() && (steps.execute_action3.outcome == 'success')"
name: "Test - C: should be mounted at /c\n"
run: "mount\nmount | grep 'C:.* on /c'\n"
shell: "wsl-bash {0}"
strategy:
matrix:
"environment":
- "windows-2019"
- "windows-2022"
- "windows-latest"
"distribution":
- "wsl-id": "Debian"
"user-id": "Debian"
"match-pattern": "*Debian*"
"default-absent-tool": "dos2unix"
- "wsl-id": "Alpine"
"user-id": "Alpine"
"match-pattern": "*Alpine*"
"default-absent-tool": "dos2unix"
- "wsl-id": "kali-linux"
"user-id": "kali-linux"
"match-pattern": "*Kali*"
"default-absent-tool": "dos2unix"
- "wsl-id": "openSUSE-Leap-15.2"
"user-id": "openSUSE-Leap-15.2"
"match-pattern": "*openSUSE*Leap*15.2*"
"default-absent-tool": "which"
- "wsl-id": "Ubuntu"
"user-id": "Ubuntu-20.04"
"match-pattern": "*Ubuntu*20.04*"
"default-absent-tool": "dos2unix"
- "wsl-id": "Ubuntu-18.04"
"user-id": "Ubuntu-18.04"
"match-pattern": "*Ubuntu*18.04*"
"default-absent-tool": "dos2unix"
- "wsl-id": "Ubuntu-16.04"
"user-id": "Ubuntu-16.04"
"match-pattern": "*Ubuntu*16.04*"
"default-absent-tool": "dos2unix"
fail-fast: false
"test_additional_packages":
name: "Test additional packages for \"${{ matrix.distribution.user-id }}\" distribution\
\ on ${{ matrix.environment }}"
Expand Down
8 changes: 8 additions & 0 deletions action.yml
Expand Up @@ -37,6 +37,14 @@ inputs:
required: false
default: 'true'

wsl-conf:
description: |
The content that will be written to /etc/wsl.conf of the installed distribution.
This can be used to adjust various settings as documented at
https://docs.microsoft.com/en-us/windows/wsl/wsl-config#configuration-settings-for-wslconf.
This can also be used if the distribution is installed already.
required: false

set-as-default:
description: |
Whether to set the distribution as default WSL distribution.
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.

group = net.kautler
version = 1.1.2-SNAPSHOT
version = 1.2.0-SNAPSHOT
description = A GitHub action to install and setup a Linux distribution for the Windows Subsystem for Linux (WSL)

org.gradle.caching = true
19 changes: 19 additions & 0 deletions readme/README_template.md
Expand Up @@ -31,6 +31,7 @@ Table of Contents
* [Inputs](#inputs)
* [distribution](#distribution)
* [use-cache](#use-cache)
* [wsl-conf](#wsl-conf)
* [set-as-default](#set-as-default)
* [update](#update)
* [additional-packages](#additional-packages)
Expand Down Expand Up @@ -173,6 +174,24 @@ _**Example:**_
use-cache: 'false'
```

#### wsl-conf

The content that will be written to /etc/wsl.conf of the installed distribution.
This can be used to adjust various settings as documented at
https://docs.microsoft.com/en-us/windows/wsl/wsl-config#configuration-settings-for-wslconf.
This can also be used if the distribution is installed already.

**Default value:** none

_**Example:**_
```yaml
- uses: Vampire/setup-wsl@v$majorVersion
with:
wsl-conf: |
[automount]
root = /
```

#### set-as-default

Whether to set the distribution as default WSL distribution.
Expand Down

0 comments on commit d8d69ee

Please sign in to comment.