Skip to content

Commit 3b45b9e

Browse files
author
infiniteregrets
committed
refactor: Add plugin
1 parent 50dff49 commit 3b45b9e

36 files changed

+96
-844
lines changed

.github/PULL_REQUEST/pull_request_template.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

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

28-
## Checklist:
28+
## Checklist
2929

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

.github/dependabot.yml

-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
version: 2
22
updates:
3-
# dependabot for GitHub Actions for this repo
43
- package-ecosystem: "github-actions"
54
directory: "/"
65
schedule:
76
interval: "weekly"
8-
# dependabot for GitHub Actions for the template
9-
- package-ecosystem: "github-actions"
10-
directory: "template/.github/"
11-
schedule:
12-
interval: "weekly"

.github/workflows/build.yml

+6-31
Original file line numberDiff line numberDiff line change
@@ -7,41 +7,16 @@ on:
77
pull_request:
88

99
jobs:
10-
test:
11-
name: template setup test
10+
plugin_test:
11+
name: asdf plugin test
1212
strategy:
1313
matrix:
1414
os:
1515
- ubuntu-latest
1616
- macos-latest
1717
runs-on: ${{ matrix.os }}
1818
steps:
19-
- name: Checkout code
20-
uses: actions/checkout@v4
21-
- name: Run Template Setup
22-
run: |
23-
git config user.name "Foo Bearer"
24-
./setup.bash \
25-
"asdf-foo" \
26-
"foo --help" \
27-
"asdf-community" \
28-
"ASDF Community" \
29-
"https://github.com/asdf-vm/asdf" \
30-
"https://asdf-vm.com" \
31-
"Apache-2.0" \
32-
"yes"
33-
34-
- name: Check setup result
35-
run: |
36-
set -xe
37-
ls -la .
38-
git log
39-
test ! -d template/
40-
grep "Apache" LICENSE
41-
test "main" = "$(git rev-parse --abbrev-ref HEAD)"
42-
! git grep -F -e "<YOUR TOOL>" \
43-
--or -e "<TOOL HOMEPAGE>" \
44-
--or -e "<TOOL REPO>" \
45-
--or -e "<TOOL CHECK>" \
46-
--or -e "<YOUR NAME>" \
47-
--or -e"<YOUR GITHUB USERNAME>"
19+
- name: asdf_plugin_test
20+
uses: asdf-vm/actions/plugin-test@v2
21+
with:
22+
command: mirrord --version

.github/workflows/lint.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ jobs:
1010
lint:
1111
runs-on: ubuntu-latest
1212
steps:
13-
- uses: actions/checkout@v4
14-
- uses: asdf-vm/actions/install@v3
13+
- uses: actions/checkout@v3
14+
- uses: asdf-vm/actions/install@v2
1515
- run: scripts/lint.bash
1616

1717
actionlint:
1818
runs-on: ubuntu-latest
1919
steps:
20-
- uses: actions/checkout@v4
20+
- uses: actions/checkout@v3
2121
- name: Check workflow files
2222
uses: docker://rhysd/actionlint:1.6.23
2323
with:
File renamed without changes.

.github/workflows/semantic-pr.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
semantic-pr:
1212
runs-on: ubuntu-latest
1313
steps:
14-
- uses: amannn/action-semantic-pull-request@v5.4.0
14+
- uses: amannn/action-semantic-pull-request@v5.2.0
1515
env:
1616
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1717
with:

LICENSE

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
12
MIT License
23

3-
Copyright (c) 2020 The asdf-vm core AUTHORS
4+
Copyright (c) 2024 MetalBear
45

56
Permission is hereby granted, free of charge, to any person obtaining a copy
67
of this software and associated documentation files (the "Software"), to deal
@@ -18,4 +19,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1819
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1920
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2021
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21-
SOFTWARE.
22+
SOFTWARE.

README.md

+47-24
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,59 @@
1-
# 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)
1+
<div align="center">
22

3-
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).
3+
# 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)
44

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

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

13-
>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).
9+
# Contents
1410

15-
## Contributing
11+
- [asdf-mirrord](#asdf-mirrord--)
12+
- [Dependencies](#dependencies)
13+
- [Install](#install)
14+
- [Contributing](#contributing)
15+
- [License](#license)
1616

17-
Contributions welcome!
17+
# Dependencies
1818

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

21-
```shell
22-
asdf plugin add shellcheck https://github.com/luizm/asdf-shellcheck.git
23-
asdf plugin add shfmt https://github.com/luizm/asdf-shfmt.git
24-
asdf install
25-
```
22+
# Install
2623

27-
1. Develop!
24+
Plugin:
2825

29-
1. Lint & Format
26+
```shell
27+
asdf plugin add mirrord
28+
# or
29+
asdf plugin add mirrord https://github.com/infiniteregrets/asdf-mirrord.git
30+
```
3031

31-
```shell
32-
./scripts/format.bash
33-
./scripts/lint.bash
34-
```
32+
mirrord:
3533

36-
1. PR changes
34+
```shell
35+
# Show all installable versions
36+
asdf list-all mirrord
37+
38+
# Install specific version
39+
asdf install mirrord latest
40+
41+
# Set a version globally (on your ~/.tool-versions file)
42+
asdf global mirrord latest
43+
44+
# Now mirrord commands are available
45+
mirrord --version
46+
```
47+
48+
Check [asdf](https://github.com/asdf-vm/asdf) readme for more instructions on how to
49+
install & manage versions.
50+
51+
# Contributing
52+
53+
Contributions of any kind welcome! See the [contributing guide](contributing.md).
54+
55+
[Thanks goes to these contributors](https://github.com/infiniteregrets/asdf-mirrord/graphs/contributors)!
56+
57+
# License
58+
59+
See [LICENSE](LICENSE) © [MetalBear](https://github.com/metalbear-co/)

template/bin/download bin/download

+7-5
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@ source "${plugin_dir}/lib/utils.bash"
1111
mkdir -p "$ASDF_DOWNLOAD_PATH"
1212

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

1616
# Download tar.gz file to the download directory
1717
download_release "$ASDF_INSTALL_VERSION" "$release_file"
1818

19-
# Extract contents of tar.gz file into the download directory
20-
tar -xzf "$release_file" -C "$ASDF_DOWNLOAD_PATH" --strip-components=1 || fail "Could not extract $release_file"
19+
echo "asdf download path is $ASDF_DOWNLOAD_PATH"
2120

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

template/bin/install bin/install

File renamed without changes.
File renamed without changes.

template/bin/list-all bin/list-all

File renamed without changes.

template/contributing-github.md contributing.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ Testing Locally:
55
```shell
66
asdf plugin test <plugin-name> <plugin-url> [--asdf-tool-version <version>] [--asdf-plugin-gitref <git-ref>] [test-command*]
77

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

1211
Tests are automatically run in GitHub Actions on push and PR.

template/lib/utils.bash lib/utils.bash

+23-19
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22

33
set -euo pipefail
44

5-
# TODO: Ensure this is the correct GitHub homepage where releases can be downloaded for <YOUR TOOL>.
6-
GH_REPO="<TOOL REPO>"
7-
TOOL_NAME="<YOUR TOOL>"
8-
TOOL_TEST="<TOOL CHECK>"
5+
GH_REPO="https://github.com/metalbear-co/mirrord"
6+
TOOL_NAME="mirrord"
7+
TOOL_TEST="mirrord --version"
98

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

1514
curl_opts=(-fsSL)
1615

17-
# NOTE: You might want to remove this if <YOUR TOOL> is not hosted on GitHub releases.
18-
if [ -n "${GITHUB_API_TOKEN:-}" ]; then
19-
curl_opts=("${curl_opts[@]}" -H "Authorization: token $GITHUB_API_TOKEN")
20-
fi
21-
2216
sort_versions() {
2317
sed 'h; s/[+-]/./g; s/.p\([[:digit:]]\)/.z\1/; s/$/.z/; G; s/\n/ /' |
2418
LC_ALL=C sort -t. -k 1,1 -k 2,2n -k 3,3n -k 4,4n -k 5,5n | awk '{print $2}'
@@ -27,25 +21,36 @@ sort_versions() {
2721
list_github_tags() {
2822
git ls-remote --tags --refs "$GH_REPO" |
2923
grep -o 'refs/tags/.*' | cut -d/ -f3- |
30-
sed 's/^v//' # NOTE: You might want to adapt this sed to remove non-version strings from tags
24+
sed 's/^v//'
3125
}
3226

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

3931
download_release() {
40-
local version filename url
32+
local version filename
4133
version="$1"
4234
filename="$2"
4335

44-
# TODO: Adapt the release URL convention for <YOUR TOOL>
45-
url="$GH_REPO/archive/v${version}.tar.gz"
46-
4736
echo "* Downloading $TOOL_NAME release $version..."
48-
curl "${curl_opts[@]}" -o "$filename" -C - "$url" || fail "Could not download $url"
37+
if [[ "$OSTYPE" == "linux"* ]]; then
38+
ARCH=$(uname -m)
39+
OS="linux"
40+
if [[ "$ARCH" != "x86_64" && "$ARCH" != "aarch64" ]]; then
41+
echo "mirrord is only available for linux x86_64/aarch64 architecture"
42+
file_issue_prompt
43+
exit 1
44+
fi
45+
elif [[ "$OSTYPE" == "darwin"* ]]; then
46+
ARCH="universal"
47+
OS="mac"
48+
else
49+
echo "mirrord isn't supported for your platform - $OSTYPE"
50+
file_issue_prompt
51+
exit 1
52+
fi
53+
curl "${curl_opts[@]}" -o "$filename" -C - https://github.com/metalbear-co/mirrord/releases/download/"$version"/mirrord_$OS\_"$ARCH" || fail "Could not download mirrord"
4954
}
5055

5156
install_version() {
@@ -56,14 +61,13 @@ install_version() {
5661
if [ "$install_type" != "version" ]; then
5762
fail "asdf-$TOOL_NAME supports release installs only"
5863
fi
59-
6064
(
6165
mkdir -p "$install_path"
6266
cp -r "$ASDF_DOWNLOAD_PATH"/* "$install_path"
6367

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

6973
echo "$TOOL_NAME $version installation was successful!"

scripts/format.bash

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
11
#!/usr/bin/env bash
22

3-
# format this repo
43
shfmt --language-dialect bash --write \
5-
setup.bash \
6-
scripts/*.bash
7-
8-
# format the template/
9-
shfmt --language-dialect bash --write \
10-
template/**/*
4+
./**/*

scripts/lint.bash

+3-13
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,9 @@
11
#!/usr/bin/env bash
22

3-
# lint this repo
43
shellcheck --shell=bash --external-sources \
5-
setup.bash \
4+
bin/* --source-path=template/lib/ \
5+
lib/* \
66
scripts/*
77

88
shfmt --language-dialect bash --diff \
9-
setup.bash \
10-
scripts/*
11-
12-
# lint the template/
13-
shellcheck --shell=bash --external-sources \
14-
template/bin/* --source-path=template/lib/ \
15-
template/lib/* \
16-
template/scripts/*
17-
18-
shfmt --language-dialect bash --diff \
19-
template/**/*
9+
./**/*

0 commit comments

Comments
 (0)