diff --git a/.github/github_workflows.ex b/.github/github_workflows.ex index 989b63d6..a3fbd8a8 100644 --- a/.github/github_workflows.ex +++ b/.github/github_workflows.ex @@ -9,7 +9,7 @@ defmodule GithubWorkflows do @preview_app_name "#{@app_name_prefix}-#{@environment_name}" @preview_app_host "#{@preview_app_name}.fly.dev" @repo_name "phx_tools" - @shells ["bash", "zsh"] + @shells ["bash", "fish", "zsh"] def get do %{ @@ -392,7 +392,7 @@ defmodule GithubWorkflows do name: "Test #{os} script with #{shell} shell", "runs-on": runs_on, env: [ - SHELL: "/bin/#{shell}", + SHELL: shell, TZ: "America/New_York" ], steps: @@ -443,14 +443,14 @@ defmodule GithubWorkflows do [ name: "Test the script", if: "steps.result_cache.outputs.cache-hit != 'true'", - run: "cd test/scripts && expect script.exp #{os}.sh", - shell: "/bin/#{shell} -l {0}" + run: "cd test/scripts && expect script.exp", + shell: "#{shell} -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: "/bin/#{shell} -l {0}" + shell: "#{shell} -l {0}" ], [ name: "Check HTTP status code", diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 8229a534..f521bfd4 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -266,7 +266,7 @@ jobs: name: Test Linux script with bash shell runs-on: ubuntu-latest env: - SHELL: /bin/bash + SHELL: bash TZ: America/New_York steps: - name: Checkout @@ -284,12 +284,12 @@ jobs: run: 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 Linux.sh - shell: /bin/bash -l {0} + run: cd test/scripts && expect script.exp + shell: 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: /bin/bash -l {0} + shell: bash -l {0} - name: Check HTTP status code if: steps.result_cache.outputs.cache-hit != 'true' uses: nick-fields/retry@v2 @@ -302,7 +302,7 @@ jobs: name: Test macOS script with bash shell runs-on: macos-latest env: - SHELL: /bin/bash + SHELL: bash TZ: America/New_York steps: - name: Checkout @@ -323,12 +323,93 @@ jobs: run: 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 macOS.sh - shell: /bin/bash -l {0} + run: cd test/scripts && expect script.exp + shell: 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: /bin/bash -l {0} + shell: 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 + test_linux_fish: + name: Test Linux script with fish shell + runs-on: ubuntu-latest + env: + SHELL: fish + TZ: America/New_York + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Restore script result cache + uses: actions/cache@v3 + id: result_cache + with: + key: ${{ runner.os }}-fish-script-${{ hashFiles('test/scripts/script.exp') }}-${{ hashFiles('priv/script.sh') }} + path: priv/static/Linux.sh + - name: Install shell + if: steps.result_cache.outputs.cache-hit != 'true' + run: sudo apt-get update && sudo apt-get install -y fish + - name: Install expect tool + if: steps.result_cache.outputs.cache-hit != 'true' + run: sudo apt-get update && sudo apt-get install -y expect + - name: Remove mise config files + run: 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: fish -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: fish -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 + test_macos_fish: + name: Test macOS script with fish shell + runs-on: macos-latest + env: + SHELL: fish + TZ: America/New_York + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Restore script result cache + uses: actions/cache@v3 + id: result_cache + with: + key: ${{ runner.os }}-fish-script-${{ hashFiles('test/scripts/script.exp') }}-${{ hashFiles('priv/script.sh') }} + path: priv/static/macOS.sh + - name: Install shell + if: steps.result_cache.outputs.cache-hit != 'true' + run: brew install fish + - name: Disable password prompt for macOS + if: steps.result_cache.outputs.cache-hit != 'true' + run: 'sudo sed -i "" "s/%admin ALL = (ALL) ALL/%admin ALL = (ALL) NOPASSWD: ALL/g" /etc/sudoers' + - name: Install expect tool + if: steps.result_cache.outputs.cache-hit != 'true' + run: brew install expect + - name: Remove mise config files + run: 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: fish -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: fish -l {0} - name: Check HTTP status code if: steps.result_cache.outputs.cache-hit != 'true' uses: nick-fields/retry@v2 @@ -341,7 +422,7 @@ jobs: name: Test Linux script with zsh shell runs-on: ubuntu-latest env: - SHELL: /bin/zsh + SHELL: zsh TZ: America/New_York steps: - name: Checkout @@ -362,12 +443,12 @@ jobs: run: 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 Linux.sh - shell: /bin/zsh -l {0} + run: cd test/scripts && expect script.exp + shell: zsh -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: /bin/zsh -l {0} + shell: zsh -l {0} - name: Check HTTP status code if: steps.result_cache.outputs.cache-hit != 'true' uses: nick-fields/retry@v2 @@ -380,7 +461,7 @@ jobs: name: Test macOS script with zsh shell runs-on: macos-latest env: - SHELL: /bin/zsh + SHELL: zsh TZ: America/New_York steps: - name: Checkout @@ -404,12 +485,12 @@ jobs: run: 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 macOS.sh - shell: /bin/zsh -l {0} + run: cd test/scripts && expect script.exp + shell: zsh -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: /bin/zsh -l {0} + shell: zsh -l {0} - name: Check HTTP status code if: steps.result_cache.outputs.cache-hit != 'true' uses: nick-fields/retry@v2 @@ -433,6 +514,8 @@ jobs: - unused_deps - test_linux_bash - test_macos_bash + - test_linux_fish + - test_macos_fish - test_linux_zsh - test_macos_zsh runs-on: ubuntu-latest diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index ffa47847..7be7f494 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -270,7 +270,7 @@ jobs: name: Test Linux script with bash shell runs-on: ubuntu-latest env: - SHELL: /bin/bash + SHELL: bash TZ: America/New_York steps: - name: Checkout @@ -288,12 +288,12 @@ jobs: run: 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 Linux.sh - shell: /bin/bash -l {0} + run: cd test/scripts && expect script.exp + shell: 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: /bin/bash -l {0} + shell: bash -l {0} - name: Check HTTP status code if: steps.result_cache.outputs.cache-hit != 'true' uses: nick-fields/retry@v2 @@ -306,7 +306,7 @@ jobs: name: Test macOS script with bash shell runs-on: macos-latest env: - SHELL: /bin/bash + SHELL: bash TZ: America/New_York steps: - name: Checkout @@ -327,12 +327,93 @@ jobs: run: 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 macOS.sh - shell: /bin/bash -l {0} + run: cd test/scripts && expect script.exp + shell: 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: /bin/bash -l {0} + shell: 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 + test_linux_fish: + name: Test Linux script with fish shell + runs-on: ubuntu-latest + env: + SHELL: fish + TZ: America/New_York + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Restore script result cache + uses: actions/cache@v3 + id: result_cache + with: + key: ${{ runner.os }}-fish-script-${{ hashFiles('test/scripts/script.exp') }}-${{ hashFiles('priv/script.sh') }} + path: priv/static/Linux.sh + - name: Install shell + if: steps.result_cache.outputs.cache-hit != 'true' + run: sudo apt-get update && sudo apt-get install -y fish + - name: Install expect tool + if: steps.result_cache.outputs.cache-hit != 'true' + run: sudo apt-get update && sudo apt-get install -y expect + - name: Remove mise config files + run: 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: fish -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: fish -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 + test_macos_fish: + name: Test macOS script with fish shell + runs-on: macos-latest + env: + SHELL: fish + TZ: America/New_York + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Restore script result cache + uses: actions/cache@v3 + id: result_cache + with: + key: ${{ runner.os }}-fish-script-${{ hashFiles('test/scripts/script.exp') }}-${{ hashFiles('priv/script.sh') }} + path: priv/static/macOS.sh + - name: Install shell + if: steps.result_cache.outputs.cache-hit != 'true' + run: brew install fish + - name: Disable password prompt for macOS + if: steps.result_cache.outputs.cache-hit != 'true' + run: 'sudo sed -i "" "s/%admin ALL = (ALL) ALL/%admin ALL = (ALL) NOPASSWD: ALL/g" /etc/sudoers' + - name: Install expect tool + if: steps.result_cache.outputs.cache-hit != 'true' + run: brew install expect + - name: Remove mise config files + run: 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: fish -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: fish -l {0} - name: Check HTTP status code if: steps.result_cache.outputs.cache-hit != 'true' uses: nick-fields/retry@v2 @@ -345,7 +426,7 @@ jobs: name: Test Linux script with zsh shell runs-on: ubuntu-latest env: - SHELL: /bin/zsh + SHELL: zsh TZ: America/New_York steps: - name: Checkout @@ -366,12 +447,12 @@ jobs: run: 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 Linux.sh - shell: /bin/zsh -l {0} + run: cd test/scripts && expect script.exp + shell: zsh -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: /bin/zsh -l {0} + shell: zsh -l {0} - name: Check HTTP status code if: steps.result_cache.outputs.cache-hit != 'true' uses: nick-fields/retry@v2 @@ -384,7 +465,7 @@ jobs: name: Test macOS script with zsh shell runs-on: macos-latest env: - SHELL: /bin/zsh + SHELL: zsh TZ: America/New_York steps: - name: Checkout @@ -408,12 +489,12 @@ jobs: run: 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 macOS.sh - shell: /bin/zsh -l {0} + run: cd test/scripts && expect script.exp + shell: zsh -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: /bin/zsh -l {0} + shell: zsh -l {0} - name: Check HTTP status code if: steps.result_cache.outputs.cache-hit != 'true' uses: nick-fields/retry@v2 @@ -437,6 +518,8 @@ jobs: - unused_deps - test_linux_bash - test_macos_bash + - test_linux_fish + - test_macos_fish - test_linux_zsh - test_macos_zsh runs-on: ubuntu-latest diff --git a/priv/script.sh b/priv/script.sh index 1cbc0993..52ff06b4 100755 --- a/priv/script.sh +++ b/priv/script.sh @@ -29,11 +29,16 @@ phoenix_version=1.7.14 postgres_version=15.1 case "${SHELL:-}" in -*/bash) +*bash) current_shell="bash" config_file="$HOME/.bashrc" ;; -*/zsh) +*fish) + current_shell="fish" + config_file="$HOME/.config/fish/config.fish" + mkdir -p "$(dirname "$config_file")" + ;; +*zsh) current_shell="zsh" config_file="$HOME/.zshrc" ;; @@ -126,16 +131,24 @@ install() { UNAME_MACHINE="$(/usr/bin/uname -m)" if [[ "${UNAME_MACHINE}" == "arm64" ]]; then - ( - echo - echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' - ) >>$config_file + if [ "$current_shell" = "fish" ]; then + fish_add_path /opt/homebrew/bin + else + ( + echo + echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' + ) >>$config_file + fi eval "$(/opt/homebrew/bin/brew shellenv)" else - ( - echo - echo 'eval "$(/usr/local/bin/brew shellenv)"' - ) >>$config_file + if [ "$current_shell" = "fish" ]; then + fish_add_path /usr/local/bin + else + ( + echo + echo 'eval "$(/usr/local/bin/brew shellenv)"' + ) >>$config_file + fi eval "$(/usr/local/bin/brew shellenv)" fi ;; @@ -146,6 +159,9 @@ install() { "bash") echo 'eval "$(~/.local/bin/mise activate bash)"' >>$config_file ;; + "fish") + echo '~/.local/bin/mise activate fish | source' >>$config_file + ;; "zsh") echo 'eval "$(~/.local/bin/mise activate zsh)"' >>$config_file ;; diff --git a/test/scripts/script.exp b/test/scripts/script.exp index 00a74b3b..b3eb74fc 100755 --- a/test/scripts/script.exp +++ b/test/scripts/script.exp @@ -1,9 +1,8 @@ #!/usr/bin/expect -set script [lindex $argv 0]; - +set script [lindex $argv 0] set timeout -1 -spawn ./../../priv/static/$script +spawn ./../../priv/script.sh match_max 100000 expect "Do you want to continue? (y/n) " send -- "y\r"