fix: plugin test git-ref to use plugin repo default branch (#1694)

Co-authored-by: James Hegedus <jthegedus@hey.com>
This commit is contained in:
Javier Garea 2024-01-09 13:47:27 +01:00 committed by GitHub
parent d7e0740461
commit 6d8cf9d44b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 18 deletions

View File

@ -814,7 +814,7 @@ asdf plugin test <plugin_name> <plugin_url> [--asdf-tool-version <version>] [--a
installed with that specific version. Defaults to `asdf latest <plugin-name>` installed with that specific version. Defaults to `asdf latest <plugin-name>`
- If optional `[--asdf-plugin-gitref <git_ref>]` is specified, the plugin itself - If optional `[--asdf-plugin-gitref <git_ref>]` is specified, the plugin itself
is checked out at that commit/branch/tag. This is useful for testing a is checked out at that commit/branch/tag. This is useful for testing a
pull-request on your plugin's CI. pull-request on your plugin's CI. Defaults to the default branch of the plugin's repository.
- Optional parameter `[test_command...]` is the command to execute to validate - Optional parameter `[test_command...]` is the command to execute to validate
the installed tool works correctly. Typically `<tool> --version` or the installed tool works correctly. Typically `<tool> --version` or
`<tool> --help`. For example, to test the NodeJS plugin, we could run `<tool> --help`. For example, to test the NodeJS plugin, we could run

View File

@ -209,8 +209,8 @@ asdf plugin test <plugin-name> <plugin-url> [--asdf-tool-version <version>] [--a
``` ```
Apenas os dois primeiros argumentos são necessários. Apenas os dois primeiros argumentos são necessários.
Se \__version_ for especificado, a ferramenta será instalada com essa versão específica. O padrão é o que retorna `asdf mais recente <plugin-name>`. Se \__version_ for especificado, a ferramenta será instalada com essa versão específica. O padrão é o que retorna `asdf latest <plugin-name>`.
Se _git-ref_ for especificado, o plug-in em si é verificado nesse commit/branch/tag, útil para testar um pull-request no CI do seu plug-in. Se _git-ref_ for especificado, o plug-in em si é verificado nesse commit/branch/tag, útil para testar um pull-request no CI do seu plug-in. O padrão é o branch _default_ do repositório do plugin.
Os argumentos Rest são considerados o comando a ser executado para garantir que a ferramenta instalada funcione corretamente. Os argumentos Rest são considerados o comando a ser executado para garantir que a ferramenta instalada funcione corretamente.
Normalmente seria algo que leva `--version` ou `--help`. Normalmente seria algo que leva `--version` ou `--help`.

View File

@ -222,7 +222,7 @@ asdf plugin test <plugin-name> <plugin-url> [--asdf-tool-version <version>] [--a
只有前两个参数是必须的。 只有前两个参数是必须的。
如果指定了 \__version_则该工具将随指定版本一起安装。默认返回为 `asdf latest <plugin-name>` 如果指定了 \__version_则该工具将随指定版本一起安装。默认返回为 `asdf latest <plugin-name>`
如果指定了 _git-ref_,则插件将检查提交/分支/标签。这对于在该插件的 CI 上测试拉取请求非常有用。 如果指定了 _git-ref_,则插件将检查提交/分支/标签。这对于在该插件的 CI 上测试拉取请求非常有用。默认值是插件仓库的默认分支。
剩下的参数被视为要执行的命令,以确保安装的工具正常工作。通常情况下,它需要带 `--version` 或者 `--help`。例如,要测试 NodeJS 插件,我们可以运行: 剩下的参数被视为要执行的命令,以确保安装的工具正常工作。通常情况下,它需要带 `--version` 或者 `--help`。例如,要测试 NodeJS 插件,我们可以运行:

View File

@ -14,7 +14,20 @@ plugin_test_command() {
local plugin_url="$2" local plugin_url="$2"
shift 2 shift 2
local plugin_gitref="master" local exit_code
local TEST_DIR
fail_test() {
printf "FAILED: %s\n" "$1"
rm -rf "$TEST_DIR"
exit 1
}
if [ -z "$plugin_name" ] || [ -z "$plugin_url" ]; then
fail_test "please provide a plugin name and url"
fi
local plugin_gitref
local tool_version local tool_version
local interpret_args_literally local interpret_args_literally
local skip_next_arg local skip_next_arg
@ -45,21 +58,13 @@ plugin_test_command() {
fi fi
done done
if [ "$#" -eq 1 ]; then if [ -z "$plugin_gitref" ]; then
set -- "${SHELL:-sh}" -c "$1" plugin_remote_default_branch=$(git ls-remote --symref "$plugin_url" HEAD | awk '{ sub(/refs\/heads\//, ""); print $2; exit }')
plugin_gitref=${3:-${plugin_remote_default_branch}}
fi fi
local exit_code if [ "$#" -eq 1 ]; then
local TEST_DIR set -- "${SHELL:-sh}" -c "$1"
fail_test() {
printf "FAILED: %s\n" "$1"
rm -rf "$TEST_DIR"
exit 1
}
if [ -z "$plugin_name" ] || [ -z "$plugin_url" ]; then
fail_test "please provide a plugin name and url"
fi fi
TEST_DIR=$(mktemp -dt asdf.XXXX) TEST_DIR=$(mktemp -dt asdf.XXXX)