Skip to content

Commit d802bec

Browse files
committed
Add a feature to install asdf
This installs the asdf version manager, via a given release version. It's then tested using a combination of the existing shell-based test framework, and the features test helper. Due to the way that the devcontainer spec cannot handle any complex data structures, the best way to handle plugins is through additional features. We need to override the default base image when testing because the scripts depend on `curl` and there's no sensible way to depend on just `curl` (and the default `ubuntu:focal` image doesn't include it). https://github.com/asdf-vm/asdf https://asdf-vm.com/guide/getting-started.html devcontainers/spec#44 devcontainers/spec#57 devcontainers/spec#766
1 parent 14d3cde commit d802bec

4 files changed

Lines changed: 81 additions & 0 deletions

File tree

‎.github/workflows/build-and-test.yml‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,17 @@ on:
55
push:
66

77
jobs:
8+
features:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v7
12+
- run: bin/setup
13+
- name: Run feature tests
14+
run: >-
15+
devcontainer features test
16+
-f asdf
17+
--base-image ghcr.io/thoughtbot/devcontainers/images/debian
18+
819
images:
920
runs-on: ubuntu-latest
1021
steps:

‎features/src/asdf/install.sh‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/sh
2+
3+
set -eu
4+
5+
version="v0.20.0"
6+
kernel_name=$(uname -s | tr '[:upper:]' '[:lower:]')
7+
architecture=$(dpkg --print-architecture)
8+
9+
if ! command -v asdf > /dev/null; then
10+
filename="asdf-$version-$kernel_name-$architecture.tar.gz"
11+
12+
curl -Lo "$filename" "https://github.com/asdf-vm/asdf/releases/download/$version/$filename"
13+
tar -xzvf "$filename" asdf
14+
sudo mv asdf /usr/local/bin/asdf
15+
16+
rm "$filename"
17+
fi
18+

‎features/test/asdf/test-utils.sh‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/sh
2+
3+
VERBOSE="${VERBOSE:-0}"
4+
LAST_COMMAND_OUTPUT=
5+
6+
# assert_command command [expected status code]
7+
#
8+
# Run a command and assert it's exit code is 0 or one given
9+
assert_command() {
10+
cmd="$1"
11+
expected_return_status="${2:-0}"
12+
13+
LAST_COMMAND_OUTPUT=
14+
15+
# Always capture stdout and stderr, and don't let a failing command
16+
# cause this function to fail
17+
if LAST_COMMAND_OUTPUT="$(printf '%s' "$cmd" | sh -a 2>&1)"; then
18+
status="$?" # ok
19+
else
20+
status="$?" # also ok
21+
fi
22+
23+
if [ ! "$VERBOSE" -eq 0 ]; then
24+
echo "Command: $cmd"
25+
echo "Command output: $LAST_COMMAND_OUTPUT"
26+
echo "Status code: $status"
27+
fi
28+
29+
if [ "$status" -ne "$expected_return_status" ]; then
30+
echo "$cmd exited with: $status"
31+
exit 1
32+
fi
33+
}
34+
35+
# assert_package package
36+
#
37+
# Query OS packages and assert one is installed
38+
assert_package() {
39+
package=$1
40+
41+
assert_command "dpkg-query --show -f='\${Package}: \${Version}' $package"
42+
}

‎features/test/asdf/test.sh‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/sh
2+
3+
set -eu
4+
5+
cwd=$(readlink -f "${0%/*}")
6+
7+
. "$cwd/test-utils.sh"
8+
9+
echo "Checking asdf runs..."
10+
assert_command "asdf --version"

0 commit comments

Comments
 (0)