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 --- src/lib/version/upgrade.sh | 108 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 src/lib/version/upgrade.sh (limited to 'src/lib/version/upgrade.sh') 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 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/upgrade.sh') 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/upgrade.sh') 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/upgrade.sh') 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 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/upgrade.sh') 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/upgrade.sh') 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