diff --git a/.github/actions/run-tests/action.yml b/.github/actions/run-tests/action.yml new file mode 100644 index 0000000..6f3b20c --- /dev/null +++ b/.github/actions/run-tests/action.yml @@ -0,0 +1,19 @@ +name: "Run tests" +description: "Install fish and Oh My Fish! if necessary and run CI tests" +runs: + using: "composite" + steps: + - name: Install Fish + shell: bash + if: runner.os == 'macOS' + run: brew update && brew install fish + + - name: Install Oh My Fish! + shell: bash + run: fish bin/install --verbose --offline --noninteractive --yes + + - name: Run tests on latest fish + shell: bash + run: | + tests/run.fish + fish -c 'fish-spec pkg/{fish-spec,omf}/spec/*_spec.fish' diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index eca9544..53ef3e8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -7,50 +7,45 @@ on: paths-ignore: - '**.md' jobs: - build: + build-linux: + strategy: + fail-fast: false + matrix: + # only use the latest patch level for all minor versions to reduce number of jobs + fish: + - '3.0.0' # since 3.0.0 is the oldest officially supported version it's included as well + - '3.0.2' + - '3.1.2' + - '3.2.2' + - '3.3.1' + - '3.4.1' + - '3.5.1' + - '3.6.4' + - '3.7.1' + - '4.0.0' + runs-on: ubuntu-latest + container: + image: ohmyfish/fish:${{ matrix.fish }} + options: --user root + steps: + - name: Checkout the repository + uses: actions/checkout@v4 + + - name: Run tests + uses: ./.github/actions/run-tests + + build-macos: strategy: fail-fast: false matrix: os: - - ubuntu-20.04 - - ubuntu-22.04 - - ubuntu-latest - fish: - - stock - - 3 - - 4 - - brew - exclude: - - os: ubuntu-20.04 - fish: 4 - - os: ubuntu-latest - fish: 4 - include: - - os: macos-latest - fish: brew - - os: macos-13 - fish: brew - - os: macos-14 - fish: brew + - macos-latest + - macos-13 + - macos-14 runs-on: ${{ matrix.os }} steps: - name: Checkout the repository - uses: actions/checkout@v3 - - - name: Add brew to path for Ubuntu - if: startsWith(matrix.os, 'ubuntu') && matrix.fish == 'brew' - run: | - echo "/home/linuxbrew/.linuxbrew/bin" >> $GITHUB_PATH - echo "/home/linuxbrew/.linuxbrew/sbin" >> $GITHUB_PATH - - - name: Install Fish - run: FISH_RELEASE=${{ matrix.fish }} tools/ci-install-fish.sh - - - name: Install Oh My Fish! - run: fish bin/install --verbose --offline --noninteractive --yes + uses: actions/checkout@v4 - name: Run tests - run: | - tests/run.fish - pushd pkg/fish-spec; fish -c 'fish-spec'; popd - pushd pkg/omf; fish -c 'fish-spec'; popd + uses: ./.github/actions/run-tests diff --git a/pkg/fish-spec/functions/fish-spec.fish b/pkg/fish-spec/functions/fish-spec.fish index 8599e60..6c1cdd8 100644 --- a/pkg/fish-spec/functions/fish-spec.fish +++ b/pkg/fish-spec/functions/fish-spec.fish @@ -75,29 +75,32 @@ function __fish_spec_run_test_function -a test_func set test_func_human_readable (string replace 'it_' 'IT ' $test_func | string replace -a '_' ' ') __fish_spec.color.echo-n.info "⏳ $test_func_human_readable" + set -l before_each_output "" if functions --query before_each - set -l before_each_output (before_each 2>&1 | string collect) + before_each 2>1 | while read -l line; test -z "$before_each_output" && set before_each_output $line || set before_each_output $before_each_output\n$line; end end - set -l test_func_output ($test_func 2>&1 | string collect) + set -l test_func_output "" + $test_func 2>&1 | while read -l line; test -z "$test_func_output" && set test_func_output $line || set test_func_output $test_func_output\n$line; end set result $status + set -l after_each_output "" if functions --query after_each - set -l before_each_output (before_each 2>&1 | string collect) + after_each 2>&1 | while read -l line; test -z "$after_each_output" && set after_each_output $line || set after_each_output $after_each_output\n$line; end end if test $__fish_spec_last_assertion_failed = no __fish_spec.color.echo.success \r"✅ $test_func_human_readable passed!" if test "$FISH_SPEC_VERBOSE" = 1 - test -n "$before_each_output" && echo $before_each_output - test -n "$test_func_output" && echo $test_func_output - test -n "$after_each_output" && echo $after_each_output + test -n "$before_each_output" && echo "$before_each_output" + test -n "$test_func_output" && echo "$test_func_output" + test -n "$after_each_output" && echo "$after_each_output" end else __fish_spec.color.echo.failure \r"❌ $test_func_human_readable failed." - test -n "$before_each_output" && echo $before_each_output - test -n "$test_func_output" && echo $test_func_output - test -n "$after_each_output" && echo $after_each_output + test -n "$before_each_output" && echo "$before_each_output" + test -n "$test_func_output" && echo "$test_func_output" + test -n "$after_each_output" && echo "$after_each_output" set __fish_spec_last_assertion_failed no end end diff --git a/tools/ci-install-fish.sh b/tools/ci-install-fish.sh deleted file mode 100755 index dc0164a..0000000 --- a/tools/ci-install-fish.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env bash - -set -o pipefail -set -o errexit -set -o nounset - -if [[ $FISH_RELEASE = "brew" ]]; then - brew update - brew install fish -else - if [[ $FISH_RELEASE == "4" ]]; then - REPO_PPA="ppa:fish-shell/beta-4" - else - REPO_PPA="ppa:fish-shell/release-3" - fi - - if [[ $FISH_RELEASE != "stock" ]]; then - sudo apt-add-repository -y $REPO_PPA - fi - - sudo apt-cache policy fish - sudo apt-get update - sudo apt-get install -y fish -fi - -fish --version