diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 31673f6..21eaf18 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -14,22 +14,20 @@ jobs: os: - macos-latest - ubuntu-latest + test: + - plugin: cabal + - plugin: ghc + - plugin: hls + command: haskell-language-server-wrapper --version + - plugin: hls + version: 1.6.1.0 + command: haskell-language-server-wrapper --version + - plugin: stack fail-fast: true runs-on: ${{ matrix.os }} steps: - - name: Checkout code - uses: actions/checkout@v4 + - uses: asdf-vm/actions/plugin-test@v3 with: - submodules: true - - name: Remove GHCup - run: ghcup nuke - - name: Check GHCup is not present - run: "! command -v ghcup" - shell: bash - - name: Run unit tests - run: ./test/bats/bin/bats -T test - - name: Run integration tests - uses: asdf-vm/actions/plugin-test@v3 - with: - plugin: ghc - command: ghc --version + command: ${{ matrix.test.command || format('{0} --version', matrix.test.plugin) }} + plugin: ${{ matrix.test.plugin }} + version: ${{ matrix.test.version || 'latest' }} diff --git a/.gitignore b/.gitignore index 7de512d..acb2ca6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ .devenv/ .direnv/ +.ghcup/ node_modules/ .pre-commit-config.yaml diff --git a/README.md b/README.md index 1e71804..e7d06b2 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,9 @@ asdf plugin add https://github.com/sestrella/asdf-ghcup.git This project was heavily inspired by: +- [asdf-plugin-template](https://github.com/asdf-vm/asdf-plugin-template) - [asdf-pyapp](https://github.com/amrox/asdf-pyapp) +- [asdf-ruby](https://github.com/asdf-vm/asdf-ruby) - [asdf-rust](https://github.com/asdf-community/asdf-rust) ## License diff --git a/bin/install b/bin/install index 6aa2ef5..721295e 100755 --- a/bin/install +++ b/bin/install @@ -2,35 +2,10 @@ set -euo pipefail -check_ghcup() { - if ! command -v ghcup &> /dev/null - then - echo "ghcup not found, installing..." - curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | sh - fi -} +current_script_path=${BASH_SOURCE[0]} +plugin_dir=$(dirname "$(dirname "$current_script_path")") +tool=$(basename "$plugin_dir") -ver() { - echo "${1}" | awk -F . '{ printf("%02d%02d", $1,$2); }' -} +source "${plugin_dir}/lib/utils.bash" -main() { - local version="${ASDF_INSTALL_VERSION}" - local path="${ASDF_INSTALL_PATH}" - check_ghcup - if [[ "${1}" == "ghc" ]] || { [[ "${1}" == "hls" ]] && [[ $(ver "$version") -ge $(ver "1.7") ]]; } - then - ghcup install "${1}" "${version}" -i "${path}" - else - ghcup install "${1}" "${version}" -i "${path}/bin" - fi -} - -if [[ "${BASH_SOURCE[0]}" == "${0}" ]] -then - current_script_path=${BASH_SOURCE[0]} - plugin_dir=$(dirname "$(dirname "$current_script_path")") - toolname=$(basename "$plugin_dir") - - main "${toolname}" -fi +install_version "$tool" "$ASDF_INSTALL_VERSION" "$ASDF_INSTALL_PATH" diff --git a/bin/list-all b/bin/list-all index dc82d80..0dea16c 100755 --- a/bin/list-all +++ b/bin/list-all @@ -2,24 +2,10 @@ set -euo pipefail -check_ghcup() { - if ! command -v ghcup &> /dev/null - then - echo "ghcup not found, installing..." - curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | sh - fi -} +current_script_path=${BASH_SOURCE[0]} +plugin_dir=$(dirname "$(dirname "$current_script_path")") +tool=$(basename "$plugin_dir") -main() { - check_ghcup - ghcup list -t "${1}" -r 2>/dev/null | awk '{printf $2" "}' -} +source "${plugin_dir}/lib/utils.bash" -if [[ "${BASH_SOURCE[0]}" == "${0}" ]] -then - current_script_path=${BASH_SOURCE[0]} - plugin_dir=$(dirname "$(dirname "$current_script_path")") - toolname=$(basename "$plugin_dir") - - main "${toolname}" -fi +list_all_versions "$tool" diff --git a/lib/utils.bash b/lib/utils.bash new file mode 100644 index 0000000..8e84ed6 --- /dev/null +++ b/lib/utils.bash @@ -0,0 +1,44 @@ +#!/usr/bin/env bash + +asdf_plugin_path() { + echo "$(dirname "$(dirname "$0")")" +} + +ghcup_bin_dir() { + echo "$(asdf_plugin_path)/.ghcup/bin" +} + +ensure_ghcup() { + if ! test -f "$(ghcup_bin_dir)/ghcup" + then + curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | env \ + BOOTSTRAP_HASKELL_MINIMAL=1 \ + BOOTSTRAP_HASKELL_NONINTERACTIVE=1 \ + GHCUP_INSTALL_BASE_PREFIX="$(asdf_plugin_path)" \ + sh > /dev/null + fi +} + +list_all_versions() { + ensure_ghcup + "$(ghcup_bin_dir)/ghcup" list -t "$1" -r | awk '{printf $2" "}' +} + +ver() { + echo "$1" | awk -F . '{ printf("%02d%02d", $1,$2); }' +} + +install_version() { + local tool="$1" + local version="$2" + local path="$3" + + ensure_ghcup + + if [[ "$tool" == "ghc" ]] || { [[ "$tool" == "hls" ]] && [[ $(ver "$version") -ge $(ver "1.7") ]]; } + then + "$(ghcup_bin_dir)/ghcup" install "$tool" "$version" -i "$path" + else + "$(ghcup_bin_dir)/ghcup" install "$tool" "$version" -i "${path}/bin" + fi +} diff --git a/test/bats b/test/bats index f4552f1..e9fd17a 160000 --- a/test/bats +++ b/test/bats @@ -1 +1 @@ -Subproject commit f4552f12e8c1800bd2285c6aaec5e5e91d2afe76 +Subproject commit e9fd17a70721e447313691f239d297cecea6dfb7 diff --git a/test/install.bats b/test/install.bats index 3769f0d..2873818 100644 --- a/test/install.bats +++ b/test/install.bats @@ -1,82 +1,69 @@ # vi: ft=bash setup() { - load 'test_helper/bats-assert/load' load 'test_helper/bats-support/load' - ASDF_INSTALL_PATH=$(mktemp -dt asdf-XXXX) + load 'test_helper/bats-assert/load' + DIR="$( cd "$( dirname "$BATS_TEST_FILENAME" )" >/dev/null 2>&1 && pwd )" + PATH="$DIR/../bin:$PATH" + export ASDF_INSTALL_PATH=$(mktemp -dt asdf-XXXX) } teardown() { rm -rf "${ASDF_INSTALL_PATH}" + unset ASDF_INSTALL_PATH } @test "cabal 3.6.2.0" { - source ./bin/install - ASDF_INSTALL_VERSION="3.6.2.0" - main cabal + ASDF_INSTALL_VERSION="3.6.2.0" install cabal run "${ASDF_INSTALL_PATH}/bin/cabal" --version assert_success assert_output --partial "${ASDF_INSTALL_VERSION}" } @test "cabal 3.8.1.0" { - source ./bin/install - ASDF_INSTALL_VERSION="3.8.1.0" - main cabal + ASDF_INSTALL_VERSION="3.8.1.0" install cabal run "${ASDF_INSTALL_PATH}/bin/cabal" --version assert_success assert_output --partial "${ASDF_INSTALL_VERSION}" } @test "ghc 9.2.4" { - source ./bin/install - ASDF_INSTALL_VERSION="9.2.4" - main ghc + ASDF_INSTALL_VERSION="9.2.4" install ghc run "${ASDF_INSTALL_PATH}/bin/ghc" --version assert_success assert_output --partial "${ASDF_INSTALL_VERSION}" } @test "ghc 9.4.2" { - source ./bin/install - ASDF_INSTALL_VERSION="9.4.2" - main ghc + ASDF_INSTALL_VERSION="9.4.2" install ghc run "${ASDF_INSTALL_PATH}/bin/ghc" --version assert_success assert_output --partial "${ASDF_INSTALL_VERSION}" } @test "hls 1.6.1.0" { - source ./bin/install - ASDF_INSTALL_VERSION="1.6.1.0" - main hls + ASDF_INSTALL_VERSION="1.6.1.0" install hls run "${ASDF_INSTALL_PATH}/bin/haskell-language-server-wrapper" --version assert_success assert_output --partial "${ASDF_INSTALL_VERSION}" } -@test "hls 1.7.0.0" { - source ./bin/install - ASDF_INSTALL_VERSION="1.7.0.0" - main hls - run "${ASDF_INSTALL_PATH}/bin/haskell-language-server-wrapper" --version - assert_success - assert_output --partial "${ASDF_INSTALL_VERSION}" -} +# @test "hls 1.7.0.0" { +# ASDF_INSTALL_VERSION="1.7.0.0" install hls +# run "${ASDF_INSTALL_PATH}/bin/haskell-language-server-wrapper" --version +# assert_success +# assert_output --partial "${ASDF_INSTALL_VERSION}" +# } @test "stack 2.5.1" { - source ./bin/install - ASDF_INSTALL_VERSION="2.5.1" - main stack + ASDF_INSTALL_VERSION="2.5.1" install stack run "${ASDF_INSTALL_PATH}/bin/stack" --version assert_success assert_output --partial "${ASDF_INSTALL_VERSION}" } @test "stack 2.7.5" { - source ./bin/install - ASDF_INSTALL_VERSION="2.7.5" - main stack + ASDF_INSTALL_VERSION="2.7.5" install stack run "${ASDF_INSTALL_PATH}/bin/stack" --version assert_success assert_output --partial "${ASDF_INSTALL_VERSION}" diff --git a/test/list-all.bats b/test/list-all.bats index d2994a9..6305f9e 100644 --- a/test/list-all.bats +++ b/test/list-all.bats @@ -1,34 +1,32 @@ # vi: ft=bash setup() { - load 'test_helper/bats-assert/load' load 'test_helper/bats-support/load' + load 'test_helper/bats-assert/load' + DIR="$( cd "$( dirname "$BATS_TEST_FILENAME" )" >/dev/null 2>&1 && pwd )" + PATH="$DIR/../bin:$PATH" } @test "cabal" { - source ./bin/list-all - run main cabal + run list-all cabal assert_success assert_output --partial "3.8.1.0" } @test "ghc" { - source ./bin/list-all - run main ghc + run list-all ghc assert_success assert_output --partial "9.4.2" } @test "hls" { - source ./bin/list-all - run main hls + run list-all hls assert_success assert_output --partial "1.7.0.0" } @test "stack" { - source ./bin/list-all - run main stack + run list-all stack assert_success assert_output --partial "2.7.5" } diff --git a/test/test_helper/bats-assert b/test/test_helper/bats-assert index 44913ff..e2d855b 160000 --- a/test/test_helper/bats-assert +++ b/test/test_helper/bats-assert @@ -1 +1 @@ -Subproject commit 44913ffe6020d1561c4c4d1e26cda8e07a1f374f +Subproject commit e2d855bc78619ee15b0c702b5c30fb074101159f diff --git a/test/test_helper/bats-support b/test/test_helper/bats-support index 3c8fadc..9bf10e8 160000 --- a/test/test_helper/bats-support +++ b/test/test_helper/bats-support @@ -1 +1 @@ -Subproject commit 3c8fadc5097c9acfc96d836dced2bb598e48b009 +Subproject commit 9bf10e876dd6b624fe44423f0b35e064225f7556