Skip to content

Commit

Permalink
Rewrite of repo
Browse files Browse the repository at this point in the history
chore: migrate to the new structure of asdf plugins
feat: add in ci pipelines
  • Loading branch information
YR-ZR0 committed Jan 11, 2024
1 parent 3cbf71c commit e529f61
Show file tree
Hide file tree
Showing 14 changed files with 299 additions and 103 deletions.
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
root = true

[*]
indent_style = tab
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.{md,yml,yaml}]
indent_style = space
indent_size = 2
27 changes: 27 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
name: Bug report
about: Create a report to help us improve
title: ""
labels: bug
assignees: ""
---

**Describe the bug**

<!-- A clear and concise description of what the bug is. -->

**Steps to reproduce**

<!-- Steps to reproduce the behavior: -->

**Expected behavior**

<!-- A clear and concise description of what you expected to happen. -->

**Screenshots**

<!-- If applicable, add screenshots to help explain your problem. -->

**Additional context**

<!-- Add any other context about the problem here. -->
23 changes: 23 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
name: Feature request
about: Suggest an idea for this project
title: ""
labels: enhancement
assignees: ""
---

**Is your feature request related to a problem? Please describe.**

<!-- A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] -->

**Describe the solution you'd like**

<!-- A clear and concise description of what you want to happen. -->

**Describe alternatives you've considered**

<!-- A clear and concise description of any alternative solutions or features you've considered. -->

**Additional context**

<!-- Add any other context or screenshots about the feature request here. -->
34 changes: 34 additions & 0 deletions .github/PULL_REQUEST/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<!--- Provide a general summary of your changes in the Title above -->

## Description

<!--- Describe your changes in detail -->

## Motivation and Context

<!--- Why is this change required? What problem does it solve? -->
<!--- If it fixes an open issue, please link to the issue here. -->

## Types of changes

<!--- What types of changes does your code introduce? Put an `x` in all the boxes that apply: -->

- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to change)

## Usage examples

<!--- Provide examples of intended usage -->

## How Has This Been Tested?

<!--- Please describe in detail how you tested your changes. -->

## Checklist:

<!--- Go over all the following points, and put an `x` in all the boxes that apply. -->
<!--- If you're unsure about any of these, don't hesitate to ask. We're here to help! -->

- [ ] I have updated the documentation accordingly.
- [ ] I have added tests to cover my changes.
11 changes: 11 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
- package-ecosystem: "github-actions" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "weekly"
22 changes: 22 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: CI

on:
workflow_dispatch:
push:
branches:
- master
- main
pull_request:
branches:
- master
- main

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: asdf_plugin_test
uses: asdf-vm/actions/[email protected]
with:
command: "micro -version"
2 changes: 2 additions & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
shellcheck 0.9.0
shfmt 3.6.0
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@ you can add this plugin like this:

```bash
asdf plugin add micro https://github.com/YR-ZR0/asdf-micro
asdf install micro 2.0.11
asdf install micro 2.0.13
```

Currently this plugin will only get the linux 64bit binary

## Acknowledgements
Parts of this code come from the following repos:
* https://github.com/johnhamelink/asdf-tekton-cli
* https://gitlab.com/wt0f/asdf-bat
- https://github.com/zyedidia/micro
23 changes: 23 additions & 0 deletions bin/download
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"

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"

# Download tar.gz 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"

# Remove the tar.gz file since we don't need to keep it
rm "$release_file"
78 changes: 5 additions & 73 deletions bin/install
Original file line number Diff line number Diff line change
Expand Up @@ -2,78 +2,10 @@

set -euo pipefail

readonly ASDF_INSTALL_TYPE=${ASDF_INSTALL_TYPE:-version}
readonly TMPDIR=${TMPDIR:-/tmp}
current_script_path=${BASH_SOURCE[0]}
plugin_dir=$(dirname "$(dirname "$current_script_path")")

fail() {
echo "asdf-$TOOL_NAME: $*" >&2
exit 1
}
# shellcheck source=../lib/utils.bash
source "${plugin_dir}/lib/utils.bash"

install_micro() {
local install_type=$1
local version=$2
local install_path=$3

case "$install_type" in
version)
local bin_install_path="${install_path}/bin"
local tmp_download_dir="$(get_tmp_dir)"
local download_url="$(get_download_url "$version")"
local download_path="${tmp_download_dir}/micro-${version}.tar.gz"
mkdir -p "$bin_install_path"
echo "Version is ${version}"
echo "Downloading micro from ${download_url}"
curl -s -L "$download_url" -o "$download_path"
tar --wildcards -zxf "$download_path" --directory "$tmp_download_dir" '*/micro' --strip=1
mv "$tmp_download_dir/micro" "$bin_install_path"
chmod +x "$bin_install_path"
rm -f "$download_path"
;;
*)
echo "Install of type [$install_type] not supported"
;;
esac
}

get_arch() {
local arch=$(uname -m | tr '[:upper:]' '[:lower:]')
case "$arch" in
x86_64)
arch='64'
;;
esac

echo "$arch"
}

get_tmp_dir() {
if [ -z "$TMPDIR" ]; then
mktemp -d -t micro_XXXXXX
else
echo "$TMPDIR"
fi
}

get_platform() {
local plat=$(uname | tr '[:upper:]' '[:lower:]')
case "$plat" in
linux)
plat='linux'
;;
darwin)
plat='osx'
;;
esac

echo "$plat"
}

get_download_url() {
local version="$1"
local arch=$(get_arch)
local platform=$(get_platform)
echo "https://github.com/zyedidia/micro/releases/download/v${version}/micro-${version}-${platform}${arch}.tar.gz"
}

install_micro "$ASDF_INSTALL_TYPE" "$ASDF_INSTALL_VERSION" "$ASDF_INSTALL_PATH"
install_version "$ASDF_INSTALL_TYPE" "$ASDF_INSTALL_VERSION" "$ASDF_INSTALL_PATH"
31 changes: 4 additions & 27 deletions bin/list-all
Original file line number Diff line number Diff line change
@@ -1,31 +1,8 @@
#!/usr/bin/env bash

set -eo pipefail
set -euo pipefail

readonly releases_path="https://api.github.com/repos/zyedidia/micro/releases"
cmd="curl -s"
# shellcheck source=../lib/utils.bash
source "$(dirname "$0")/../lib/utils.bash"

if [ -n "$OAUTH_TOKEN" ]; then
cmd="$cmd -H 'Authorization: token $OAUTH_TOKEN'"
fi

cmd="$cmd $releases_path"

sort_versions() {
sed 'h; s/[+-]/./g; s/.p\([[:digit:]]\)/.z\1/; s/$/.z/; G; s/\n/ /' |
LC_ALL=C sort -t. -k 1,1 -k 2,2n -k 3,3n -k 4,4n -k 5,5n |
awk '{print $2}'
}

# Fetch all tag names, get only the second column, remove unnecessary characters.
versions=$(
$cmd |
grep '"tag_name":' |
sed -E 's/.*"([^"]+)".*/\1/' |
grep -v 'nightly' |
grep -Ev "rc*" |
sed -E 's/^(v)([0-9]+\.[0-9]+\.[0-9]+)$/\2/' |
sort_versions
)

echo "$versions"
list_all_versions | sort_versions | xargs echo
Loading

0 comments on commit e529f61

Please sign in to comment.