Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/github_actions/asdf-vm/actions-3
Browse files Browse the repository at this point in the history
  • Loading branch information
CSergienko authored Jul 9, 2024
2 parents 970261b + c0aeae6 commit 146ff9b
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 27 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: asdf-vm/actions/install@v3
- run: scripts/lint.bash

actionlint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Check workflow files
uses: docker://rhysd/actionlint:1.6.23
with:
Expand Down
5 changes: 5 additions & 0 deletions .rusty-hook.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[hooks]
pre-commit = "just lint && just format"

[logging]
verbose = true
4 changes: 1 addition & 3 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
TODO: INSERT YOUR NAME COPYRIGHT YEAR (if applicable to your license)

MIT License

Copyright (c) [year] [fullname]
Copyright (c) Chris Sergienko 2024

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# asdf-helix [![Build](https://github.com/CSergienko/asdf-helix/actions/workflows/build.yml/badge.svg)](https://github.com/CSergienko/asdf-helix/actions/workflows/build.yml) [![Lint](https://github.com/CSergienko/asdf-helix/actions/workflows/lint.yml/badge.svg)](https://github.com/CSergienko/asdf-helix/actions/workflows/lint.yml)

[helix](https://github.com/CSergienko/asdf-helix) plugin for the [asdf version manager](https://asdf-vm.com).
[helix](https://helix-editor.com/) plugin for the [asdf version manager](https://asdf-vm.com).

</div>

Expand All @@ -15,10 +15,7 @@

# Dependencies

**TODO: adapt this section**

- `bash`, `curl`, `tar`, and [POSIX utilities](https://pubs.opengroup.org/onlinepubs/9699919799/idx/utilities.html).
- `SOME_ENV_VAR`: set this environment variable in your shell config to load the correct version of tool x.

# Install

Expand All @@ -44,6 +41,7 @@ asdf global helix latest

# Now helix commands are available
hx --version
hx --health
```

Check [asdf](https://github.com/asdf-vm/asdf) readme for more instructions on how to
Expand Down
11 changes: 5 additions & 6 deletions bin/download
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@ source "${plugin_dir}/lib/utils.bash"

mkdir -p "$ASDF_DOWNLOAD_PATH"

# TODO: Adapt this to proper extension and adapt extracting strategy.
release_file="$ASDF_DOWNLOAD_PATH/$TOOL_NAME-$ASDF_INSTALL_VERSION.tar.gz"
release_file="$ASDF_DOWNLOAD_PATH/$TOOL_NAME-$ASDF_INSTALL_VERSION.tar.xz"

# Download tar.gz file to the download directory
# Download tar.xz file to the download directory
download_release "$ASDF_INSTALL_VERSION" "$release_file"

# Extract contents of tar.gz file into the download directory
tar -xzf "$release_file" -C "$ASDF_DOWNLOAD_PATH" --strip-components=1 || fail "Could not extract $release_file"
# Extract contents of tar.xz file into the download directory
tar -xJf "$release_file" -C "$ASDF_DOWNLOAD_PATH" --strip-components=1 || fail "Could not extract $release_file"

# Remove the tar.gz file since we don't need to keep it
# Remove the tar.xz file since we don't need to keep it
rm "$release_file"
21 changes: 21 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
default:
just --choose

lint:
#!/usr/bin/env bash
shellcheck --shell=bash --external-sources \
bin/* --source-path=template/lib/ \
lib/* \
scripts/*
shfmt --language-dialect bash --diff \
./**/*

format:
#!/usr/bin/env bash
shfmt --language-dialect bash --write \
./**/*
test:
#!/usr/bin/env bash
asdf plugin test helix https://github.com/CSergienko/asdf-helix.git "hx --health"
25 changes: 13 additions & 12 deletions lib/utils.bash
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

set -euo pipefail

# TODO: Ensure this is the correct GitHub homepage where releases can be downloaded for helix.
GH_REPO="https://github.com/CSergienko/asdf-helix"
GH_REPO="https://github.com/helix-editor/helix"
TOOL_NAME="helix"
TOOL_TEST="hx --version"
TOOL_TEST="hx --health"

fail() {
echo -e "asdf-$TOOL_NAME: $*"
Expand All @@ -14,7 +13,6 @@ fail() {

curl_opts=(-fsSL)

# NOTE: You might want to remove this if helix is not hosted on GitHub releases.
if [ -n "${GITHUB_API_TOKEN:-}" ]; then
curl_opts=("${curl_opts[@]}" -H "Authorization: token $GITHUB_API_TOKEN")
fi
Expand All @@ -25,24 +23,28 @@ sort_versions() {
}

list_github_tags() {
git ls-remote --tags --refs "$GH_REPO" |
grep -o 'refs/tags/.*' | cut -d/ -f3- |
sed 's/^v//' # NOTE: You might want to adapt this sed to remove non-version strings from tags
git ls-remote --heads --tags $GH_REPO |
grep refs/tags |
cut -d '/' -f 3 |
grep -v '\^{}' |
sed -E 's/^(v)([0-9]+\.[0-9]+\.[0-9]+)$/\2/'
}

list_all_versions() {
# TODO: Adapt this. By default we simply list the tag names from GitHub releases.
# Change this function if helix has other means of determining installable versions.
list_github_tags
}

download_release() {
local version filename url
version="$1"
filename="$2"
architecture="$(uname -m)"
os="$(uname | tr '[:upper:]' '[:lower:]')"

# TODO: Adapt the release URL convention for helix
url="$GH_REPO/archive/v${version}.tar.gz"
if [ "$os" = "darwin" ]; then
os="macos"
fi
url="$GH_REPO/releases/download/${version}/helix-${version}-${architecture}-${os}.tar.xz"

echo "* Downloading $TOOL_NAME release $version..."
curl "${curl_opts[@]}" -o "$filename" -C - "$url" || fail "Could not download $url"
Expand All @@ -61,7 +63,6 @@ install_version() {
mkdir -p "$install_path"
cp -r "$ASDF_DOWNLOAD_PATH"/* "$install_path"

# TODO: Assert helix executable exists.
local tool_cmd
tool_cmd="$(echo "$TOOL_TEST" | cut -d' ' -f1)"
test -x "$install_path/$tool_cmd" || fail "Expected $install_path/$tool_cmd to be executable."
Expand Down

0 comments on commit 146ff9b

Please sign in to comment.