Skip to content

Commit

Permalink
feat: Install GHCup inside the plugin directory (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
sestrella authored Dec 3, 2023
1 parent e603d88 commit 15769d5
Show file tree
Hide file tree
Showing 11 changed files with 98 additions and 107 deletions.
28 changes: 13 additions & 15 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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' }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.devenv/
.direnv/
.ghcup/
node_modules/

.pre-commit-config.yaml
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ asdf plugin add <tool> 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
Expand Down
35 changes: 5 additions & 30 deletions bin/install
Original file line number Diff line number Diff line change
Expand Up @@ -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"
24 changes: 5 additions & 19 deletions bin/list-all
Original file line number Diff line number Diff line change
Expand Up @@ -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"
44 changes: 44 additions & 0 deletions lib/utils.bash
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 1 addition & 1 deletion test/bats
Submodule bats updated 45 files
+3 −0 .codespellrc
+47 −0 .github/dependabot.yml
+22 −0 .github/workflows/codespell.yml
+22 −0 .github/workflows/dependency-review.yml
+9 −4 .github/workflows/release.yml
+18 −6 .github/workflows/release_dockerhub.yml
+4 −4 .github/workflows/scorecard.yml
+30 −30 .github/workflows/tests.yml
+14 −0 .pre-commit-config.yaml
+2 −2 Dockerfile
+9 −0 SECURITY.md
+3 −1 bin/bats
+1 −1 contrib/rpm/bats.spec
+26 −0 docs/CHANGELOG.md
+1 −1 docs/CONTRIBUTING.md
+18 −6 docs/source/docker-usage.md
+1 −1 docs/source/installation.rst
+1 −1 docs/source/writing-tests.md
+10 −4 install.sh
+122 −1 lib/bats-core/test_functions.bash
+3 −3 lib/bats-core/tracing.bash
+1 −1 lib/bats-core/warnings.bash
+2 −2 libexec/bats-core/bats
+5 −5 libexec/bats-core/bats-exec-file
+4 −4 libexec/bats-core/bats-exec-suite
+6 −6 libexec/bats-core/bats-exec-test
+1 −1 libexec/bats-core/bats-format-junit
+1 −1 libexec/bats-core/bats-format-pretty
+1 −1 libexec/bats-core/bats-format-tap
+1 −1 libexec/bats-core/bats-format-tap13
+1 −1 libexec/bats-core/bats-preprocess
+1 −1 man/bats.7
+73 −2 man/bats.7.ronn
+1 −1 package.json
+1 −1 shellcheck.sh
+1 −1 test/bats.bats
+1,410 −0 test/bats_pipe.bats
+1 −1 test/cat-formatter.bats
+1 −1 test/fixtures/formatter/echo-formatter
+1 −1 test/formatter.bats
+12 −12 test/install.bats
+2 −2 test/parallel.bats
+1 −1 test/test_helper.bash
+2 −2 test/warnings.bats
+35 −11 uninstall.sh
49 changes: 18 additions & 31 deletions test/install.bats
Original file line number Diff line number Diff line change
@@ -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}"
Expand Down
16 changes: 7 additions & 9 deletions test/list-all.bats
Original file line number Diff line number Diff line change
@@ -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"
}
2 changes: 1 addition & 1 deletion test/test_helper/bats-assert

0 comments on commit 15769d5

Please sign in to comment.