Skip to content

Commit 0c6168f

Browse files
committed
workflows/tests: use WSL2
1 parent e65f88c commit 0c6168f

File tree

2 files changed

+32
-30
lines changed

2 files changed

+32
-30
lines changed

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.sh text eol=lf

.github/workflows/tests.yml

+31-30
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
name: CI
2+
23
on:
34
push:
45
branches:
56
- master
67
pull_request:
8+
79
permissions:
810
contents: read
911

12+
concurrency:
13+
group: ${{ github.ref }}
14+
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
15+
1016
jobs:
1117
tests:
1218
strategy:
@@ -21,21 +27,14 @@ jobs:
2127
- os: ubuntu-latest
2228
shell: bash
2329
- os: windows-latest
24-
shell: "wsl-bash {0}"
25-
runs-on: ${{matrix.os}}
30+
shell: wsl -- dos2unix <"$(wslpath '{0}')" | bash --noprofile --norc -euo pipefail
31+
runs-on: ${{ matrix.os }}
2632
defaults:
2733
run:
2834
shell: ${{ matrix.shell }}
2935
steps:
30-
- name: Set up WSL
31-
if: runner.os == 'windows'
32-
shell: powershell
33-
run: |
34-
git config --global core.autocrlf false
35-
git config --global core.eol lf
36-
3736
- name: Set up Git repository
38-
uses: actions/checkout@main
37+
uses: actions/checkout@v4
3938

4039
- name: Cleanup macOS
4140
if: runner.os == 'macOS'
@@ -44,13 +43,23 @@ jobs:
4443
/Library/Developer/CommandLineTools
4544
sudo xcode-select --reset
4645
47-
- name: Install WSL
48-
if: runner.os == 'windows'
49-
uses: Vampire/setup-wsl@6f87de3102a29ac6b92800f33bf1e8d9164ac0a1
50-
with:
51-
distribution: Ubuntu-22.04
52-
wsl-shell-user: runner
53-
additional-packages: build-essential
46+
- name: Set up WSL
47+
if: runner.os == 'Windows'
48+
shell: powershell
49+
run: |
50+
wsl --update
51+
wsl --version
52+
wsl --set-default-version 2
53+
wsl --install Ubuntu-22.04 --no-launch
54+
ubuntu2204 install --root
55+
wsl --set-default Ubuntu-22.04
56+
wsl --list --verbose
57+
wsl --exec apt-get update
58+
wsl --exec apt-get install -y --no-install-recommends build-essential dos2unix
59+
wsl --exec /usr/sbin/useradd --create-home runner
60+
wsl -- --% echo "runner ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/runner
61+
ubuntu2204 config --default-user runner
62+
echo "WSLENV=CI:GITHUB_ACTIONS:RUNNER_OS:GITHUB_PATH/p" >> $env:GITHUB_ENV # allow some basic envs to be passed in
5463
5564
- name: Check Bash 3.x syntax
5665
if: runner.os == 'macOS'
@@ -59,11 +68,13 @@ jobs:
5968
/bin/bash -u -O extglob -n uninstall.sh
6069
6170
- name: Set up Homebrew PATH
62-
if: runner.os != 'windows'
6371
run: |
64-
if [[ "${{ runner.os }}" = "macOS" ]]
72+
if [[ "${RUNNER_OS}" = "macOS" ]]
6573
then
6674
echo "/usr/local/bin:/usr/bin:/bin" >> "${GITHUB_PATH}"
75+
elif [[ "${RUNNER_OS}" = "Windows" ]]
76+
then
77+
echo "$(wslpath -w /home/linuxbrew/.linuxbrew/bin)" >> "${GITHUB_PATH}"
6778
else
6879
echo "/home/linuxbrew/.linuxbrew/bin:/usr/bin:/bin" >> "${GITHUB_PATH}"
6980
fi
@@ -76,15 +87,6 @@ jobs:
7687
/bin/bash uninstall.sh -f >/dev/null
7788
fi
7889
79-
- name: Set up WSL environment
80-
if: runner.os == 'windows'
81-
shell: "wsl-bash -u root {0}"
82-
run: |
83-
echo "runner ALL=(ALL) NOPASSWD:ALL" | tee /etc/sudoers.d/runner
84-
chmod 644 /etc/sudoers.d/runner
85-
echo -e "#!/bin/bash\nexec /home/linuxbrew/.linuxbrew/bin/brew \"\$@\"" | tee /usr/local/bin/brew
86-
chmod 755 /usr/local/bin/brew
87-
8890
- run: /bin/bash -c "$(cat install.sh)"
8991

9092
- run: brew config
@@ -96,14 +98,13 @@ jobs:
9698
- run: /bin/bash -c "$(cat install.sh)"
9799

98100
- name: Uninstall and reinstall with sudo NOPASSWD
99-
if: runner.os == 'linux'
101+
if: runner.os == 'Linux'
100102
run: |
101103
echo "${USER} ALL=(ALL) NOPASSWD:ALL" | sudo tee "/etc/sudoers.d/${USER}"
102104
/bin/bash uninstall.sh -f >/dev/null
103105
/bin/bash -c "$(cat install.sh)"
104106
105107
- name: Check code styles
106-
if: runner.os != 'windows'
107108
run: |
108109
brew install shellcheck shfmt diffutils
109110
brew style *.sh

0 commit comments

Comments
 (0)