diff --git a/.github/github_workflows.ex b/.github/github_workflows.ex index 01f65100..e9997840 100644 --- a/.github/github_workflows.ex +++ b/.github/github_workflows.ex @@ -378,15 +378,19 @@ defmodule GithubWorkflows do {:"test_linux_#{shell}", test_linux_script_job(shell)}, {:"test_macos_#{shell}", test_macos_script_job(shell)} ] - end) + end) ++ + [ + {:test_wsl, test_wsl_script_job()} + ] end defp test_shell_script_job(opts) do os = Keyword.fetch!(opts, :os) runs_on = Keyword.fetch!(opts, :runs_on) shell = Keyword.fetch!(opts, :shell) - shell_install_command = Keyword.fetch!(opts, :shell_install_command) - expect_install_command = Keyword.fetch!(opts, :expect_install_command) + shell_install_command = Keyword.get(opts, :shell_install_command) + expect_install_command = Keyword.get(opts, :expect_install_command) + setup = Keyword.get(opts, :setup, []) [ name: "Test #{os} script with #{shell} shell", @@ -396,20 +400,21 @@ defmodule GithubWorkflows do TZ: "America/New_York" ], steps: - [ - checkout_step(), + [checkout_step()] ++ + setup ++ [ - name: "Restore script result cache", - uses: "actions/cache@v3", - id: "result_cache", - with: [ - key: - "${{ runner.os }}-#{shell}-script-${{ hashFiles('test/scripts/script.exp') }}-${{ hashFiles('priv/script.sh') }}", - path: "priv/script.sh" + [ + name: "Restore script result cache", + uses: "actions/cache@v3", + id: "result_cache", + with: [ + key: + "${{ runner.os }}-#{shell}-script-${{ hashFiles('test/scripts/script.exp') }}-${{ hashFiles('priv/script.sh') }}", + path: "priv/script.sh" + ] ] - ] - ] ++ - if(shell == "bash", + ] ++ + if(String.contains?(shell, "bash"), do: [], else: [ [ @@ -419,26 +424,31 @@ defmodule GithubWorkflows do ] ] ) ++ - if(os == "Linux", - do: [], - else: [ + if(os == "macOS", + do: [ [ name: "Disable password prompt for macOS", if: "steps.result_cache.outputs.cache-hit != 'true'", run: ~S ] - ] + ], + else: [] ) ++ - [ - [ - name: "Install expect tool", - if: "steps.result_cache.outputs.cache-hit != 'true'", - run: expect_install_command + if(expect_install_command, + do: [ + [ + name: "Install expect tool", + if: "steps.result_cache.outputs.cache-hit != 'true'", + run: expect_install_command + ] ], + else: [] + ) ++ + [ [ name: "Remove mise config files", - run: "rm -f .mise.toml .tool-versions" + run: "#{if(os == "WSL", do: "wsl ", else: "")}rm -f .mise.toml .tool-versions" ], [ name: "Test the script", @@ -488,6 +498,26 @@ defmodule GithubWorkflows do ) end + defp test_wsl_script_job do + test_shell_script_job( + os: "WSL", + runs_on: "windows-latest", + shell: "wsl-bash", + setup: [ + [ + name: "Setup WSL", + uses: "Vampire/setup-wsl@v3", + with: [ + distribution: "Ubuntu-22.04", + additional_packages: "expect", + wsl_shell_user: "root", + update: true + ] + ] + ] + ) + end + defp unused_deps_job do elixir_job("Check unused deps", needs: :compile, diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 3ac33b65..b68dd144 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -499,6 +499,46 @@ jobs: max_attempts: 7 retry_wait_seconds: 5 timeout_seconds: 1 + test_wsl: + name: Test WSL script with wsl-bash shell + runs-on: windows-latest + env: + SHELL: wsl-bash + TZ: America/New_York + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Setup WSL + uses: Vampire/setup-wsl@v3 + with: + distribution: Ubuntu-22.04 + additional_packages: expect + wsl_shell_user: root + update: true + - name: Restore script result cache + uses: actions/cache@v3 + id: result_cache + with: + key: ${{ runner.os }}-wsl-bash-script-${{ hashFiles('test/scripts/script.exp') }}-${{ hashFiles('priv/script.sh') }} + path: priv/script.sh + - name: Remove mise config files + run: wsl rm -f .mise.toml .tool-versions + - name: Test the script + if: steps.result_cache.outputs.cache-hit != 'true' + run: cd test/scripts && expect script.exp + shell: wsl-bash -l {0} + - name: Generate an app and start the server + if: steps.result_cache.outputs.cache-hit != 'true' + run: make -f test/scripts/Makefile serve + shell: wsl-bash -l {0} + - name: Check HTTP status code + if: steps.result_cache.outputs.cache-hit != 'true' + uses: nick-fields/retry@v2 + with: + command: INPUT_SITES='["http://localhost:4000"]' INPUT_EXPECTED='[200]' ./test/scripts/check_status_code.sh + max_attempts: 7 + retry_wait_seconds: 5 + timeout_seconds: 1 deploy_production_app: name: Deploy production app needs: @@ -518,6 +558,7 @@ jobs: - test_macos_fish - test_linux_zsh - test_macos_zsh + - test_wsl runs-on: ubuntu-latest steps: - name: Checkout diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index ae8bcd6a..a0e42e3f 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -503,6 +503,46 @@ jobs: max_attempts: 7 retry_wait_seconds: 5 timeout_seconds: 1 + test_wsl: + name: Test WSL script with wsl-bash shell + runs-on: windows-latest + env: + SHELL: wsl-bash + TZ: America/New_York + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Setup WSL + uses: Vampire/setup-wsl@v3 + with: + distribution: Ubuntu-22.04 + additional_packages: expect + wsl_shell_user: root + update: true + - name: Restore script result cache + uses: actions/cache@v3 + id: result_cache + with: + key: ${{ runner.os }}-wsl-bash-script-${{ hashFiles('test/scripts/script.exp') }}-${{ hashFiles('priv/script.sh') }} + path: priv/script.sh + - name: Remove mise config files + run: wsl rm -f .mise.toml .tool-versions + - name: Test the script + if: steps.result_cache.outputs.cache-hit != 'true' + run: cd test/scripts && expect script.exp + shell: wsl-bash -l {0} + - name: Generate an app and start the server + if: steps.result_cache.outputs.cache-hit != 'true' + run: make -f test/scripts/Makefile serve + shell: wsl-bash -l {0} + - name: Check HTTP status code + if: steps.result_cache.outputs.cache-hit != 'true' + uses: nick-fields/retry@v2 + with: + command: INPUT_SITES='["http://localhost:4000"]' INPUT_EXPECTED='[200]' ./test/scripts/check_status_code.sh + max_attempts: 7 + retry_wait_seconds: 5 + timeout_seconds: 1 deploy_preview_app: name: Deploy preview app needs: @@ -522,6 +562,7 @@ jobs: - test_macos_fish - test_linux_zsh - test_macos_zsh + - test_wsl runs-on: ubuntu-latest permissions: write-all concurrency: