Skip to content

Commit

Permalink
Merge pull request #1 from olofvndrhr/dev
Browse files Browse the repository at this point in the history
update plugin template and simplify script
  • Loading branch information
olofvndrhr committed Aug 31, 2023
2 parents 6882e77 + 92e48ce commit 76431f9
Show file tree
Hide file tree
Showing 20 changed files with 118 additions and 93 deletions.
11 changes: 11 additions & 0 deletions .editorconfig
@@ -1,8 +1,19 @@
# EditorConfig is awesome: https://EditorConfig.org

# top-most EditorConfig file
root = true

[*]
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true


[*.{yml,yaml,xml,hcl,tf}]
indent_size = 2

[*.{bat,cmd,ps1,ps[md]1}]
end_of_line = crlf
2 changes: 1 addition & 1 deletion .github/PULL_REQUEST/pull_request_template.md
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: 6 additions & 0 deletions .github/dependabot.yml
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Expand Up @@ -17,6 +17,6 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
- name: asdf_plugin_test
uses: asdf-vm/actions/plugin-test@v1
uses: asdf-vm/actions/plugin-test@v2
with:
command: just --version
32 changes: 10 additions & 22 deletions .github/workflows/lint.yml
Expand Up @@ -7,30 +7,18 @@ on:
pull_request:

jobs:
shellcheck:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: asdf-vm/actions/install@v2
- run: scripts/lint.bash

- name: Install asdf dependencies
uses: asdf-vm/actions/install@v1

- name: Run ShellCheck
run: scripts/shellcheck.bash

shellfmt:
actionlint:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Install asdf dependencies
uses: asdf-vm/actions/install@v1

- name: List file to shfmt
run: shfmt -f .

- name: Run shfmt
run: scripts/shfmt.bash

- uses: actions/checkout@v3
- name: Check workflow files
uses: docker://rhysd/actionlint:1.6.23
with:
args: -color
6 changes: 5 additions & 1 deletion .github/workflows/release.yml
Expand Up @@ -5,10 +5,14 @@ on:
branches:
- main

permissions:
contents: write
pull-requests: write

jobs:
release-please:
runs-on: ubuntu-latest
steps:
- uses: GoogleCloudPlatform/release-please-action@v2
- uses: GoogleCloudPlatform/release-please-action@v3
with:
release-type: simple
18 changes: 18 additions & 0 deletions .github/workflows/semantic-pr.yml
@@ -0,0 +1,18 @@
name: Lint

on:
pull_request_target:
types:
- opened
- edited
- synchronize

jobs:
semantic-pr:
runs-on: ubuntu-latest
steps:
- uses: amannn/action-semantic-pull-request@v5.2.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
validateSingleCommit: true
1 change: 1 addition & 0 deletions .gitignore
@@ -1 +1,2 @@
.idea/
asdf-plugin-template/
4 changes: 2 additions & 2 deletions .tool-versions
@@ -1,2 +1,2 @@
shellcheck 0.8.0
shfmt 3.5.1
shellcheck 0.9.0
shfmt 3.6.0
2 changes: 1 addition & 1 deletion LICENSE
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2022 Ivan Schaller
Copyright (c) 2022-present Ivan Schaller

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
11 changes: 5 additions & 6 deletions README.md
Expand Up @@ -2,23 +2,22 @@

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


[just](https://just.systems/man/en/) plugin for the [asdf version manager](https://asdf-vm.com).

</div>

# Contents

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

# Dependencies

**TODO: adapt this section**

- `bash`, `curl`, `tar`, `gzip`: generic POSIX utilities.
- `bash`, `curl`, `tar`, `gzip`: generic POSIX utilities.

# Install

Expand Down
5 changes: 1 addition & 4 deletions bin/download
Expand Up @@ -12,8 +12,5 @@ if [[ "${ASDF_INSTALL_TYPE}" != "version" ]]; then
fail "asdf-${TOOL_NAME} supports release installs only"
fi

# download tar.gz file to the download directory
# download and extract tool to the download directory
download_release "${ASDF_INSTALL_VERSION}" "${ASDF_DOWNLOAD_PATH}"

# extract contents of tar.gz file into the download directory
extract_release "${ASDF_INSTALL_VERSION}" "${ASDF_DOWNLOAD_PATH}"
2 changes: 1 addition & 1 deletion bin/help.links
Expand Up @@ -12,6 +12,6 @@ cat << EOF
Links:
- asdf plugin repository: https://github.com/olofvndrhr/asdf-just
- tool repository: https://github.com/casey/just
- tool website: https://just.systems/
- tool website: https://just.systems/man/en/
EOF
6 changes: 1 addition & 5 deletions bin/help.overview
Expand Up @@ -9,14 +9,10 @@ plugin_dir=$(dirname "$(dirname "${current_script_path}")")
source "${plugin_dir}/lib/utils.bash"

cat << EOF
> From the github page:
> More infos on: https://just.systems/man/en/
just is a handy way to save and run project-specific commands.
This readme is also available as a book.
(中文文档在 这里, 快看过来!)
Commands, called recipes, are stored in a file called justfile with syntax inspired by make.
You can then run them with just RECIPE:
Expand Down
3 changes: 1 addition & 2 deletions contributing.md
@@ -1,11 +1,10 @@
# Contributing
Contributing

Testing Locally:

```shell
asdf plugin test <plugin-name> <plugin-url> [--asdf-tool-version <version>] [--asdf-plugin-gitref <git-ref>] [test-command*]

#
asdf plugin test just https://github.com/olofvndrhr/asdf-just.git "just --version"
```

Expand Down
80 changes: 40 additions & 40 deletions lib/utils.bash
Expand Up @@ -4,7 +4,7 @@ set -euo pipefail

GH_REPO="https://github.com/casey/just"
TOOL_NAME="just"
TOOL_TEST="just --version"
TOOL_TEST="--version"

function fail() {
echo -e "asdf-${TOOL_NAME}: ${*}"
Expand Down Expand Up @@ -37,21 +37,32 @@ function list_all_versions() {
function get_platform() {
local platform arch

platform="$(uname -s)"
arch="$(uname -m)"

case "${platform}" in
"Linux") platform_dl="unknown-linux-musl" ;;
"*BSD") platform_dl="unknown-linux-musl" ;;
"Darwin") platform_dl="apple-darwin" ;;
case "$(uname -s)" in
"Linux")
platform="unknown-linux-musl"
;;
"*BSD")
platform="unknown-linux-musl"
;;
"Darwin")
platform="apple-darwin"
;;
esac
case "${arch}" in
"x86_64" | "amd64") arch_dl="x86_64" ;;
"arm64" | "aarch64") arch_dl="aarch64" ;;
"arm" | "armv7") arch_dl="armv7" ;;

case "$(uname -m)" in
"x86_64" | "amd64")
arch="x86_64"
;;
"arm64" | "aarch64")
arch="aarch64"
;;
"arm" | "armv7")
arch="armv7"
platform=unknown-linux-musleabihf
;;
esac

echo "${arch_dl}-${platform_dl}"
echo -n "${arch}-${platform}"
}

function download_release() {
Expand All @@ -60,57 +71,46 @@ function download_release() {
version="${1}"
download_path="${2}"
platform="$(get_platform)"
release_tar="just-${version}-${platform}.tar.gz"
release_tar="${TOOL_NAME}-${version}-${platform}.tar.gz"

url="${GH_REPO}/releases/download/${version}/${release_tar}"

mkdir -p "${download_path}"

echo "* Platform: ${platform}"
echo "* Downloading ${TOOL_NAME} release ${version}..."
echo "* Downloading ${TOOL_NAME}, release ${version}..."
if ! curl "${curl_opts[@]}" -o "${download_path}/${release_tar}" -C - "${url}"; then
fail "Could not download ${url}"
fi
}

function extract_release() {
local version download_path platform release_tar

version="${1}"
download_path="${2}"
platform="$(get_platform)"
release_tar="just-${version}-${platform}.tar.gz"
echo "> Download successful"

echo "* Extracting ${release_tar}..."
if ! tar -xzf "${download_path}/${release_tar}" -C "${download_path}" just; then
if ! tar -xzf "${download_path}/${release_tar}" -C "${download_path}" "${TOOL_NAME}"; then
fail "Could not extract ${release_tar}"
fi
rm -f "${download_path}/${release_tar}"
echo "> Extraction successful"
}

function install_version() {
local version install_path download_path tool_cmd
local version install_path download_path

version="${1}"
install_path="${2%/bin}/bin"
download_path="${3}"

if ! (
mkdir -p "${install_path}"

mv -f "${download_path}/just" "${install_path}"
mkdir -p "${install_path}"

tool_cmd="$(echo "${TOOL_TEST}" | cut -d' ' -f1)"
if [[ ! -x "${install_path}/${tool_cmd}" ]]; then
fail "Expected ${install_path}/${tool_cmd} to be executable."
fi
if ! "${install_path}/${tool_cmd}" --version; then
fail "'${tool_cmd} --version' failed."
fi
mv -f "${download_path}/${TOOL_NAME}" "${install_path}/${TOOL_NAME}"

echo "${TOOL_NAME} ${version} installation was successful!"
); then
if [[ ! -x "${install_path}/${TOOL_NAME}" ]]; then
rm -rf "${install_path}"
fail "An error occurred while installing ${TOOL_NAME} ${version}."
fail "Expected ${install_path}/${TOOL_NAME} to be executable"
fi
if ! "${install_path}/${TOOL_NAME}" "${TOOL_TEST}"; then
rm -rf "${install_path}"
fail "Error with command: '${TOOL_NAME} ${TOOL_TEST}'"
fi

echo "> ${TOOL_NAME} ${version} installation was successful!"
}
4 changes: 4 additions & 0 deletions scripts/format.bash
@@ -0,0 +1,4 @@
#!/usr/bin/env bash

shfmt --language-dialect bash --write -i 4 -bn -ci -sr \
./**/*
9 changes: 9 additions & 0 deletions scripts/lint.bash
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

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

shfmt --language-dialect bash --diff -i 4 -bn -ci -sr \
./**/*
4 changes: 0 additions & 4 deletions scripts/shellcheck.bash

This file was deleted.

3 changes: 0 additions & 3 deletions scripts/shfmt.bash

This file was deleted.

0 comments on commit 76431f9

Please sign in to comment.