Skip to content

Commit

Permalink
feat: implement for macos and linux
Browse files Browse the repository at this point in the history
  • Loading branch information
barmac committed Apr 7, 2022
1 parent 1285ff2 commit 31d92dc
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ jobs:
- name: asdf_plugin_test
uses: asdf-vm/actions/plugin-test@v1
with:
command: which modeler
command: ""
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ asdf install modeler latest
asdf global modeler latest

# Now modeler commands are available
which modeler
asdf modeler diagram.bpmn
```

Check [asdf](https://github.com/asdf-vm/asdf) readme for more instructions on how to
Expand Down
23 changes: 23 additions & 0 deletions bin/list-bin-paths
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env bash

set -euo pipefail

current_script_path=${BASH_SOURCE[0]}
plugin_dir=$(dirname "$(dirname "$current_script_path")")

# shellcheck source=../lib/utils.bash
source "${plugin_dir}/lib/utils.bash"

platform_name="$(platform)"

case "$platform_name" in
mac)
echo "Contents/MacOS"
;;
linux)
echo ""
;;
*)
fail "Unknown platform: $platform_name"
;;
esac
2 changes: 1 addition & 1 deletion contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Testing Locally:
asdf plugin test <plugin-name> <plugin-url> [--asdf-tool-version <version>] [--asdf-plugin-gitref <git-ref>] [test-command*]

#
asdf plugin test modeler https://github.com/barmac/asdf-modeler.git "which modeler"
asdf plugin test modeler https://github.com/barmac/asdf-modeler.git
```

Tests are automatically run in GitHub Actions on push and PR.
11 changes: 11 additions & 0 deletions lib/commands/command.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash

set -euo pipefail

current_script_path=${BASH_SOURCE[0]}
plugin_dir=$(dirname "$(dirname "$current_script_path")")

# shellcheck source=../lib/utils.bash
source "${plugin_dir}/utils.bash"

$(asdf where modeler)/"$(executable)" "$*"
68 changes: 60 additions & 8 deletions lib/utils.bash
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,67 @@ set -euo pipefail
# TODO: Ensure this is the correct GitHub homepage where releases can be downloaded for modeler.
GH_REPO="https://github.com/camunda/camunda-modeler"
TOOL_NAME="modeler"
TOOL_TEST="which modeler"
TOOL_TEST=""

fail() {
echo -e "asdf-$TOOL_NAME: $*"
exit 1
}

platform() {
local os
local platform

os=$(uname -s)
case "$os" in
Darwin)
platform="mac"
;;
Linux)
platform="linux"
;;
*)
fail "Unknown OS: $os"
;;
esac

echo "$platform"
}

file_name() {
local version="$1"
local platform_name="$(platform)"

case "$platform_name" in
mac)
echo "camunda-modeler-$version-mac.zip"
;;
linux)
echo "camunda-modeler-$version-linux-x64.tar.gz"
;;
*)
fail "Unknown platform: $platform_name"
;;
esac
}

executable() {
local platform_name="$(platform)"

case "$platform_name" in
mac)
echo "Contents/MacOS/Camunda Modeler"
;;
linux)
echo "camunda-modeler"
;;
*)
fail "Unknown platform: $platform_name"
;;
esac

}

curl_opts=(-fsSL)

# NOTE: You might want to remove this if modeler is not hosted on GitHub releases.
Expand All @@ -37,12 +91,12 @@ list_all_versions() {
}

download_release() {
local version filename url
local version filename url artifact_name
version="$1"
filename="$2"
artifact_name="$(file_name $version)"

# TODO: Adapt the release URL convention for modeler
url="$GH_REPO/archive/v${version}.tar.gz"
url="$GH_REPO/releases/download/v${version}/$artifact_name"

echo "* Downloading $TOOL_NAME release $version..."
curl "${curl_opts[@]}" -o "$filename" -C - "$url" || fail "Could not download $url"
Expand All @@ -52,6 +106,7 @@ install_version() {
local install_type="$1"
local version="$2"
local install_path="$3"
local executable_path="$(executable)"

if [ "$install_type" != "version" ]; then
fail "asdf-$TOOL_NAME supports release installs only"
Expand All @@ -61,10 +116,7 @@ install_version() {
mkdir -p "$install_path"
cp -r "$ASDF_DOWNLOAD_PATH"/* "$install_path"

# TODO: Asert modeler executable exists.
local tool_cmd
tool_cmd="$(echo "$TOOL_TEST" | cut -d' ' -f1)"
test -x "$install_path/bin/$tool_cmd" || fail "Expected $install_path/bin/$tool_cmd to be executable."
test -x "$install_path/$executable_path" || fail "Expected $install_path/$executable_path to be executable."

echo "$TOOL_NAME $version installation was successful!"
) || (
Expand Down

0 comments on commit 31d92dc

Please sign in to comment.