Skip to content

Commit

Permalink
Merge branch 'master' into add-unset-all
Browse files Browse the repository at this point in the history
  • Loading branch information
edvardsanta authored Sep 11, 2023
2 parents 79906e7 + c18b60f commit c876fef
Show file tree
Hide file tree
Showing 13 changed files with 102 additions and 54 deletions.
4 changes: 4 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@ updates:
interval: "monthly"
reviewers:
- "jthegedus"
groups:
docs:
patterns:
- "*"
2 changes: 1 addition & 1 deletion .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
working-directory: docs/

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
# fetch all commits to get last updated time or other git log info
fetch-depth: 0
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
asdf:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: asdf-vm/actions/install@v2
- uses: actions/setup-python@v4
with:
Expand All @@ -24,7 +24,7 @@ jobs:
actions:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Check workflow files
uses: docker://rhysd/actionlint:1.6.24
with:
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
documentation: ${{ steps.filter.outputs.documentation }}
cli: ${{ steps.filter.outputs.cli }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: dorny/paths-filter@v2
Expand Down Expand Up @@ -44,7 +44,7 @@ jobs:
if: ${{ needs.detect-changes.outputs.cli == 'true' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0
- run: scripts/install_dependencies.bash
Expand All @@ -59,7 +59,7 @@ jobs:
if: ${{ needs.detect-changes.outputs.cli == 'true' }}
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0
- run: scripts/install_dependencies.bash
Expand All @@ -75,7 +75,7 @@ jobs:
if: ${{ github.event_name == 'pull_request' && needs.detect-changes.outputs.documentation == 'true' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
# fetch all commits to get git log info for Vuepress
fetch-depth: 0
Expand Down
10 changes: 5 additions & 5 deletions asdf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
export ASDF_DIR="${ASDF_DIR:-}"

if [ -z "$ASDF_DIR" ]; then
if [ -n "$BASH_VERSION" ]; then
if [ -n "${BASH_VERSION:-}" ]; then
# Use BASH_SOURCE[0] to obtain the relative path to this source'd file. Since it's
# a relative path, 'cd' to its dirname and use '$PWD' to obtain the fullpath.
# Use 'builtin cd' to ensure user-defined 'cd()' functions aren't called.
Expand All @@ -28,14 +28,14 @@ if [ -z "$ASDF_DIR" ]; then
return 1
fi
unset -v _asdf_old_dir
elif [ -n "$ZSH_VERSION" ]; then
elif [ -n "${ZSH_VERSION:-}" ]; then
# Use '%x' to expand to path of current file. It must be prefixed
# with '(%):-', so it expands in non-prompt-string contexts.

# shellcheck disable=SC2296
ASDF_DIR=${(%):-%x}
ASDF_DIR=${ASDF_DIR%/*}
elif [ -n "$KSH_VERSION" ] && [ -z "$PATHSEP" ]; then
elif [ -n "${KSH_VERSION:-}" ] && [ -z "$PATHSEP" ]; then
# Only the original KornShell (kornshell.com) has a '.sh.file' variable with the path
# of the current file. To prevent errors with other variations, such as the MirBSD
# Korn shell (mksh), test for 'PATHSEP' which is _not_ set on the original Korn Shell.
Expand Down Expand Up @@ -65,7 +65,7 @@ if [ -n "${ASDF_FORCE_PREPEND+x}" ]; then
else
# If ASDF_FORCE_PREPEND is not set, then prepend by default on macOS
# to workaround `path_helper`.
if [ -n "$BASH_VERSION" ] || [ -n "$ZSH_VERSION" ]; then
if [ -n "${BASH_VERSION:-}" ] || [ -n "${ZSH_VERSION:-}" ]; then
# shellcheck disable=SC3028
case $OSTYPE in
darwin*) _asdf_should_prepend=yes ;;
Expand All @@ -85,7 +85,7 @@ fi
# If prepending is enabled, remove any existing instances of asdf from PATH so
# the prepending done after is always at the frontmost part of the PATH.
if [ "$_asdf_should_prepend" = 'yes' ]; then
if [ -n "$BASH_VERSION" ] || [ -n "$ZSH_VERSION" ]; then
if [ -n "${BASH_VERSION:-}" ] || [ -n "${ZSH_VERSION:-}" ]; then
# shellcheck disable=SC3060
case ":$PATH:" in
*":${_asdf_bin}:"*) PATH=${PATH//$_asdf_bin:/} ;;
Expand Down
12 changes: 12 additions & 0 deletions bin/asdf
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,18 @@ asdf_cmd() {
fi

if [ -x "$ASDF_CMD_FILE" ]; then
# When '$ASDF_CMD_FILE' is an executable, we are executing a command directly from a plugin.
# Example: https://github.com/asdf-community/asdf-nim/blob/397c14a7f04ad5b91963814afc2e9cc92366e1c5/lib/commands/command-install-deps.bash
# In those cases, the path to that command is always an absolute path. However, this codepath can also be activated if a user accidentally
# marks files in ./lib/commands/* as executable. This code detects when that happens and prints a useful warning message.
if [[ "$ASDF_CMD_FILE" == ./lib/commands/* ]]; then
printf '%s\n' "----------"
printf '%s\n' "asdf: Warning: You are executing an asdf command from \$ASDF_DIR, but we detected that some files have been"
printf '%s\n' " erroneously marked as executable. All files under '$ASDF_DIR/lib/commands' must NOT be marked"
printf '%s\n' " as executable. Otherwise, asdf will not be able to source its core files"
printf '%s\n' "----------"
fi >&2

exec "$ASDF_CMD_FILE" "${@:${args_offset}}"
elif [ -f "$ASDF_CMD_FILE" ]; then
set -- "${@:${args_offset}}"
Expand Down
8 changes: 4 additions & 4 deletions docs/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"preview": "vitepress preview"
},
"devDependencies": {
"@types/node": "^20.3.3",
"@types/node": "^20.5.7",
"prettier": "^2.8.8",
"vitepress": "^1.0.0-beta.3"
}
Expand Down
1 change: 1 addition & 0 deletions lib/functions/plugins.bash
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ update_plugin() {
local prev_ref=
local post_ref=
{
printf "Location of %s plugin: %s\n" "$plugin_name" "$plugin_path"
asdf_run_hook "pre_asdf_plugin_update" "$plugin_name"
asdf_run_hook "pre_asdf_plugin_update_${plugin_name}"

Expand Down
5 changes: 3 additions & 2 deletions scripts/install_dependencies.bash
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ if [ -z "$RUNNER_OS" ]; then
exit 1
fi

### Set environment variables for tracking versions
### Set variables for tracking versions
# Elvish
elvish_semver="v0.19.2"
# Fish
Expand Down Expand Up @@ -73,5 +73,6 @@ fi

### Install bats-core
printf "%s\n" "Installing bats-core"
git clone --depth 1 --branch "v$(grep -Eo "^\\s*bats\\s*.*$" ".tool-versions" | cut -d ' ' -f2-)" https://github.com/bats-core/bats-core.git "$HOME/bats-core"
bats_version=$(grep -Eo "^\\s*bats\\s*.*$" ".tool-versions" | cut -d ' ' -f2-)
git clone --depth 1 --branch "v$bats_version" https://github.com/bats-core/bats-core.git "$HOME/bats-core"
echo "$HOME/bats-core/bin" >>"$GITHUB_PATH"
50 changes: 30 additions & 20 deletions scripts/lint.bash
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
set -euo pipefail
IFS=$'\n\t'

print.info() {
printf '[INFO] %s\n' "$*"
}

print.error() {
printf '[ERROR] %s\n' "$*" >&2
}

usage() {
printf "%s\n" "Lint script for the asdf codebase. Must be executed from the"
printf "%s\n\n" "repository root directory."
Expand All @@ -21,7 +29,7 @@ run_shfmt_stylecheck() {
shfmt_flag="--diff"
fi

printf "%s\n" "[INFO] Checking .bash with shfmt"
print.info "Checking .bash with shfmt"
shfmt --language-dialect bash --indent 2 "${shfmt_flag}" \
completions/*.bash \
bin/asdf \
Expand All @@ -35,17 +43,17 @@ run_shfmt_stylecheck() {
test/fixtures/dummy_legacy_plugin/bin/* \
test/fixtures/dummy_plugin/bin/*

printf "%s\n" "[INFO] Checking .bats with shfmt"
print.info "Checking .bats with shfmt"
shfmt --language-dialect bats --indent 2 "${shfmt_flag}" \
test/*.bats
}

run_shellcheck_linter() {
printf "%s\n" "[INFO] Checking .sh files with Shellcheck"
print.info "Checking .sh files with Shellcheck"
shellcheck --shell sh --external-sources \
asdf.sh

printf "%s\n" "[INFO] Checking .bash files with Shellcheck"
print.info "Checking .bash files with Shellcheck"
shellcheck --shell bash --external-sources \
completions/*.bash \
bin/asdf \
Expand All @@ -59,7 +67,7 @@ run_shellcheck_linter() {
test/fixtures/dummy_legacy_plugin/bin/* \
test/fixtures/dummy_plugin/bin/*

printf "%s\n" "[INFO] Checking .bats files with Shellcheck"
print.info "Checking .bats files with Shellcheck"
shellcheck --shell bats --external-source \
test/*.bats
}
Expand All @@ -74,15 +82,15 @@ run_custom_python_stylecheck() {

if [ -n "$github_actions" ] && ! command -v python3 &>/dev/null; then
# fail if CI and no python3
printf "%s\n" "[ERROR] Detected execution in GitHub Actions but python3 was not found. This is required during CI linting."
print.error "Detected execution in GitHub Actions but python3 was not found. This is required during CI linting."
exit 1
fi

if ! command -v python3 &>/dev/null; then
# skip if local and no python3
printf "%s\n" "[WARNING] python3 not found. Skipping Custom Python Script."
else
printf "%s\n" "[INFO] Checking files with Custom Python Script."
print.info "Checking files with Custom Python Script."
"${0%/*}/checkstyle.py" "${flag}"
fi

Expand All @@ -106,15 +114,15 @@ run_fish_linter() {

if [ -n "$github_actions" ] && ! command -v fish_indent &>/dev/null; then
# fail if CI and no fish_ident
printf "%s\n" "[ERROR] Detected execution in GitHub Actions but fish_indent was not found. This is required during CI linting."
print.error "Detected execution in GitHub Actions but fish_indent was not found. This is required during CI linting."
exit 1
fi

if ! command -v fish_indent &>/dev/null; then
# skip if local and no fish_ident
printf "%s\n" "[WARNING] fish_indent not found. Skipping .fish files."
else
printf "%s\n" "[INFO] Checking .fish files with fish_indent"
print.info "Checking .fish files with fish_indent"
fish_indent "${flag}" ./**/*.fish
fi
}
Expand All @@ -129,17 +137,19 @@ run_fish_linter() {
# printf "%s\n" "[WARNING] powershell linter/formatter not found, skipping for now."
#}

repo_root=$(git rev-parse --show-toplevel)
if [ "$repo_root" != "$PWD" ]; then
printf "%s\n" "[ERROR] This scripts requires execution from the repository root directory."
printf "\t%s\t%s\n" "Repo root dir:" "$repo_root"
printf "\t%s\t%s\n\n" "Current dir:" "$PWD"
printf "%s\n" "See usage details with -h or --help."
exit 1
fi
{
repo_dir=$(git rev-parse --show-toplevel)
current_dir=$(pwd -P)
if [ "$repo_dir" != "$current_dir" ]; then
print.error "This scripts requires execution from the repository root directory."
printf "\t%s\t%s\n" "Repo root dir:" "$repo_dir"
printf "\t%s\t%s\n\n" "Current dir:" "$current_dir"
exit 1
fi
}

if [ $# -eq 0 ]; then
printf "%s\n" "[ERROR] At least one option required."
print.error "At least one option required."
printf "=%.0s" {1..60}
printf "\n"
usage
Expand All @@ -159,7 +169,7 @@ case "$1" in
mode="fix"
;;
*)
printf "%s\n" "[ERROR] Invalid flag: $1"
print.error "Invalid flag: $1"
printf "=%.0s" {1..60}
printf "\n"
usage
Expand All @@ -177,4 +187,4 @@ run_fish_linter "$mode"
#run_nushell_linter "$mode"
#run_powershell_linter "$mode"

printf "%s\n" "[INFO] Success!"
print.info "Success!"
37 changes: 24 additions & 13 deletions scripts/test.bash
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,37 @@
set -euo pipefail
IFS=$'\n\t'

repo_root=$(git rev-parse --show-toplevel)
if [ "$repo_root" != "$PWD" ]; then
printf "%s\n" "[ERROR] This scripts requires execution from the repository root directory."
printf "\t%s\t%s\n" "Repo root dir:" "$repo_root"
printf "\t%s\t%s\n\n" "Current dir:" "$PWD"
exit 1
fi
print.info() {
printf '[INFO] %s\n' "$1"
}

print.error() {
printf '[ERROR] %s\n' "$1" >&2
}

{
repo_dir=$(git rev-parse --show-toplevel)
current_dir=$(pwd -P)
if [ "$repo_dir" != "$current_dir" ]; then
print.error "This scripts requires execution from the repository root directory."
printf "\t%s\t%s\n" "Repo root dir:" "$repo_dir"
printf "\t%s\t%s\n\n" "Current dir:" "$current_dir"
exit 1
fi
}

test_directory="test"
test_directory="./test"
bats_options=(--timing --print-output-on-failure)

if command -v parallel >/dev/null; then
# enable parallel jobs
bats_options=("${bats_options[@]}" --jobs 2 --no-parallelize-within-files)
# Enable parallel jobs
bats_options+=(--jobs 2 --no-parallelize-within-files)
elif [[ -n "${CI-}" ]]; then
printf "* %s\n" "GNU parallel should be installed in the CI environment. Please install and rerun the test suite."
print.error "GNU parallel should be installed in the CI environment. Please install and rerun the test suite."
exit 1
else
printf "* %s\n" "For faster test execution, install GNU parallel."
print.info "For faster test execution, install GNU parallel."
fi

printf "* %s\n" "Running Bats in directory '${test_directory}' with options:" "${bats_options[@]}"
print.info "Running Bats in directory '${test_directory}' with options:" "${bats_options[@]}"
bats "${bats_options[@]}" "${test_directory}"
Loading

0 comments on commit c876fef

Please sign in to comment.