Skip to content

Commit

Permalink
refactor: Add plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
infiniteregrets committed Dec 24, 2023
1 parent 50dff49 commit 3b45b9e
Show file tree
Hide file tree
Showing 36 changed files with 96 additions and 844 deletions.
2 changes: 1 addition & 1 deletion .github/PULL_REQUEST/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

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

## Checklist:
## 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! -->
Expand Down
6 changes: 0 additions & 6 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
version: 2
updates:
# dependabot for GitHub Actions for this repo
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
# dependabot for GitHub Actions for the template
- package-ecosystem: "github-actions"
directory: "template/.github/"
schedule:
interval: "weekly"
37 changes: 6 additions & 31 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,41 +7,16 @@ on:
pull_request:

jobs:
test:
name: template setup test
plugin_test:
name: asdf plugin test
strategy:
matrix:
os:
- ubuntu-latest
- macos-latest
runs-on: ${{ matrix.os }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Run Template Setup
run: |
git config user.name "Foo Bearer"
./setup.bash \
"asdf-foo" \
"foo --help" \
"asdf-community" \
"ASDF Community" \
"https://github.com/asdf-vm/asdf" \
"https://asdf-vm.com" \
"Apache-2.0" \
"yes"
- name: Check setup result
run: |
set -xe
ls -la .
git log
test ! -d template/
grep "Apache" LICENSE
test "main" = "$(git rev-parse --abbrev-ref HEAD)"
! git grep -F -e "<YOUR TOOL>" \
--or -e "<TOOL HOMEPAGE>" \
--or -e "<TOOL REPO>" \
--or -e "<TOOL CHECK>" \
--or -e "<YOUR NAME>" \
--or -e"<YOUR GITHUB USERNAME>"
- name: asdf_plugin_test
uses: asdf-vm/actions/plugin-test@v2
with:
command: mirrord --version
6 changes: 3 additions & 3 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@v4
- uses: asdf-vm/actions/install@v3
- uses: actions/checkout@v3
- uses: asdf-vm/actions/install@v2
- run: scripts/lint.bash

actionlint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v3
- name: Check workflow files
uses: docker://rhysd/actionlint:1.6.23
with:
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion .github/workflows/semantic-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
semantic-pr:
runs-on: ubuntu-latest
steps:
- uses: amannn/action-semantic-pull-request@v5.4.0
- uses: amannn/action-semantic-pull-request@v5.2.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
Expand Down
5 changes: 3 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

MIT License

Copyright (c) 2020 The asdf-vm core AUTHORS
Copyright (c) 2024 MetalBear

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 All @@ -18,4 +19,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
SOFTWARE.
71 changes: 47 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,59 @@
# asdf-plugin-template [![Build](https://github.com/asdf-vm/asdf-plugin-template/actions/workflows/build.yml/badge.svg)](https://github.com/asdf-vm/asdf-plugin-template/actions/workflows/build.yml) [![Lint](https://github.com/asdf-vm/asdf-plugin-template/actions/workflows/lint.yml/badge.svg)](https://github.com/asdf-vm/asdf-plugin-template/actions/workflows/lint.yml)
<div align="center">

This is an [asdf-vm plugin](https://asdf-vm.com/#/plugins-create) template with CI to run [Shellcheck](https://github.com/koalaman/shellcheck) and testing with the [asdf test GitHub Action](https://github.com/asdf-vm/actions).
# asdf-mirrord [![Build](https://github.com/infiniteregrets/asdf-mirrord/actions/workflows/build.yml/badge.svg)](https://github.com/infiniteregrets/asdf-mirrord/actions/workflows/build.yml) [![Lint](https://github.com/infiniteregrets/asdf-mirrord/actions/workflows/lint.yml/badge.svg)](https://github.com/infiniteregrets/asdf-mirrord/actions/workflows/lint.yml)

## Usage
[mirrord](https://mirrord.dev/) plugin for the [asdf version manager](https://asdf-vm.com).

1. [Generate](https://github.com/asdf-vm/asdf-plugin-template/generate) a new repository based on this template.
1. Clone it and run `bash setup.bash`.
1. Force push to your repo: `git push --force-with-lease`.
1. Adapt your code at the TODO markers. To find the markers: `git grep TODO`.
1. To develop your plugin further, please read [the plugins create section of the docs](https://asdf-vm.com/plugins/create.html).
</div>

>A feature of this plugin-template when hosted on GitHub is the use of [release-please](https://github.com/googleapis/release-please), an automated release tool. It leverages [Conventional Commit messages](https://www.conventionalcommits.org/) to determine semver release type, see the [documentation](https://github.com/googleapis/release-please).
# Contents

## Contributing
- [asdf-mirrord](#asdf-mirrord--)
- [Dependencies](#dependencies)
- [Install](#install)
- [Contributing](#contributing)
- [License](#license)

Contributions welcome!
# Dependencies

1. Install `asdf` tools
- `bash`, `curl`, `tar`, and [POSIX utilities](https://pubs.opengroup.org/onlinepubs/9699919799/idx/utilities.html).
- mirrord has OS specific binaries and are downloaded on the basis `OSTYPE` for determining the OS and `uname` for the architecture.

```shell
asdf plugin add shellcheck https://github.com/luizm/asdf-shellcheck.git
asdf plugin add shfmt https://github.com/luizm/asdf-shfmt.git
asdf install
```
# Install

1. Develop!
Plugin:

1. Lint & Format
```shell
asdf plugin add mirrord
# or
asdf plugin add mirrord https://github.com/infiniteregrets/asdf-mirrord.git
```

```shell
./scripts/format.bash
./scripts/lint.bash
```
mirrord:

1. PR changes
```shell
# Show all installable versions
asdf list-all mirrord

# Install specific version
asdf install mirrord latest

# Set a version globally (on your ~/.tool-versions file)
asdf global mirrord latest

# Now mirrord commands are available
mirrord --version
```

Check [asdf](https://github.com/asdf-vm/asdf) readme for more instructions on how to
install & manage versions.

# Contributing

Contributions of any kind welcome! See the [contributing guide](contributing.md).

[Thanks goes to these contributors](https://github.com/infiniteregrets/asdf-mirrord/graphs/contributors)!

# License

See [LICENSE](LICENSE) © [MetalBear](https://github.com/metalbear-co/)
12 changes: 7 additions & 5 deletions template/bin/download → bin/download
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ 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"

# 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"
echo "asdf download path is $ASDF_DOWNLOAD_PATH"

# Remove the tar.gz file since we don't need to keep it
rm "$release_file"
# # Extract contents of tar.gz file into the download directory
# cp "$release_file" "$ASDF_DOWNLOAD_PATH" || fail "Could not copy $release_file to $ASDF_DOWNLOAD_PATH"

# # Remove the tar.gz file since we don't need to keep it
# rm "$release_file"
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 1 addition & 2 deletions template/contributing-github.md → contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ Testing Locally:
```shell
asdf plugin test <plugin-name> <plugin-url> [--asdf-tool-version <version>] [--asdf-plugin-gitref <git-ref>] [test-command*]

# TODO: adapt this
asdf plugin test <YOUR TOOL> https://github.com/<YOUR GITHUB USERNAME>/asdf-<YOUR TOOL>.git "<TOOL CHECK>"
asdf plugin test mirrord https://github.com/infiniteregrets/asdf-mirrord.git "mirrord --version"
```

Tests are automatically run in GitHub Actions on push and PR.
42 changes: 23 additions & 19 deletions template/lib/utils.bash → lib/utils.bash
100755 → 100644
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 <YOUR TOOL>.
GH_REPO="<TOOL REPO>"
TOOL_NAME="<YOUR TOOL>"
TOOL_TEST="<TOOL CHECK>"
GH_REPO="https://github.com/metalbear-co/mirrord"
TOOL_NAME="mirrord"
TOOL_TEST="mirrord --version"

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

curl_opts=(-fsSL)

# NOTE: You might want to remove this if <YOUR TOOL> is not hosted on GitHub releases.
if [ -n "${GITHUB_API_TOKEN:-}" ]; then
curl_opts=("${curl_opts[@]}" -H "Authorization: token $GITHUB_API_TOKEN")
fi

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}'
Expand All @@ -27,25 +21,36 @@ 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
sed 's/^v//'
}

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

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

# TODO: Adapt the release URL convention for <YOUR TOOL>
url="$GH_REPO/archive/v${version}.tar.gz"

echo "* Downloading $TOOL_NAME release $version..."
curl "${curl_opts[@]}" -o "$filename" -C - "$url" || fail "Could not download $url"
if [[ "$OSTYPE" == "linux"* ]]; then
ARCH=$(uname -m)
OS="linux"
if [[ "$ARCH" != "x86_64" && "$ARCH" != "aarch64" ]]; then
echo "mirrord is only available for linux x86_64/aarch64 architecture"
file_issue_prompt
exit 1
fi
elif [[ "$OSTYPE" == "darwin"* ]]; then
ARCH="universal"
OS="mac"
else
echo "mirrord isn't supported for your platform - $OSTYPE"
file_issue_prompt
exit 1
fi
curl "${curl_opts[@]}" -o "$filename" -C - https://github.com/metalbear-co/mirrord/releases/download/"$version"/mirrord_$OS\_"$ARCH" || fail "Could not download mirrord"
}

install_version() {
Expand All @@ -56,14 +61,13 @@ install_version() {
if [ "$install_type" != "version" ]; then
fail "asdf-$TOOL_NAME supports release installs only"
fi

(
mkdir -p "$install_path"
cp -r "$ASDF_DOWNLOAD_PATH"/* "$install_path"

# TODO: Assert <YOUR TOOL> executable exists.
local tool_cmd
tool_cmd="$(echo "$TOOL_TEST" | cut -d' ' -f1)"
chmod +x "$install_path/$tool_cmd"
test -x "$install_path/$tool_cmd" || fail "Expected $install_path/$tool_cmd to be executable."

echo "$TOOL_NAME $version installation was successful!"
Expand Down
8 changes: 1 addition & 7 deletions scripts/format.bash
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
#!/usr/bin/env bash

# format this repo
shfmt --language-dialect bash --write \
setup.bash \
scripts/*.bash

# format the template/
shfmt --language-dialect bash --write \
template/**/*
./**/*
16 changes: 3 additions & 13 deletions scripts/lint.bash
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
#!/usr/bin/env bash

# lint this repo
shellcheck --shell=bash --external-sources \
setup.bash \
bin/* --source-path=template/lib/ \
lib/* \
scripts/*

shfmt --language-dialect bash --diff \
setup.bash \
scripts/*

# lint the template/
shellcheck --shell=bash --external-sources \
template/bin/* --source-path=template/lib/ \
template/lib/* \
template/scripts/*

shfmt --language-dialect bash --diff \
template/**/*
./**/*
Loading

0 comments on commit 3b45b9e

Please sign in to comment.