From e6f7aa395fabc7eca1ee4d93e454d2551cea505c Mon Sep 17 00:00:00 2001 From: Jelle van der Waa Date: Sun, 5 Nov 2023 16:11:12 +0100 Subject: feat(version): introduce version check subcommand The version subcommand handles pkgver related commands, the first subcommand being `check`. Check runs nvchecker if a `.nvchecker.toml` file exists and compares the current pkgver with the latest release. Introduces nvchecker as optional dependency which has to be installed in order to use this particular subcommand. BREAKING CHANGE: formerly pkgctl version would output the version of the pkgctl tool, now it is used as a version related subcommand. Fixes #140 Component: pkgctl version Component: pkgctl version check Co-authored-by: Christian Heusel --- src/lib/version/check.sh | 97 ++++++++++++++++++++++++++++++++++++++++++++++ src/lib/version/version.sh | 47 ---------------------- 2 files changed, 97 insertions(+), 47 deletions(-) create mode 100644 src/lib/version/check.sh delete mode 100644 src/lib/version/version.sh (limited to 'src/lib/version') diff --git a/src/lib/version/check.sh b/src/lib/version/check.sh new file mode 100644 index 0000000..f6619c2 --- /dev/null +++ b/src/lib/version/check.sh @@ -0,0 +1,97 @@ +#!/bin/bash +# +# SPDX-License-Identifier: GPL-3.0-or-later +# +[[ -z ${DEVTOOLS_INCLUDE_VERSION_CHECK_SH:-} ]] || return 0 +DEVTOOLS_INCLUDE_VERSION_CHECK_SH=1 + +_DEVTOOLS_LIBRARY_DIR=${_DEVTOOLS_LIBRARY_DIR:-@pkgdatadir@} +# shellcheck source=src/lib/common.sh +source "${_DEVTOOLS_LIBRARY_DIR}"/lib/common.sh + +source /usr/share/makepkg/util/message.sh + +set -e + +pkgctl_version_check_usage() { + local -r COMMAND=${_DEVTOOLS_COMMAND:-${BASH_SOURCE[0]##*/}} + cat <<- _EOF_ + Usage: ${COMMAND} [OPTIONS] [PKGBASE]... + + Uses nvchecker, a .nvchecker.toml file and the current PKGBUILD + pkgver to check if there is a newer package version available. + + The current working directory is used if no PKGBASE is specified. + + OPTIONS + -h, --help Show this help text + + EXAMPLES + $ ${COMMAND} neovim vim +_EOF_ +} + +pkgctl_version_check() { + local path + local pkgbases=() + + while (( $# )); do + case $1 in + -h|--help) + pkgctl_version_check_usage + exit 0 + ;; + --) + shift + break + ;; + -*) + die "invalid argument: %s" "$1" + ;; + *) + pkgbases=("$@") + break + ;; + esac + done + + if ! command -v nvchecker &>/dev/null; then + die "The \"$_DEVTOOLS_COMMAND\" command requires 'nvchecker'" + fi + + # Check if used without pkgbases in a packaging directory + if (( ${#pkgbases[@]} == 0 )); then + if [[ -f PKGBUILD ]]; then + pkgbases=(".") + else + pkgctl_version_check_usage + exit 1 + fi + fi + + for path in "${pkgbases[@]}"; do + pushd "${path}" >/dev/null + run_nvchecker "${path}" + popd >/dev/null + done +} + +run_nvchecker() { + local path=$1 + local pkgbase latest_version + + if [[ ! -f ".nvchecker.toml" || ! -f "PKGBUILD" ]]; then + die "No .nvchecker.toml or PKGBUILD found for ${path}" + exit 1 + fi + + # TODO: parse .SRCINFO file + # shellcheck source=contrib/makepkg/PKGBUILD.proto + . ./PKGBUILD + pkgbase=${pkgbase:-$pkgname} + + latest_version=$(nvchecker -c .nvchecker.toml --logger json | jq --raw-output 'select( .version ) | .version') + if (( $(vercmp "${latest_version}" "${pkgver}") > 0 )); then + msg2 "New ${pkgbase} version ${latest_version} is available upstream" + fi +} diff --git a/src/lib/version/version.sh b/src/lib/version/version.sh deleted file mode 100644 index d00a460..0000000 --- a/src/lib/version/version.sh +++ /dev/null @@ -1,47 +0,0 @@ -#!/hint/bash -# -# SPDX-License-Identifier: GPL-3.0-or-later - -[[ -z ${DEVTOOLS_INCLUDE_VERSION_SH:-} ]] || return 0 -DEVTOOLS_INCLUDE_VERSION_SH=1 - -_DEVTOOLS_LIBRARY_DIR=${_DEVTOOLS_LIBRARY_DIR:-@pkgdatadir@} - -source /usr/share/makepkg/util/message.sh - -set -e - - -pkgctl_version_usage() { - local -r COMMAND=${_DEVTOOLS_COMMAND:-${BASH_SOURCE[0]##*/}} - cat <<- _EOF_ - Usage: ${COMMAND} [OPTIONS] - - Shows the current version information of pkgctl - - OPTIONS - -h, --help Show this help text -_EOF_ -} - -pkgctl_version_print() { - cat <<- _EOF_ - pkgctl @buildtoolver@ -_EOF_ -} - -pkgctl_version() { - while (( $# )); do - case $1 in - -h|--help) - pkgctl_version_usage - exit 0 - ;; - *) - die "invalid argument: %s" "$1" - ;; - esac - done - - pkgctl_version_print -} -- cgit v1.2.3-70-g09d2 From 313c5b4d32291e618cc136035f5e056581aec416 Mon Sep 17 00:00:00 2001 From: Christian Heusel Date: Fri, 5 Jan 2024 18:35:39 +0100 Subject: chore(check): factor out function to get upstream version Component: pkgctl version check Signed-off-by: Christian Heusel --- src/lib/version/check.sh | 42 ++++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 16 deletions(-) (limited to 'src/lib/version') diff --git a/src/lib/version/check.sh b/src/lib/version/check.sh index f6619c2..b93752a 100644 --- a/src/lib/version/check.sh +++ b/src/lib/version/check.sh @@ -34,6 +34,8 @@ _EOF_ pkgctl_version_check() { local path local pkgbases=() + local path pkgbase upstream_version + while (( $# )); do case $1 in @@ -71,27 +73,35 @@ pkgctl_version_check() { for path in "${pkgbases[@]}"; do pushd "${path}" >/dev/null - run_nvchecker "${path}" + + if [[ ! -f "PKGBUILD" ]]; then + die "No PKGBUILD found for ${path}" + fi + + # shellcheck disable=SC2119 + upstream_version=$(get_upstream_version) + + # TODO: parse .SRCINFO file + # shellcheck source=contrib/makepkg/PKGBUILD.proto + . ./PKGBUILD + pkgbase=${pkgbase:-$pkgname} + + if (( $(vercmp "${upstream_version}" "${pkgver}") > 0 )); then + msg2 "New ${pkgbase} version ${upstream_version} is available upstream" + fi + popd >/dev/null done } -run_nvchecker() { - local path=$1 - local pkgbase latest_version +get_upstream_version() { + local config=${1:-.nvchecker.toml} + local upstream_version - if [[ ! -f ".nvchecker.toml" || ! -f "PKGBUILD" ]]; then - die "No .nvchecker.toml or PKGBUILD found for ${path}" - exit 1 + if [[ ! -f $config ]]; then + die "No $config found" fi - # TODO: parse .SRCINFO file - # shellcheck source=contrib/makepkg/PKGBUILD.proto - . ./PKGBUILD - pkgbase=${pkgbase:-$pkgname} - - latest_version=$(nvchecker -c .nvchecker.toml --logger json | jq --raw-output 'select( .version ) | .version') - if (( $(vercmp "${latest_version}" "${pkgver}") > 0 )); then - msg2 "New ${pkgbase} version ${latest_version} is available upstream" - fi + upstream_version=$(nvchecker -c "$config" --logger json | jq --raw-output 'select( .version ) | .version') + printf "%s" "$upstream_version" } -- cgit v1.2.3-70-g09d2 From 6054c869e1b9b853aa7408261e477dcb187ff498 Mon Sep 17 00:00:00 2001 From: Christian Heusel Date: Fri, 5 Jan 2024 19:10:38 +0100 Subject: feat(upgrade): introduce the version upgrade subcommand This subcommand applies the detected upstream version upgrades to a PKGBUILD. Component: pkgctl version upgrade Co-authored-by: Levente Polyak Signed-off-by: Christian Heusel --- contrib/completion/bash/devtools.in | 7 ++ contrib/completion/zsh/_devtools.in | 6 ++ doc/man/pkgctl-version-upgrade.1.asciidoc | 33 +++++++++ doc/man/pkgctl-version.1.asciidoc | 4 ++ src/lib/version.sh | 11 ++- src/lib/version/upgrade.sh | 108 ++++++++++++++++++++++++++++++ 6 files changed, 168 insertions(+), 1 deletion(-) create mode 100644 doc/man/pkgctl-version-upgrade.1.asciidoc create mode 100644 src/lib/version/upgrade.sh (limited to 'src/lib/version') diff --git a/contrib/completion/bash/devtools.in b/contrib/completion/bash/devtools.in index f1084ab..101bd78 100644 --- a/contrib/completion/bash/devtools.in +++ b/contrib/completion/bash/devtools.in @@ -339,6 +339,7 @@ _pkgctl_repo_switch_opts() { _pkgctl_version_cmds=( check + upgrade ) _pkgctl_version_check_args=( @@ -347,6 +348,12 @@ _pkgctl_version_check_args=( _pkgctl_version_check_opts() { _filedir -d; } +_pkgctl_version_upgrade_args=( + -h --help +) + +_pkgctl_version_upgrade_opts() { _filedir -d; } + _pkgctl_repo_web_args=( --print -h --help diff --git a/contrib/completion/zsh/_devtools.in b/contrib/completion/zsh/_devtools.in index 575c327..38bf582 100644 --- a/contrib/completion/zsh/_devtools.in +++ b/contrib/completion/zsh/_devtools.in @@ -288,6 +288,7 @@ _pkgctl_args=( _pkgctl_version_cmds=( "pkgctl version command" "check[Check if there is an new upstream version available]" + "upgrade[Upgrade the PKGBUILD according to the latest available upstream version]" ) _pkgctl_version_check_args=( @@ -295,6 +296,11 @@ _pkgctl_version_check_args=( '*:git_dir:_files -/' ) +_pkgctl_version_upgrade_args=( + '(-h --help)'{-h,--help}'[Display usage]' + '*:git_dir:_files -/' +) + _pkgctl_diff_args=("${_diffpkg_args[@]}") _handle_subcommands() { diff --git a/doc/man/pkgctl-version-upgrade.1.asciidoc b/doc/man/pkgctl-version-upgrade.1.asciidoc new file mode 100644 index 0000000..3d5d882 --- /dev/null +++ b/doc/man/pkgctl-version-upgrade.1.asciidoc @@ -0,0 +1,33 @@ +pkgctl-version-upgrade(1) +========================= + +Name +---- +pkgctl-version-upgrade - Upgrade the PKGBUILD according to the latest available upstream version + +Synopsis +-------- +pkgctl version upgrade [OPTIONS] [PKGBASE...] + +Description +----------- + +Upgrade the PKGBUILD according to the latest available upstream version. + +Uses nvchecker, a .nvchecker.toml file and the current PKGBUILD pkgver to check +if there is a newer package version available. + +The current working directory is used if no PKGBASE is specified. + +Options +------- + +*-h, --help*:: + Show a help text + +See Also +-------- + +linkman:nvchecker[1] + +include::include/footer.asciidoc[] diff --git a/doc/man/pkgctl-version.1.asciidoc b/doc/man/pkgctl-version.1.asciidoc index 53a72f3..e71becd 100644 --- a/doc/man/pkgctl-version.1.asciidoc +++ b/doc/man/pkgctl-version.1.asciidoc @@ -27,9 +27,13 @@ Subcommands pkgctl version check:: Check if there is an new upstream version available +pkgctl version upgrade:: + Upgrade the PKGBUILD according to the latest available upstream version + See Also -------- linkman:pkgctl-version-check[1] +linkman:pkgctl-version-upgrade[1] include::include/footer.asciidoc[] diff --git a/src/lib/version.sh b/src/lib/version.sh index 826b306..14cd810 100644 --- a/src/lib/version.sh +++ b/src/lib/version.sh @@ -18,7 +18,8 @@ pkgctl_version_usage() { Package version related commands. COMMANDS - check Check if there is a newer version availble + check Check if there is a newer version availble + upgrade Upgrade the PKGBUILD according to the latest available upstream version OPTIONS -h, --help Show this help text @@ -48,6 +49,14 @@ pkgctl_version() { pkgctl_version_check "$@" exit 0 ;; + upgrade) + _DEVTOOLS_COMMAND+=" $1" + shift + # shellcheck source=src/lib/version/upgrade.sh + source "${_DEVTOOLS_LIBRARY_DIR}"/lib/version/upgrade.sh + pkgctl_version_upgrade "$@" + exit 0 + ;; *) die "invalid argument: %s" "$1" ;; diff --git a/src/lib/version/upgrade.sh b/src/lib/version/upgrade.sh new file mode 100644 index 0000000..704431a --- /dev/null +++ b/src/lib/version/upgrade.sh @@ -0,0 +1,108 @@ +#!/bin/bash +# +# SPDX-License-Identifier: GPL-3.0-or-later +# +[[ -z ${DEVTOOLS_INCLUDE_VERSION_UPGRADE_SH:-} ]] || return 0 +DEVTOOLS_INCLUDE_VERSION_UPGRADE_SH=1 + +_DEVTOOLS_LIBRARY_DIR=${_DEVTOOLS_LIBRARY_DIR:-@pkgdatadir@} +# shellcheck source=src/lib/common.sh +source "${_DEVTOOLS_LIBRARY_DIR}"/lib/common.sh +# shellcheck source=src/lib/version/check.sh +source "${_DEVTOOLS_LIBRARY_DIR}"/lib/version/check.sh +# shellcheck source=src/lib/util/pkgbuild.sh +source "${_DEVTOOLS_LIBRARY_DIR}"/lib/util/pkgbuild.sh + +source /usr/share/makepkg/util/message.sh + +set -e + +pkgctl_version_upgrade_usage() { + local -r COMMAND=${_DEVTOOLS_COMMAND:-${BASH_SOURCE[0]##*/}} + cat <<- _EOF_ + Usage: ${COMMAND} [OPTIONS] [PKGBASE]... + + Upgrade the PKGBUILD according to the latest available upstream version + + Uses nvchecker, a .nvchecker.toml file and the current PKGBUILD + pkgver to check if there is a newer package version available. + + The current working directory is used if no PKGBASE is specified. + + OPTIONS + -h, --help Show this help text + + EXAMPLES + $ ${COMMAND} neovim vim +_EOF_ +} + +pkgctl_version_upgrade() { + local path upstream_version result + local pkgbases=() + + while (( $# )); do + case $1 in + -h|--help) + pkgctl_version_upgrade_usage + exit 0 + ;; + --) + shift + break + ;; + -*) + die "invalid argument: %s" "$1" + ;; + *) + pkgbases=("$@") + break + ;; + esac + done + + if ! command -v nvchecker &>/dev/null; then + die "The \"$_DEVTOOLS_COMMAND\" command requires 'nvchecker'" + fi + + # Check if used without pkgbases in a packaging directory + if (( ${#pkgbases[@]} == 0 )); then + if [[ -f PKGBUILD ]]; then + pkgbases=(".") + else + pkgctl_version_upgrade_usage + exit 1 + fi + fi + + for path in "${pkgbases[@]}"; do + pushd "${path}" >/dev/null + + if [[ ! -f "PKGBUILD" ]]; then + die "No PKGBUILD found for ${path}" + fi + + # reset common PKGBUILD variables + unset pkgbase pkgname arch source pkgver pkgrel validpgpkeys + # shellcheck source=contrib/makepkg/PKGBUILD.proto + . ./PKGBUILD + pkgbase=${pkgbase:-$pkgname} + + if ! upstream_version=$(get_upstream_version); then + die "Failed to get latest upstream version for %s" "${pkgbase}" + fi + + if ! result=$(vercmp "${upstream_version}" "${pkgver}"); then + die "Failed to compare version %s against %s" "${upstream_version}" "${pkgver}" + fi + + if (( result > 0 )); then + msg_success "${BOLD}${pkgbase}${ALL_OFF}: upgrading from version ${PURPLE}${pkgver}${ALL_OFF} to ${DARK_GREEN}${upstream_version}${ALL_OFF}" + + pkgbuild_set_pkgver "${upstream_version}" + pkgbuild_set_pkgrel 1 + fi + + popd >/dev/null + done +} -- cgit v1.2.3-70-g09d2 From 03d5c928cf01e2aee56a4520ac5896c602fb1f75 Mon Sep 17 00:00:00 2001 From: Levente Polyak Date: Sat, 13 Jan 2024 14:33:09 +0100 Subject: fix(version): add error handling to version check subcommand Add defensive programming to the execution chain of the version check subcommand for graceful error handling of subprocesses as well as errors returned from nvchecker itself indicated in the returned JSON. Furthermore this fixes a bug when processing multiple packages where the pkgbase variable is stuck for subsequent packages that do not declare a pkgbase variable itself. Component: pkgctl version check Signed-off-by: Levente Polyak --- src/lib/version/check.sh | 107 ++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 93 insertions(+), 14 deletions(-) (limited to 'src/lib/version') diff --git a/src/lib/version/check.sh b/src/lib/version/check.sh index b93752a..c78e364 100644 --- a/src/lib/version/check.sh +++ b/src/lib/version/check.sh @@ -11,7 +11,7 @@ source "${_DEVTOOLS_LIBRARY_DIR}"/lib/common.sh source /usr/share/makepkg/util/message.sh -set -e +set -eo pipefail pkgctl_version_check_usage() { local -r COMMAND=${_DEVTOOLS_COMMAND:-${BASH_SOURCE[0]##*/}} @@ -34,8 +34,7 @@ _EOF_ pkgctl_version_check() { local path local pkgbases=() - local path pkgbase upstream_version - + local path pkgbase upstream_version result while (( $# )); do case $1 in @@ -78,15 +77,28 @@ pkgctl_version_check() { die "No PKGBUILD found for ${path}" fi - # shellcheck disable=SC2119 - upstream_version=$(get_upstream_version) - - # TODO: parse .SRCINFO file + # reset common PKGBUILD variables + unset pkgbase pkgname arch source pkgver pkgrel validpgpkeys # shellcheck source=contrib/makepkg/PKGBUILD.proto . ./PKGBUILD pkgbase=${pkgbase:-$pkgname} - if (( $(vercmp "${upstream_version}" "${pkgver}") > 0 )); then + if ! result=$(get_upstream_version); then + msg_error "${pkgbase}: ${result}" + popd >/dev/null + continue + fi + upstream_version=${result} + + if ! result=$(vercmp "${upstream_version}" "${pkgver}"); then + result="${BOLD}${pkgbase}${ALL_OFF}: failed to compare version ${upstream_version} against ${pkgver}" + msg_error "${result}" + + popd >/dev/null + continue + fi + + if (( result > 0 )); then msg2 "New ${pkgbase} version ${upstream_version} is available upstream" fi @@ -95,13 +107,80 @@ pkgctl_version_check() { } get_upstream_version() { - local config=${1:-.nvchecker.toml} - local upstream_version + local config=.nvchecker.toml + local output errors upstream_version + local output + + # check nvchecker config file + if ! errors=$(nvchecker_check_config "${config}"); then + printf "%s" "${errors}" + return 1 + fi + + if ! output=$(nvchecker --file "${config}" --logger json 2>&1 | \ + jq --raw-output 'select(.level != "debug")'); then + printf "failed to run nvchecker: %s" "${output}" + return 1 + fi + + if ! errors=$(nvchecker_check_error "${output}"); then + printf "%s" "${errors}" + return 1 + fi + + if ! upstream_version=$(jq --raw-output --exit-status '.version' <<< "${output}"); then + printf "failed to select version from result" + return 1 + fi + + printf "%s" "${upstream_version}" + return 0 +} + +nvchecker_check_config() { + local config=$1 + + local restricted_properties=(keyfile httptoken token) + local property + + # check if the config file exists + if [[ ! -f ${config} ]]; then + printf "configuration file not found: %s" "${config}" + return 1 + fi + + # check if config contains any restricted properties like secrets + for property in "${restricted_properties[@]}"; do + if grep --max-count=1 --quiet "^${property}" < "${config}"; then + printf "restricted property in %s: %s" "${config}" "${property}" + return 1 + fi + done + + # check if the config contains a pkgbase section + if [[ -n ${pkgbase} ]] && ! grep --max-count=1 --quiet "^\\[${pkgbase}\\]" < "${config}"; then + printf "missing pkgbase section in %s: %s" "${config}" "${pkgbase}" + return 1 + fi + + # check if the config contains any section other than pkgbase + if [[ -n ${pkgbase} ]] && property=$(grep --max-count=1 --perl-regexp "^\\[(?!${pkgbase}\\]).+\\]" < "${config}"); then + printf "none pkgbase section not supported in %s: %s" "${config}" "${property}" + return 1 + fi +} + +nvchecker_check_error() { + local result=$1 + local errors - if [[ ! -f $config ]]; then - die "No $config found" + if ! errors=$(jq --raw-output --exit-status \ + 'select(.level == "error") | "\(.event)" + if .error then ": \(.error)" else "" end' \ + <<< "${result}"); then + return 0 fi - upstream_version=$(nvchecker -c "$config" --logger json | jq --raw-output 'select( .version ) | .version') - printf "%s" "$upstream_version" + mapfile -t errors <<< "${errors}" + printf "%s\n" "${errors[@]}" + return 1 } -- cgit v1.2.3-70-g09d2 From 96f39525bf60a499aa840015159d9040b53be69a Mon Sep 17 00:00:00 2001 From: Levente Polyak Date: Sat, 13 Jan 2024 15:27:34 +0100 Subject: feat(version): support nvchecker keyfile from user config home This adds support for global keyfile from the user config home XDG_CONFIG_HOME which allows to set tokens for GitHub and GitLab for certain nvchecker configuration. When ~/.config/nvchecker/keyfile.toml exists, it will automatically be appended as keyfile of the local .nvchecker.toml file. Component: pkgctl version check Signed-off-by: Levente Polyak --- doc/man/pkgctl-version-check.1.asciidoc | 8 +++++++- src/lib/version/check.sh | 12 +++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) (limited to 'src/lib/version') diff --git a/doc/man/pkgctl-version-check.1.asciidoc b/doc/man/pkgctl-version-check.1.asciidoc index 97d8c47..ed9abdf 100644 --- a/doc/man/pkgctl-version-check.1.asciidoc +++ b/doc/man/pkgctl-version-check.1.asciidoc @@ -18,7 +18,13 @@ which this package could possibly be upgraded. The current working directory is used if no PKGBASE is specified. -See the section on configuration files in **nvchecker**(1) for possible options +Configuration +------------- + +To provide GitHub or GitLab tokens to nvchecker, a `keyfile.toml` will be +supplied from `$XDG_CONFIG_HOME`/nvchecker. + +See the section on configuration files in linkman:nvchecker[1] for possible options which can be utilized in .nvchecker.toml. Options diff --git a/src/lib/version/check.sh b/src/lib/version/check.sh index c78e364..600a346 100644 --- a/src/lib/version/check.sh +++ b/src/lib/version/check.sh @@ -23,6 +23,9 @@ pkgctl_version_check_usage() { The current working directory is used if no PKGBASE is specified. + To provide GitHub or GitLab tokens to nvchecker, a keyfile.toml + will be supplied from \${XDG_CONFIG_HOME}/nvchecker. + OPTIONS -h, --help Show this help text @@ -110,6 +113,8 @@ get_upstream_version() { local config=.nvchecker.toml local output errors upstream_version local output + local opts=() + local keyfile="${XDG_CONFIG_HOME:-${HOME}/.config}/nvchecker/keyfile.toml" # check nvchecker config file if ! errors=$(nvchecker_check_config "${config}"); then @@ -117,7 +122,12 @@ get_upstream_version() { return 1 fi - if ! output=$(nvchecker --file "${config}" --logger json 2>&1 | \ + # populate keyfile to nvchecker opts + if [[ -f ${keyfile} ]]; then + opts+=(--keyfile "${keyfile}") + fi + + if ! output=$(nvchecker --file "${config}" --logger json "${opts[@]}" 2>&1 | \ jq --raw-output 'select(.level != "debug")'); then printf "failed to run nvchecker: %s" "${output}" return 1 -- cgit v1.2.3-70-g09d2 From 66e83c950cfa1c51820f04130abfacaf7c6b4c4c Mon Sep 17 00:00:00 2001 From: Levente Polyak Date: Thu, 18 Jan 2024 02:29:27 +0100 Subject: feat(version): pretty print and group together version check results Collect all check results in arrays and pretty print the results after grouping them together based on out-of-date, up-to-date and failures. Print a summary that shows a brief statistic about the results when processing multiple check items. Component: pkgctl version check Component: pkgctl version upgrade Signed-off-by: Levente Polyak --- src/lib/common.sh | 3 +- src/lib/version/check.sh | 72 +++++++++++++++++++++++++++++++++++++--- src/lib/version/upgrade.sh | 82 ++++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 145 insertions(+), 12 deletions(-) (limited to 'src/lib/version') diff --git a/src/lib/common.sh b/src/lib/common.sh index a93e906..9d5622e 100644 --- a/src/lib/common.sh +++ b/src/lib/common.sh @@ -36,9 +36,10 @@ if [[ -t 2 && "$TERM" != dumb ]] || [[ ${DEVTOOLS_COLOR} == always ]]; then colorize PURPLE="$(tput setaf 5)" DARK_GREEN="$(tput setaf 2)" + UNDERLINE="$(tput smul)" else # shellcheck disable=2034 - declare -gr ALL_OFF='' BOLD='' BLUE='' GREEN='' RED='' YELLOW='' PURPLE='' + declare -gr ALL_OFF='' BOLD='' BLUE='' GREEN='' RED='' YELLOW='' PURPLE='' DARK_GREEN='' UNDERLINE='' fi stat_busy() { diff --git a/src/lib/version/check.sh b/src/lib/version/check.sh index 600a346..ddd400d 100644 --- a/src/lib/version/check.sh +++ b/src/lib/version/check.sh @@ -39,6 +39,11 @@ pkgctl_version_check() { local pkgbases=() local path pkgbase upstream_version result + local up_to_date=() + local out_of_date=() + local failure=() + local section_separator='' + while (( $# )); do case $1 in -h|--help) @@ -87,7 +92,8 @@ pkgctl_version_check() { pkgbase=${pkgbase:-$pkgname} if ! result=$(get_upstream_version); then - msg_error "${pkgbase}: ${result}" + result="${BOLD}${pkgbase}${ALL_OFF}: ${result}" + failure+=("${result}") popd >/dev/null continue fi @@ -95,18 +101,49 @@ pkgctl_version_check() { if ! result=$(vercmp "${upstream_version}" "${pkgver}"); then result="${BOLD}${pkgbase}${ALL_OFF}: failed to compare version ${upstream_version} against ${pkgver}" - msg_error "${result}" - + failure+=("${result}") popd >/dev/null continue fi - if (( result > 0 )); then - msg2 "New ${pkgbase} version ${upstream_version} is available upstream" + if (( result == 0 )); then + result="${BOLD}${pkgbase}${ALL_OFF}: current version ${PURPLE}${pkgver}${ALL_OFF} is latest" + up_to_date+=("${result}") + elif (( result < 0 )); then + result="${BOLD}${pkgbase}${ALL_OFF}: current version ${PURPLE}${pkgver}${ALL_OFF} is never than ${DARK_GREEN}${upstream_version}${ALL_OFF}" + up_to_date+=("${result}") + elif (( result > 0 )); then + result="${BOLD}${pkgbase}${ALL_OFF}: upgrade from version ${PURPLE}${pkgver}${ALL_OFF} to ${DARK_GREEN}${upstream_version}${ALL_OFF}" + out_of_date+=("${result}") fi popd >/dev/null done + + if (( ${#failure[@]} > 0 )); then + printf "%sFailure%s\n" "${section_separator}${BOLD}${UNDERLINE}" "${ALL_OFF}" + section_separator=$'\n' + for result in "${failure[@]}"; do + msg_error " ${result}" + done + fi + + if (( ${#out_of_date[@]} > 0 )); then + printf "%sOut-of-date%s\n" "${section_separator}${BOLD}${UNDERLINE}" "${ALL_OFF}" + section_separator=$'\n' + for result in "${out_of_date[@]}"; do + msg_warn " ${result}" + done + fi + + # Show summary when processing multiple packages + if (( ${#pkgbases[@]} > 1 )); then + printf '%s' "${section_separator}" + pkgctl_version_check_summary \ + "${#up_to_date[@]}" \ + "${#out_of_date[@]}" \ + "${#failure[@]}" + fi } get_upstream_version() { @@ -194,3 +231,28 @@ nvchecker_check_error() { printf "%s\n" "${errors[@]}" return 1 } + +pkgctl_version_check_summary() { + local up_to_date_count=$1 + local out_of_date_count=$2 + local failure_count=$3 + + # print nothing if all stats are zero + if (( up_to_date_count == 0 )) && \ + (( out_of_date_count == 0 )) && \ + (( failure_count == 0 )); then + return 0 + fi + + # print summary for all none zero stats + printf "%sSummary%s\n" "${BOLD}${UNDERLINE}" "${ALL_OFF}" + if (( up_to_date_count > 0 )); then + msg_success " Up-to-date: ${BOLD}${up_to_date_count}${ALL_OFF}" 2>&1 + fi + if (( failure_count > 0 )); then + msg_error " Failure: ${BOLD}${failure_count}${ALL_OFF}" 2>&1 + fi + if (( out_of_date_count > 0 )); then + msg_warn " Out-of-date: ${BOLD}${out_of_date_count}${ALL_OFF}" 2>&1 + fi +} diff --git a/src/lib/version/upgrade.sh b/src/lib/version/upgrade.sh index 704431a..26a5ccb 100644 --- a/src/lib/version/upgrade.sh +++ b/src/lib/version/upgrade.sh @@ -40,6 +40,7 @@ _EOF_ pkgctl_version_upgrade() { local path upstream_version result local pkgbases=() + local exit_code=0 while (( $# )); do case $1 in @@ -88,21 +89,90 @@ pkgctl_version_upgrade() { . ./PKGBUILD pkgbase=${pkgbase:-$pkgname} - if ! upstream_version=$(get_upstream_version); then - die "Failed to get latest upstream version for %s" "${pkgbase}" + if ! result=$(get_upstream_version); then + result="${BOLD}${pkgbase}${ALL_OFF}: ${result}" + failure+=("${result}") + popd >/dev/null + continue fi + upstream_version=${result} if ! result=$(vercmp "${upstream_version}" "${pkgver}"); then - die "Failed to compare version %s against %s" "${upstream_version}" "${pkgver}" + result="${BOLD}${pkgbase}${ALL_OFF}: failed to compare version ${upstream_version} against ${pkgver}" + failure+=("${result}") + popd >/dev/null + continue fi - if (( result > 0 )); then - msg_success "${BOLD}${pkgbase}${ALL_OFF}: upgrading from version ${PURPLE}${pkgver}${ALL_OFF} to ${DARK_GREEN}${upstream_version}${ALL_OFF}" - + if (( result == 0 )); then + result="${BOLD}${pkgbase}${ALL_OFF}: current version ${PURPLE}${pkgver}${ALL_OFF} is latest" + up_to_date+=("${result}") + elif (( result < 0 )); then + result="${BOLD}${pkgbase}${ALL_OFF}: current version ${PURPLE}${pkgver}${ALL_OFF} is never than ${DARK_GREEN}${upstream_version}${ALL_OFF}" + up_to_date+=("${result}") + elif (( result > 0 )); then + result="${BOLD}${pkgbase}${ALL_OFF}: upgraded from version ${PURPLE}${pkgver}${ALL_OFF} to ${DARK_GREEN}${upstream_version}${ALL_OFF}" + out_of_date+=("${result}") + + # change the PKGBUILD pkgbuild_set_pkgver "${upstream_version}" pkgbuild_set_pkgrel 1 fi popd >/dev/null done + + if (( ${#failure[@]} > 0 )); then + exit_code=1 + printf "%sFailure%s\n" "${section_separator}${BOLD}${UNDERLINE}" "${ALL_OFF}" + section_separator=$'\n' + for result in "${failure[@]}"; do + msg_error " ${result}" + done + fi + + if (( ${#out_of_date[@]} > 0 )); then + printf "%sUpgraded%s\n" "${section_separator}${BOLD}${UNDERLINE}" "${ALL_OFF}" + section_separator=$'\n' + for result in "${out_of_date[@]}"; do + msg_warn " ${result}" + done + fi + + # Show summary when processing multiple packages + if (( ${#pkgbases[@]} > 1 )); then + printf '%s' "${section_separator}" + pkgctl_version_upgrade_summary \ + "${#up_to_date[@]}" \ + "${#out_of_date[@]}" \ + "${#failure[@]}" + fi + + # return status based on results + return "${exit_code}" +} + +pkgctl_version_upgrade_summary() { + local up_to_date_count=$1 + local out_of_date_count=$2 + local failure_count=$3 + + # print nothing if all stats are zero + if (( up_to_date_count == 0 )) && \ + (( out_of_date_count == 0 )) && \ + (( failure_count == 0 )); then + return 0 + fi + + # print summary for all none zero stats + printf "%sSummary%s\n" "${BOLD}${UNDERLINE}" "${ALL_OFF}" + if (( up_to_date_count > 0 )); then + msg_success " Up-to-date: ${BOLD}${up_to_date_count}${ALL_OFF}" 2>&1 + fi + if (( failure_count > 0 )); then + msg_error " Failure: ${BOLD}${failure_count}${ALL_OFF}" 2>&1 + fi + if (( out_of_date_count > 0 )); then + msg_warn " Upgraded: ${BOLD}${out_of_date_count}${ALL_OFF}" 2>&1 + fi } -- cgit v1.2.3-70-g09d2 From 08ece1640b360d741bd08dc6dc028a42682aa4ed Mon Sep 17 00:00:00 2001 From: Levente Polyak Date: Thu, 18 Jan 2024 02:57:55 +0100 Subject: feat(version): add spinner while checking upstream versions It may take quite some time to check a lot of upstream versions. However, we still want to nicely group the results together. To avoid just showing a static status message it makes much more sense to show a dynamic spinner with a summary of the progress. Component: pkgctl version check Component: pkgctl version upgrade Signed-off-by: Levente Polyak --- src/lib/version/check.sh | 49 +++++++++++++++++++++++++++++++++++++++++++++- src/lib/version/upgrade.sh | 47 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+), 1 deletion(-) (limited to 'src/lib/version') diff --git a/src/lib/version/check.sh b/src/lib/version/check.sh index ddd400d..fba2d1a 100644 --- a/src/lib/version/check.sh +++ b/src/lib/version/check.sh @@ -8,6 +8,8 @@ DEVTOOLS_INCLUDE_VERSION_CHECK_SH=1 _DEVTOOLS_LIBRARY_DIR=${_DEVTOOLS_LIBRARY_DIR:-@pkgdatadir@} # shellcheck source=src/lib/common.sh source "${_DEVTOOLS_LIBRARY_DIR}"/lib/common.sh +# shellcheck source=src/lib/util/term.sh +source "${_DEVTOOLS_LIBRARY_DIR}"/lib/util/term.sh source /usr/share/makepkg/util/message.sh @@ -37,11 +39,12 @@ _EOF_ pkgctl_version_check() { local path local pkgbases=() - local path pkgbase upstream_version result + local status_file path pkgbase upstream_version result local up_to_date=() local out_of_date=() local failure=() + local current_item=0 local section_separator='' while (( $# )); do @@ -78,6 +81,10 @@ pkgctl_version_check() { fi fi + # start a terminal spinner as checking versions takes time + status_dir=$(mktemp --tmpdir="${WORKDIR}" --directory pkgctl-version-check-spinner.XXXXXXXXXX) + term_spinner_start "${status_dir}" + for path in "${pkgbases[@]}"; do pushd "${path}" >/dev/null @@ -85,6 +92,16 @@ pkgctl_version_check() { die "No PKGBUILD found for ${path}" fi + # update the current terminal spinner status + (( ++current_item )) + pkgctl_version_check_spinner \ + "${status_dir}" \ + "${#up_to_date[@]}" \ + "${#out_of_date[@]}" \ + "${#failure[@]}" \ + "${current_item}" \ + "${#pkgbases[@]}" + # reset common PKGBUILD variables unset pkgbase pkgname arch source pkgver pkgrel validpgpkeys # shellcheck source=contrib/makepkg/PKGBUILD.proto @@ -120,6 +137,9 @@ pkgctl_version_check() { popd >/dev/null done + # stop the terminal spinner after all checks + term_spinner_stop "${status_dir}" + if (( ${#failure[@]} > 0 )); then printf "%sFailure%s\n" "${section_separator}${BOLD}${UNDERLINE}" "${ALL_OFF}" section_separator=$'\n' @@ -256,3 +276,30 @@ pkgctl_version_check_summary() { msg_warn " Out-of-date: ${BOLD}${out_of_date_count}${ALL_OFF}" 2>&1 fi } + +pkgctl_version_check_spinner() { + local status_dir=$1 + local up_to_date_count=$2 + local out_of_date_count=$3 + local failure_count=$4 + local current=$5 + local total=$6 + + local percentage=$(( 100 * current / total )) + local tmp_file="${status_dir}/tmp" + local status_file="${status_dir}/status" + + # print the current summary + pkgctl_version_check_summary \ + "${up_to_date_count}" \ + "${out_of_date_count}" \ + "${failure_count}" > "${tmp_file}" + + # print the progress status + printf "📡 Checking: %s/%s [%s] %%spinner%%" \ + "${BOLD}${current}" "${total}" "${percentage}%${ALL_OFF}" \ + >> "${tmp_file}" + + # swap the status file + mv "${tmp_file}" "${status_file}" +} diff --git a/src/lib/version/upgrade.sh b/src/lib/version/upgrade.sh index 26a5ccb..9f884d0 100644 --- a/src/lib/version/upgrade.sh +++ b/src/lib/version/upgrade.sh @@ -12,6 +12,8 @@ source "${_DEVTOOLS_LIBRARY_DIR}"/lib/common.sh source "${_DEVTOOLS_LIBRARY_DIR}"/lib/version/check.sh # shellcheck source=src/lib/util/pkgbuild.sh source "${_DEVTOOLS_LIBRARY_DIR}"/lib/util/pkgbuild.sh +# shellcheck source=src/lib/util/term.sh +source "${_DEVTOOLS_LIBRARY_DIR}"/lib/util/term.sh source /usr/share/makepkg/util/message.sh @@ -41,6 +43,7 @@ pkgctl_version_upgrade() { local path upstream_version result local pkgbases=() local exit_code=0 + local current_item=0 while (( $# )); do case $1 in @@ -76,6 +79,10 @@ pkgctl_version_upgrade() { fi fi + # start a terminal spinner as checking versions takes time + status_dir=$(mktemp --tmpdir="${WORKDIR}" --directory pkgctl-version-check-spinner.XXXXXXXXXX) + term_spinner_start "${status_dir}" + for path in "${pkgbases[@]}"; do pushd "${path}" >/dev/null @@ -83,6 +90,16 @@ pkgctl_version_upgrade() { die "No PKGBUILD found for ${path}" fi + # update the current terminal spinner status + (( ++current_item )) + pkgctl_version_upgrade_spinner \ + "${status_dir}" \ + "${#up_to_date[@]}" \ + "${#out_of_date[@]}" \ + "${#failure[@]}" \ + "${current_item}" \ + "${#pkgbases[@]}" + # reset common PKGBUILD variables unset pkgbase pkgname arch source pkgver pkgrel validpgpkeys # shellcheck source=contrib/makepkg/PKGBUILD.proto @@ -122,6 +139,9 @@ pkgctl_version_upgrade() { popd >/dev/null done + # stop the terminal spinner after all checks + term_spinner_stop "${status_dir}" + if (( ${#failure[@]} > 0 )); then exit_code=1 printf "%sFailure%s\n" "${section_separator}${BOLD}${UNDERLINE}" "${ALL_OFF}" @@ -176,3 +196,30 @@ pkgctl_version_upgrade_summary() { msg_warn " Upgraded: ${BOLD}${out_of_date_count}${ALL_OFF}" 2>&1 fi } + +pkgctl_version_upgrade_spinner() { + local status_dir=$1 + local up_to_date_count=$2 + local out_of_date_count=$3 + local failure_count=$4 + local current=$5 + local total=$6 + + local percentage=$(( 100 * current / total )) + local tmp_file="${status_dir}/tmp" + local status_file="${status_dir}/status" + + # print the current summary + pkgctl_version_upgrade_summary \ + "${up_to_date_count}" \ + "${out_of_date_count}" \ + "${failure_count}" > "${tmp_file}" + + # print the progress status + printf "📡 Upgrading: %s/%s [%s] %%spinner%%" \ + "${BOLD}${current}" "${total}" "${percentage}%${ALL_OFF}" \ + >> "${tmp_file}" + + # swap the status file + mv "${tmp_file}" "${status_file}" +} -- cgit v1.2.3-70-g09d2 From b258bb3b7c55d06bad108400450acd32cff05366 Mon Sep 17 00:00:00 2001 From: Levente Polyak Date: Thu, 18 Jan 2024 03:33:13 +0100 Subject: feat(version): add verbose option to display up-to-date versions Sometimes it can be desired to get a results for each entry even if the current version is up-to-date. Add a --verbose option to print this optional detail. Component: pkgctl version check Component: pkgctl version upgrade Signed-off-by: Levente Polyak --- contrib/completion/bash/devtools.in | 2 ++ contrib/completion/zsh/_devtools.in | 2 ++ doc/man/pkgctl-version-check.1.asciidoc | 3 +++ doc/man/pkgctl-version-upgrade.1.asciidoc | 3 +++ src/lib/version/check.sh | 25 ++++++++++++++++++++++--- src/lib/version/upgrade.sh | 21 ++++++++++++++++++++- 6 files changed, 52 insertions(+), 4 deletions(-) (limited to 'src/lib/version') diff --git a/contrib/completion/bash/devtools.in b/contrib/completion/bash/devtools.in index 101bd78..f8b1c9f 100644 --- a/contrib/completion/bash/devtools.in +++ b/contrib/completion/bash/devtools.in @@ -343,12 +343,14 @@ _pkgctl_version_cmds=( ) _pkgctl_version_check_args=( + -v --verbose -h --help ) _pkgctl_version_check_opts() { _filedir -d; } _pkgctl_version_upgrade_args=( + -v --verbose -h --help ) diff --git a/contrib/completion/zsh/_devtools.in b/contrib/completion/zsh/_devtools.in index 38bf582..b427d20 100644 --- a/contrib/completion/zsh/_devtools.in +++ b/contrib/completion/zsh/_devtools.in @@ -292,11 +292,13 @@ _pkgctl_version_cmds=( ) _pkgctl_version_check_args=( + '(-v --verbose)'{-v,--verbose}'[Display results including up-to-date versions]' '(-h --help)'{-h,--help}'[Display usage]' '*:git_dir:_files -/' ) _pkgctl_version_upgrade_args=( + '(-v --verbose)'{-v,--verbose}'[Display results including up-to-date versions]' '(-h --help)'{-h,--help}'[Display usage]' '*:git_dir:_files -/' ) diff --git a/doc/man/pkgctl-version-check.1.asciidoc b/doc/man/pkgctl-version-check.1.asciidoc index ed9abdf..3113afa 100644 --- a/doc/man/pkgctl-version-check.1.asciidoc +++ b/doc/man/pkgctl-version-check.1.asciidoc @@ -30,6 +30,9 @@ which can be utilized in .nvchecker.toml. Options ------- +*-v, --verbose*:: + Display results including up-to-date versions + *-h, --help*:: Show a help text diff --git a/doc/man/pkgctl-version-upgrade.1.asciidoc b/doc/man/pkgctl-version-upgrade.1.asciidoc index 3d5d882..7f9cd96 100644 --- a/doc/man/pkgctl-version-upgrade.1.asciidoc +++ b/doc/man/pkgctl-version-upgrade.1.asciidoc @@ -22,6 +22,9 @@ The current working directory is used if no PKGBASE is specified. Options ------- +*-v, --verbose*:: + Display results including up-to-date versions + *-h, --help*:: Show a help text diff --git a/src/lib/version/check.sh b/src/lib/version/check.sh index fba2d1a..9bc29c1 100644 --- a/src/lib/version/check.sh +++ b/src/lib/version/check.sh @@ -29,7 +29,8 @@ pkgctl_version_check_usage() { will be supplied from \${XDG_CONFIG_HOME}/nvchecker. OPTIONS - -h, --help Show this help text + -v, --verbose Display results including up-to-date versions + -h, --help Show this help text EXAMPLES $ ${COMMAND} neovim vim @@ -37,9 +38,10 @@ _EOF_ } pkgctl_version_check() { - local path local pkgbases=() - local status_file path pkgbase upstream_version result + local verbose=0 + + local path status_file path pkgbase upstream_version result local up_to_date=() local out_of_date=() @@ -53,6 +55,10 @@ pkgctl_version_check() { pkgctl_version_check_usage exit 0 ;; + -v|--verbose) + verbose=1 + shift + ;; --) shift break @@ -81,6 +87,11 @@ pkgctl_version_check() { fi fi + # enable verbose mode when we only have a single item to check + if (( ${#pkgbases[@]} == 1 )); then + verbose=1 + fi + # start a terminal spinner as checking versions takes time status_dir=$(mktemp --tmpdir="${WORKDIR}" --directory pkgctl-version-check-spinner.XXXXXXXXXX) term_spinner_start "${status_dir}" @@ -140,6 +151,14 @@ pkgctl_version_check() { # stop the terminal spinner after all checks term_spinner_stop "${status_dir}" + if (( verbose )) && (( ${#up_to_date[@]} > 0 )); then + printf "%sUp-to-date%s\n" "${section_separator}${BOLD}${UNDERLINE}" "${ALL_OFF}" + section_separator=$'\n' + for result in "${up_to_date[@]}"; do + msg_success " ${result}" + done + fi + if (( ${#failure[@]} > 0 )); then printf "%sFailure%s\n" "${section_separator}${BOLD}${UNDERLINE}" "${ALL_OFF}" section_separator=$'\n' diff --git a/src/lib/version/upgrade.sh b/src/lib/version/upgrade.sh index 9f884d0..70513ce 100644 --- a/src/lib/version/upgrade.sh +++ b/src/lib/version/upgrade.sh @@ -32,7 +32,8 @@ pkgctl_version_upgrade_usage() { The current working directory is used if no PKGBASE is specified. OPTIONS - -h, --help Show this help text + -v, --verbose Display results including up-to-date versions + -h, --help Show this help text EXAMPLES $ ${COMMAND} neovim vim @@ -42,6 +43,7 @@ _EOF_ pkgctl_version_upgrade() { local path upstream_version result local pkgbases=() + local verbose=0 local exit_code=0 local current_item=0 @@ -51,6 +53,10 @@ pkgctl_version_upgrade() { pkgctl_version_upgrade_usage exit 0 ;; + -v|--verbose) + verbose=1 + shift + ;; --) shift break @@ -79,6 +85,11 @@ pkgctl_version_upgrade() { fi fi + # enable verbose mode when we only have a single item to check + if (( ${#pkgbases[@]} == 1 )); then + verbose=1 + fi + # start a terminal spinner as checking versions takes time status_dir=$(mktemp --tmpdir="${WORKDIR}" --directory pkgctl-version-check-spinner.XXXXXXXXXX) term_spinner_start "${status_dir}" @@ -142,6 +153,14 @@ pkgctl_version_upgrade() { # stop the terminal spinner after all checks term_spinner_stop "${status_dir}" + if (( verbose )) && (( ${#up_to_date[@]} > 0 )); then + printf "%sUp-to-date%s\n" "${section_separator}${BOLD}${UNDERLINE}" "${ALL_OFF}" + section_separator=$'\n' + for result in "${up_to_date[@]}"; do + msg_success " ${result}" + done + fi + if (( ${#failure[@]} > 0 )); then exit_code=1 printf "%sFailure%s\n" "${section_separator}${BOLD}${UNDERLINE}" "${ALL_OFF}" -- cgit v1.2.3-70-g09d2 From e3edf25554c78e28679b100e24c55c87ee65a22d Mon Sep 17 00:00:00 2001 From: Levente Polyak Date: Thu, 18 Jan 2024 19:15:22 +0100 Subject: feat(version): use exit code for check to indicate out-of-date versions It can be handy to have an exit code that allows better status indication or chaining. On exit, return one of the following codes: - 0: Normal exit condition, all checked versions are up-to-date - 1: Unknown cause of failure - 2: Normal exit condition, but there are out-of-date versions - 3: Failed to run some version checks Component: pkgctl version check Signed-off-by: Levente Polyak --- doc/man/pkgctl-version-check.1.asciidoc | 17 +++++++++++++++++ src/lib/version.sh | 4 ++-- src/lib/version/check.sh | 14 ++++++++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) (limited to 'src/lib/version') diff --git a/doc/man/pkgctl-version-check.1.asciidoc b/doc/man/pkgctl-version-check.1.asciidoc index 3113afa..fa5401f 100644 --- a/doc/man/pkgctl-version-check.1.asciidoc +++ b/doc/man/pkgctl-version-check.1.asciidoc @@ -36,6 +36,23 @@ Options *-h, --help*:: Show a help text +Errors +------ + +On exit, return one of the following codes: + +*0*:: + Normal exit condition, all checked versions are up-to-date + +*1*:: + Unknown cause of failure + +*2*:: + Normal exit condition, but there are out-of-date versions + +*3*:: + Failed to run some version checks + See Also -------- diff --git a/src/lib/version.sh b/src/lib/version.sh index 14cd810..4340fca 100644 --- a/src/lib/version.sh +++ b/src/lib/version.sh @@ -47,7 +47,7 @@ pkgctl_version() { # shellcheck source=src/lib/version/check.sh source "${_DEVTOOLS_LIBRARY_DIR}"/lib/version/check.sh pkgctl_version_check "$@" - exit 0 + exit $? ;; upgrade) _DEVTOOLS_COMMAND+=" $1" @@ -55,7 +55,7 @@ pkgctl_version() { # shellcheck source=src/lib/version/upgrade.sh source "${_DEVTOOLS_LIBRARY_DIR}"/lib/version/upgrade.sh pkgctl_version_upgrade "$@" - exit 0 + exit $? ;; *) die "invalid argument: %s" "$1" diff --git a/src/lib/version/check.sh b/src/lib/version/check.sh index 9bc29c1..cc8827d 100644 --- a/src/lib/version/check.sh +++ b/src/lib/version/check.sh @@ -15,6 +15,14 @@ source /usr/share/makepkg/util/message.sh set -eo pipefail +readonly PKGCTL_VERSION_CHECK_EXIT_UP_TO_DATE=0 +export PKGCTL_VERSION_CHECK_EXIT_UP_TO_DATE +readonly PKGCTL_VERSION_CHECK_EXIT_OUT_OF_DATE=2 +export PKGCTL_VERSION_CHECK_EXIT_OUT_OF_DATE +readonly PKGCTL_VERSION_CHECK_EXIT_FAILURE=3 +export PKGCTL_VERSION_CHECK_EXIT_FAILURE + + pkgctl_version_check_usage() { local -r COMMAND=${_DEVTOOLS_COMMAND:-${BASH_SOURCE[0]##*/}} cat <<- _EOF_ @@ -48,6 +56,7 @@ pkgctl_version_check() { local failure=() local current_item=0 local section_separator='' + local exit_code=${PKGCTL_VERSION_CHECK_EXIT_UP_TO_DATE} while (( $# )); do case $1 in @@ -160,6 +169,7 @@ pkgctl_version_check() { fi if (( ${#failure[@]} > 0 )); then + exit_code=${PKGCTL_VERSION_CHECK_EXIT_FAILURE} printf "%sFailure%s\n" "${section_separator}${BOLD}${UNDERLINE}" "${ALL_OFF}" section_separator=$'\n' for result in "${failure[@]}"; do @@ -168,6 +178,7 @@ pkgctl_version_check() { fi if (( ${#out_of_date[@]} > 0 )); then + exit_code=${PKGCTL_VERSION_CHECK_EXIT_OUT_OF_DATE} printf "%sOut-of-date%s\n" "${section_separator}${BOLD}${UNDERLINE}" "${ALL_OFF}" section_separator=$'\n' for result in "${out_of_date[@]}"; do @@ -183,6 +194,9 @@ pkgctl_version_check() { "${#out_of_date[@]}" \ "${#failure[@]}" fi + + # return status based on results + return "${exit_code}" } get_upstream_version() { -- cgit v1.2.3-70-g09d2 From 4d72f4560c3a64b38dcdb705ec633c3c2ba1f20c Mon Sep 17 00:00:00 2001 From: Levente Polyak Date: Fri, 19 Jan 2024 01:57:18 +0100 Subject: doc(version): extensively revamp documentation for version subcommands Enhanced and overhauled the documentation for the 'version' subcommand. The improvements include comprehensive details on the subcommand's behavior, usage, and a variety of scenarios it handles. Added a central section within the pkgctl-version manpage that documents the nvchecker configuration and rules. Component: pkgctl version Singled-off-by: Levente Polyak --- contrib/completion/zsh/_devtools.in | 6 +++--- doc/man/pkgctl-version-check.1.asciidoc | 29 +++++++++++++++++------------ doc/man/pkgctl-version-upgrade.1.asciidoc | 24 +++++++++++++++++++----- doc/man/pkgctl-version.1.asciidoc | 29 +++++++++++++++++++++++++---- doc/man/pkgctl.1.asciidoc | 2 +- src/lib/version.sh | 6 +++--- src/lib/version/check.sh | 12 +++++++----- src/lib/version/upgrade.sh | 12 ++++++++---- src/pkgctl.in | 2 +- 9 files changed, 84 insertions(+), 38 deletions(-) (limited to 'src/lib/version') diff --git a/contrib/completion/zsh/_devtools.in b/contrib/completion/zsh/_devtools.in index b427d20..34f90c6 100644 --- a/contrib/completion/zsh/_devtools.in +++ b/contrib/completion/zsh/_devtools.in @@ -277,7 +277,7 @@ _pkgctl_cmds=( "release[Release step to commit, tag and upload build artifacts]" "repo[Manage Git packaging repositories and their configuration]" "search[Search for an expression across the GitLab packaging group]" - "version[Package version related commands]" + "version[Check and manage package versions against upstream]" ) _pkgctl_args=( @@ -287,8 +287,8 @@ _pkgctl_args=( _pkgctl_version_cmds=( "pkgctl version command" - "check[Check if there is an new upstream version available]" - "upgrade[Upgrade the PKGBUILD according to the latest available upstream version]" + "check[Compares local package versions against upstream versions]" + "upgrade[Adjust the PKGBUILD to match the latest upstream version]" ) _pkgctl_version_check_args=( diff --git a/doc/man/pkgctl-version-check.1.asciidoc b/doc/man/pkgctl-version-check.1.asciidoc index fa5401f..2543bcb 100644 --- a/doc/man/pkgctl-version-check.1.asciidoc +++ b/doc/man/pkgctl-version-check.1.asciidoc @@ -3,7 +3,7 @@ pkgctl-version-check(1) Name ---- -pkgctl-version-check - Check if there is an new upstream version available +pkgctl-version-check - Compares local package versions against upstream Synopsis -------- @@ -12,20 +12,24 @@ pkgctl version check [OPTIONS] [PKGBASE...] Description ----------- -Uses nvchecker, a .nvchecker.toml file and the version specified in the current -PKGBUILDs pkgver to check if there is a newer package version available to -which this package could possibly be upgraded. +Compares the versions of packages in the local packaging repository against +their latest upstream versions. -The current working directory is used if no PKGBASE is specified. +Upon execution, it generates a grouped list that provides detailed insights +into each package's status. For each package, it displays the current local +version alongside the latest version available upstream. + +Outputs a summary of up-to-date packages, out-of-date packages, and any check +failures. + +This simplifies the maintenance of PKGBUILD files, reducing the manual effort +required to track version changes from upstream sources. Configuration ------------- -To provide GitHub or GitLab tokens to nvchecker, a `keyfile.toml` will be -supplied from `$XDG_CONFIG_HOME`/nvchecker. - -See the section on configuration files in linkman:nvchecker[1] for possible options -which can be utilized in .nvchecker.toml. +Uses linkman:nvchecker[1] and a `.nvchecker.toml` file located alongside the +PKGBUILD. Refer to the configuration section in linkman:pkgctl-version[1]. Options ------- @@ -36,8 +40,8 @@ Options *-h, --help*:: Show a help text -Errors ------- +Exit Codes +---------- On exit, return one of the following codes: @@ -56,6 +60,7 @@ On exit, return one of the following codes: See Also -------- +linkman:pkgctl-version[1] linkman:nvchecker[1] include::include/footer.asciidoc[] diff --git a/doc/man/pkgctl-version-upgrade.1.asciidoc b/doc/man/pkgctl-version-upgrade.1.asciidoc index 7f9cd96..68e6369 100644 --- a/doc/man/pkgctl-version-upgrade.1.asciidoc +++ b/doc/man/pkgctl-version-upgrade.1.asciidoc @@ -3,7 +3,7 @@ pkgctl-version-upgrade(1) Name ---- -pkgctl-version-upgrade - Upgrade the PKGBUILD according to the latest available upstream version +pkgctl-version-upgrade - Adjust the PKGBUILD to match the latest upstream version Synopsis -------- @@ -12,12 +12,25 @@ pkgctl version upgrade [OPTIONS] [PKGBASE...] Description ----------- -Upgrade the PKGBUILD according to the latest available upstream version. +Streamlines the process of keeping PKGBUILD files up-to-date with the latest +upstream versions. -Uses nvchecker, a .nvchecker.toml file and the current PKGBUILD pkgver to check -if there is a newer package version available. +Upon execution, it automatically adjusts the PKGBUILD file, ensuring that the +pkgver field is set to match the latest version available from the upstream +source. In addition to updating the pkgver, this command also resets the pkgrel +to 1. -The current working directory is used if no PKGBASE is specified. +Outputs a summary of upgraded packages, up-to-date packages, and any check +failures. + +This simplifies the maintenance of PKGBUILD files, reducing the manual effort +required to track and implement version changes from upstream sources. + +Configuration +------------- + +Uses linkman:nvchecker[1] and a `.nvchecker.toml` file located alongside the +PKGBUILD. Refer to the configuration section in linkman:pkgctl-version[1]. Options ------- @@ -31,6 +44,7 @@ Options See Also -------- +linkman:pkgctl-version[1] linkman:nvchecker[1] include::include/footer.asciidoc[] diff --git a/doc/man/pkgctl-version.1.asciidoc b/doc/man/pkgctl-version.1.asciidoc index e71becd..fa83314 100644 --- a/doc/man/pkgctl-version.1.asciidoc +++ b/doc/man/pkgctl-version.1.asciidoc @@ -3,7 +3,7 @@ pkgctl-version(1) Name ---- -pkgctl-version - Package version related commands. +pkgctl-version - Check and manage package versions against upstream Synopsis @@ -13,7 +13,28 @@ pkgctl version [OPTIONS] [SUBCOMMAND] Description ----------- -Package version related commands such as checking if a package is out of date. +Commands related to package versions, including checks for outdated packages. + +Uses linkman:nvchecker[1] and a `.nvchecker.toml` file located alongside the +PKGBUILD. + +Configuration +------------- + +The `.nvchecker.toml` file must contain a section that matches the +package's pkgbase. The pkgbase section within the `.nvchecker.toml` file +specifies the source and method for checking the latest version of the +corresponding package. + +For detailed information on the various configuration options available for the +`.nvchecker.toml` file, refer to the configuration files section in +linkman:nvchecker[1]. This documentation provides insights into the possible +options that can be utilized to customize the version checking process. + +To supply GitHub or GitLab tokens to nvchecker, a `keyfile.toml` should be +placed in the `$XDG_CONFIG_HOME`/nvchecker` directory. This keyfile is +used for providing the necessary authentication tokens required for +accessing the GitHub or GitLab API. Options ------- @@ -25,10 +46,10 @@ Subcommands ----------- pkgctl version check:: - Check if there is an new upstream version available + Compares local package versions against upstream pkgctl version upgrade:: - Upgrade the PKGBUILD according to the latest available upstream version + Adjust the PKGBUILD to match the latest upstream version See Also -------- diff --git a/doc/man/pkgctl.1.asciidoc b/doc/man/pkgctl.1.asciidoc index 929ae9a..d9a1d8c 100644 --- a/doc/man/pkgctl.1.asciidoc +++ b/doc/man/pkgctl.1.asciidoc @@ -51,7 +51,7 @@ pkgctl search:: Search for an expression across the GitLab packaging group pkgctl version:: - Package version related commands + Check and manage package versions against upstream See Also -------- diff --git a/src/lib/version.sh b/src/lib/version.sh index 4340fca..ac810ae 100644 --- a/src/lib/version.sh +++ b/src/lib/version.sh @@ -15,11 +15,11 @@ pkgctl_version_usage() { cat <<- _EOF_ Usage: ${COMMAND} [COMMAND] [OPTIONS] - Package version related commands. + Check and manage package versions against upstream. COMMANDS - check Check if there is a newer version availble - upgrade Upgrade the PKGBUILD according to the latest available upstream version + check Compares local package versions against upstream + upgrade Adjust the PKGBUILD to match the latest upstream version OPTIONS -h, --help Show this help text diff --git a/src/lib/version/check.sh b/src/lib/version/check.sh index cc8827d..006fd80 100644 --- a/src/lib/version/check.sh +++ b/src/lib/version/check.sh @@ -28,13 +28,15 @@ pkgctl_version_check_usage() { cat <<- _EOF_ Usage: ${COMMAND} [OPTIONS] [PKGBASE]... - Uses nvchecker, a .nvchecker.toml file and the current PKGBUILD - pkgver to check if there is a newer package version available. + Compares the versions of packages in the local packaging repository against + their latest upstream versions. - The current working directory is used if no PKGBASE is specified. + Upon execution, it generates a grouped list that provides detailed insights + into each package's status. For each package, it displays the current local + version alongside the latest version available upstream. - To provide GitHub or GitLab tokens to nvchecker, a keyfile.toml - will be supplied from \${XDG_CONFIG_HOME}/nvchecker. + Outputs a summary of up-to-date packages, out-of-date packages, and any + check failures. OPTIONS -v, --verbose Display results including up-to-date versions diff --git a/src/lib/version/upgrade.sh b/src/lib/version/upgrade.sh index 70513ce..87744b0 100644 --- a/src/lib/version/upgrade.sh +++ b/src/lib/version/upgrade.sh @@ -24,12 +24,16 @@ pkgctl_version_upgrade_usage() { cat <<- _EOF_ Usage: ${COMMAND} [OPTIONS] [PKGBASE]... - Upgrade the PKGBUILD according to the latest available upstream version + Streamlines the process of keeping PKGBUILD files up-to-date with the latest + upstream versions. - Uses nvchecker, a .nvchecker.toml file and the current PKGBUILD - pkgver to check if there is a newer package version available. + Upon execution, it automatically adjusts the PKGBUILD file, ensuring that the + pkgver field is set to match the latest version available from the upstream + source. In addition to updating the pkgver, this command also resets the pkgrel + to 1. - The current working directory is used if no PKGBASE is specified. + Outputs a summary of upgraded packages, up-to-date packages, and any check + failures. OPTIONS -v, --verbose Display results including up-to-date versions diff --git a/src/pkgctl.in b/src/pkgctl.in index 9deb4b2..50c14b5 100644 --- a/src/pkgctl.in +++ b/src/pkgctl.in @@ -27,7 +27,7 @@ usage() { release Release step to commit, tag and upload build artifacts repo Manage Git packaging repositories and their configuration search Search for an expression across the GitLab packaging group - version Package version related commands + version Check and manage package versions against upstream OPTIONS -h, --help Show this help text -- cgit v1.2.3-70-g09d2 From 800cf9b56b64f9954852f55fea408786cd5aaaa0 Mon Sep 17 00:00:00 2001 From: Jelle van der Waa Date: Sun, 4 Feb 2024 11:27:02 +0100 Subject: fix(version): fix typo never should be newer Component: pkgctl version check Component: pkgctl version update --- src/lib/version/check.sh | 2 +- src/lib/version/upgrade.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/lib/version') diff --git a/src/lib/version/check.sh b/src/lib/version/check.sh index 006fd80..4731545 100644 --- a/src/lib/version/check.sh +++ b/src/lib/version/check.sh @@ -149,7 +149,7 @@ pkgctl_version_check() { result="${BOLD}${pkgbase}${ALL_OFF}: current version ${PURPLE}${pkgver}${ALL_OFF} is latest" up_to_date+=("${result}") elif (( result < 0 )); then - result="${BOLD}${pkgbase}${ALL_OFF}: current version ${PURPLE}${pkgver}${ALL_OFF} is never than ${DARK_GREEN}${upstream_version}${ALL_OFF}" + result="${BOLD}${pkgbase}${ALL_OFF}: current version ${PURPLE}${pkgver}${ALL_OFF} is newer than ${DARK_GREEN}${upstream_version}${ALL_OFF}" up_to_date+=("${result}") elif (( result > 0 )); then result="${BOLD}${pkgbase}${ALL_OFF}: upgrade from version ${PURPLE}${pkgver}${ALL_OFF} to ${DARK_GREEN}${upstream_version}${ALL_OFF}" diff --git a/src/lib/version/upgrade.sh b/src/lib/version/upgrade.sh index 87744b0..e217532 100644 --- a/src/lib/version/upgrade.sh +++ b/src/lib/version/upgrade.sh @@ -140,7 +140,7 @@ pkgctl_version_upgrade() { result="${BOLD}${pkgbase}${ALL_OFF}: current version ${PURPLE}${pkgver}${ALL_OFF} is latest" up_to_date+=("${result}") elif (( result < 0 )); then - result="${BOLD}${pkgbase}${ALL_OFF}: current version ${PURPLE}${pkgver}${ALL_OFF} is never than ${DARK_GREEN}${upstream_version}${ALL_OFF}" + result="${BOLD}${pkgbase}${ALL_OFF}: current version ${PURPLE}${pkgver}${ALL_OFF} is newer than ${DARK_GREEN}${upstream_version}${ALL_OFF}" up_to_date+=("${result}") elif (( result > 0 )); then result="${BOLD}${pkgbase}${ALL_OFF}: upgraded from version ${PURPLE}${pkgver}${ALL_OFF} to ${DARK_GREEN}${upstream_version}${ALL_OFF}" -- cgit v1.2.3-70-g09d2 From a7a2f25fb092f30bb8c31ed45a60ffcf44b34932 Mon Sep 17 00:00:00 2001 From: Carl Smedstad Date: Mon, 5 Feb 2024 11:43:33 +0100 Subject: fix(version): Handle pkgbase with '.' correctly MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For pkgbases with '.' in the name, the TOML-section must be wrapped in double quotes in order for it not to be parsed as a supersection and a subsection. This case was not properly handled by checks for if the TOML-file contains a pkgbase section, and for if the TOML-file contains superfluous sections. Address this by handling optional double quotes in the greps related to said checks. This was discovered in the AUR package ruby-cool.io and the issue can be reproduced with the following minimal PKGBUILD and .nvchecker.toml file: $ cat PKGBUILD pkgname=ruby-cool.io pkgver=1.8.0 $ cat .nvchecker.toml ["ruby-cool.io"] source = "gems" gems = "cool.io" Before the fix: $ pkgctl version check Failure x ruby-cool.io: missing pkgbase section in .nvchecker.toml: ruby-cool.io After the fix: $ pkgctl version check GEN lib/version/check.sh Out-of-date ✓ ruby-cool.io: current version 1.8.0 is latest Component: pkgctl version check --- src/lib/version/check.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/lib/version') diff --git a/src/lib/version/check.sh b/src/lib/version/check.sh index 4731545..6aa465c 100644 --- a/src/lib/version/check.sh +++ b/src/lib/version/check.sh @@ -260,13 +260,13 @@ nvchecker_check_config() { done # check if the config contains a pkgbase section - if [[ -n ${pkgbase} ]] && ! grep --max-count=1 --quiet "^\\[${pkgbase}\\]" < "${config}"; then + if [[ -n ${pkgbase} ]] && ! grep --max-count=1 --extended-regexp --quiet "^\\[\"?${pkgbase}\"?\\]" < "${config}"; then printf "missing pkgbase section in %s: %s" "${config}" "${pkgbase}" return 1 fi # check if the config contains any section other than pkgbase - if [[ -n ${pkgbase} ]] && property=$(grep --max-count=1 --perl-regexp "^\\[(?!${pkgbase}\\]).+\\]" < "${config}"); then + if [[ -n ${pkgbase} ]] && property=$(grep --max-count=1 --perl-regexp "^\\[(?!\"?${pkgbase}\"?\\]).+\\]" < "${config}"); then printf "none pkgbase section not supported in %s: %s" "${config}" "${property}" return 1 fi -- cgit v1.2.3-70-g09d2 From eabb1a9313a83baa5789992004dba3eb28efd070 Mon Sep 17 00:00:00 2001 From: Carl Smedstad Date: Mon, 5 Feb 2024 11:44:51 +0100 Subject: fix(doc): Correct typo in version check error message Change 'none pkgbase' to 'non-pkgbase' as the sentence refers sections that are not the pkgbase section, rather than an empty pkgbase section or something of that sort that could be misconstrued by using the word 'none'. Component: pkgctl version check --- src/lib/version/check.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/lib/version') diff --git a/src/lib/version/check.sh b/src/lib/version/check.sh index 6aa465c..35d07e2 100644 --- a/src/lib/version/check.sh +++ b/src/lib/version/check.sh @@ -267,7 +267,7 @@ nvchecker_check_config() { # check if the config contains any section other than pkgbase if [[ -n ${pkgbase} ]] && property=$(grep --max-count=1 --perl-regexp "^\\[(?!\"?${pkgbase}\"?\\]).+\\]" < "${config}"); then - printf "none pkgbase section not supported in %s: %s" "${config}" "${property}" + printf "non-pkgbase section not supported in %s: %s" "${config}" "${property}" return 1 fi } -- cgit v1.2.3-70-g09d2