release: command to commit, tag and upload build artifacts
This is a smart and more convenient invocation of the classical commitpkg and archrelease with auto-discovery for target repositories and a shorthand option to directly call db-update.
This commit is contained in:
parent
b9db6160a2
commit
5752488ef1
|
@ -59,6 +59,16 @@ _pkgctl_db_update_args=(
|
|||
'(-h --help)'{-h,--help}'[Display usage]'
|
||||
)
|
||||
|
||||
_pkgctl_release_args=(
|
||||
'(-m --message=)'{-m,--message=}"[Use the given <msg> as the commit message]:message:"
|
||||
'(-r --repo=)'{-r,--repo=}"[Specify a target repository (disables auto-detection)]:repo:($_repos[*])"
|
||||
'(-s --staging)'{-s,--staging}'[Release to the staging counterpart of the auto-detected repo]'
|
||||
'(-t --testing)'{-t,--testing}'[Release to the testing counterpart of the auto-detected repo]'
|
||||
'(-u --db-update)'{-u,--db-update}'[Automatically update the pacman database after uploading]'
|
||||
'(-h --help)'{-h,--help}'[Display usage]'
|
||||
'*:git_dir:_files -/'
|
||||
)
|
||||
|
||||
_pkgctl_repo_cmds=(
|
||||
"pkgctl repo command"
|
||||
"clone[Clone a package repository]"
|
||||
|
@ -205,6 +215,7 @@ _pkgctl_cmds=(
|
|||
"auth[Authenticate with services like GitLab]"
|
||||
"db[Pacman database modification for packge update, move etc]"
|
||||
"diff[Compare package files using different modes]"
|
||||
"release[Release step to commit, tag and upload build artifacts]"
|
||||
"repo[Manage Git packaging repositories and their configuration]"
|
||||
)
|
||||
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
pkgctl-release(1)
|
||||
=================
|
||||
|
||||
Name
|
||||
----
|
||||
pkgctl-release - Release step to commit, tag and upload build artifacts
|
||||
|
||||
Synopsis
|
||||
--------
|
||||
pkgctl release [OPTIONS] [PATH...]
|
||||
|
||||
Description
|
||||
-----------
|
||||
|
||||
Modified version controlled files will first be staged for commit,
|
||||
afterwards a Git tag matching the pkgver will be created and finally
|
||||
all build artifacts will be uploaded.
|
||||
|
||||
By default the target pacman repository will be auto-detected by querying
|
||||
the repo it is currently released in. When initially adding a new package
|
||||
to the repositories, the target repo must be specified manually.
|
||||
|
||||
Options
|
||||
-------
|
||||
|
||||
*-m, --message* 'MSG'::
|
||||
Use the given <msg> as the commit message
|
||||
|
||||
*-r, --repo* 'REPO'::
|
||||
Specify a target repository (disables auto-detection)
|
||||
|
||||
*-s, --staging*::
|
||||
Build against the staging counterpart of the auto-detected repo
|
||||
|
||||
*-t, --testing*::
|
||||
Build against the testing counterpart of the auto-detected repo
|
||||
|
||||
*-u, --db-update*::
|
||||
Automatically update the pacman database after uploading
|
||||
|
||||
*-h, --help*::
|
||||
Show a help text
|
||||
|
||||
See Also
|
||||
--------
|
||||
|
||||
linkman:pkgctl-db-update[1]
|
||||
|
||||
include::include/footer.asciidoc[]
|
|
@ -26,6 +26,9 @@ pkgctl db::
|
|||
pkgctl diff::
|
||||
Compare package files using different modes
|
||||
|
||||
pkgctl release::
|
||||
Release step to commit, tag and upload build artifacts
|
||||
|
||||
pkgctl repo::
|
||||
Manage Git packaging repositories and their configuration
|
||||
|
||||
|
@ -35,6 +38,7 @@ See Also
|
|||
linkman:pkgctl-auth[1]
|
||||
linkman:pkgctl-db[1]
|
||||
linkman:pkgctl-diff[1]
|
||||
linkman:pkgctl-release[1]
|
||||
linkman:pkgctl-repo[1]
|
||||
|
||||
include::include/footer.asciidoc[]
|
||||
|
|
|
@ -0,0 +1,167 @@
|
|||
#!/hint/bash
|
||||
#
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
[[ -z ${DEVTOOLS_INCLUDE_RELEASE_SH:-} ]] || return 0
|
||||
DEVTOOLS_INCLUDE_RELEASE_SH=1
|
||||
|
||||
_DEVTOOLS_LIBRARY_DIR=${_DEVTOOLS_LIBRARY_DIR:-@pkgdatadir@}
|
||||
# shellcheck source=src/lib/db/update.sh
|
||||
source "${_DEVTOOLS_LIBRARY_DIR}"/lib/db/update.sh
|
||||
# shellcheck source=src/lib/util/pacman.sh
|
||||
source "${_DEVTOOLS_LIBRARY_DIR}"/lib/util/pacman.sh
|
||||
# shellcheck source=src/lib/valid-repos.sh
|
||||
source "${_DEVTOOLS_LIBRARY_DIR}"/lib/valid-repos.sh
|
||||
|
||||
source /usr/share/makepkg/util/util.sh
|
||||
|
||||
set -e
|
||||
|
||||
|
||||
pkgctl_release_usage() {
|
||||
local -r COMMAND=${_DEVTOOLS_COMMAND:-${BASH_SOURCE[0]##*/}}
|
||||
cat <<- _EOF_
|
||||
Usage: ${COMMAND} [OPTIONS] [PATH]...
|
||||
|
||||
Release step to commit, tag and upload build artifacts
|
||||
|
||||
Modified version controlled files will first be staged for commit,
|
||||
afterwards a Git tag matching the pkgver will be created and finally
|
||||
all build artifacts will be uploaded.
|
||||
|
||||
By default the target pacman repository will be auto-detected by querying
|
||||
the repo it is currently released in. When initially adding a new package
|
||||
to the repositories, the target repo must be specified manually.
|
||||
|
||||
OPTIONS
|
||||
-m, --message MSG Use the given <msg> as the commit message
|
||||
-r, --repo REPO Specify a target repository (disables auto-detection)
|
||||
-s, --staging Release to the staging counterpart of the auto-detected repo
|
||||
-t, --testing Release to the testing counterpart of the auto-detected repo
|
||||
-u, --db-update Automatically update the pacman database after uploading
|
||||
-h, --help Show this help text
|
||||
|
||||
EXAMPLES
|
||||
$ ${COMMAND}
|
||||
$ ${COMMAND} --repo core-testing --message 'libyay 0.42 rebuild' libfoo libbar
|
||||
$ ${COMMAND} --staging --db-update libfoo
|
||||
_EOF_
|
||||
}
|
||||
|
||||
pkgctl_release_check_option_group() {
|
||||
local option=$1
|
||||
local repo=$2
|
||||
local testing=$3
|
||||
local staging=$4
|
||||
if [[ -n "${repo}" ]] || (( testing )) || (( staging )); then
|
||||
die "The argument '%s' cannot be used with one or more of the other specified arguments" "${option}"
|
||||
exit 1
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
pkgctl_release() {
|
||||
if (( $# < 1 )) && [[ ! -f PKGBUILD ]]; then
|
||||
pkgctl_release_usage
|
||||
exit 1
|
||||
fi
|
||||
|
||||
local MESSAGE=""
|
||||
local PKGBASES=()
|
||||
local REPO=""
|
||||
local TESTING=0
|
||||
local STAGING=0
|
||||
local DB_UPDATE=0
|
||||
|
||||
local path pkgbase pkgnames repo repos
|
||||
|
||||
# option checking
|
||||
while (( $# )); do
|
||||
case $1 in
|
||||
-h|--help)
|
||||
pkgctl_release_usage
|
||||
exit 0
|
||||
;;
|
||||
-m|--message)
|
||||
(( $# <= 1 )) && die "missing argument for %s" "$1"
|
||||
MESSAGE=$2
|
||||
shift 2
|
||||
;;
|
||||
-r|--repo)
|
||||
(( $# <= 1 )) && die "missing argument for %s" "$1"
|
||||
pkgctl_release_check_option_group '--repo' "${REPO}" "${TESTING}" "${STAGING}"
|
||||
REPO=$2
|
||||
shift 2
|
||||
;;
|
||||
-s|--staging)
|
||||
pkgctl_release_check_option_group '--staging' "${REPO}" "${TESTING}" "${STAGING}"
|
||||
STAGING=1
|
||||
shift
|
||||
;;
|
||||
-t|--testing)
|
||||
pkgctl_release_check_option_group '--testing' "${REPO}" "${TESTING}" "${STAGING}"
|
||||
TESTING=1
|
||||
shift
|
||||
;;
|
||||
-u|--db-update)
|
||||
DB_UPDATE=1
|
||||
shift
|
||||
;;
|
||||
-*)
|
||||
die "invalid option: %s" "$1"
|
||||
;;
|
||||
*)
|
||||
PKGBASES+=("$@")
|
||||
break
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Resolve package from current working directory
|
||||
if (( 0 == ${#PKGBASES[@]} )); then
|
||||
PKGBASES=("$PWD")
|
||||
fi
|
||||
|
||||
# Update pacman cache for auto-detection
|
||||
if [[ -z ${REPO} ]]; then
|
||||
update_pacman_repo_cache
|
||||
# Check valid repos if not resolved dynamically
|
||||
elif ! in_array "${REPO}" "${_repos[@]}"; then
|
||||
die "Invalid repository target: %s" "${REPO}"
|
||||
fi
|
||||
|
||||
for path in "${PKGBASES[@]}"; do
|
||||
pushd "${path}" >/dev/null
|
||||
pkgbase=$(basename "${path}")
|
||||
|
||||
if [[ -n ${REPO} ]]; then
|
||||
repo=${REPO}
|
||||
else
|
||||
if ! repo=$(get_pacman_repo_from_pkgbuild PKGBUILD); then
|
||||
die 'Failed to get pacman repo'
|
||||
fi
|
||||
if [[ -z "${repo}" ]]; then
|
||||
die 'Unknown repo, please specify --repo for new packages'
|
||||
fi
|
||||
fi
|
||||
|
||||
if (( TESTING )); then
|
||||
repo="${repo}-testing"
|
||||
elif (( STAGING )); then
|
||||
repo="${repo}-staging"
|
||||
elif [[ $repo == core ]]; then
|
||||
repo="${repo}-testing"
|
||||
fi
|
||||
|
||||
msg "Releasing ${pkgbase} to ${repo}"
|
||||
commitpkg "${repo}" "${MESSAGE}"
|
||||
|
||||
unset repo
|
||||
popd >/dev/null
|
||||
done
|
||||
|
||||
if (( DB_UPDATE )); then
|
||||
# shellcheck disable=2119
|
||||
pkgctl_db_update
|
||||
fi
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
#!/hint/bash
|
||||
#
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
[[ -z ${DEVTOOLS_INCLUDE_UTIL_PACMAN_SH:-} ]] || return 0
|
||||
DEVTOOLS_INCLUDE_UTIL_PACMAN_SH=1
|
||||
|
||||
_DEVTOOLS_LIBRARY_DIR=${_DEVTOOLS_LIBRARY_DIR:-@pkgdatadir@}
|
||||
# shellcheck source=src/lib/common.sh
|
||||
source "${_DEVTOOLS_LIBRARY_DIR}"/lib/common.sh
|
||||
|
||||
set -e
|
||||
|
||||
|
||||
readonly _DEVTOOLS_PACMAN_CACHE_DIR=${XDG_CACHE_DIR:-$HOME/.cache}/devtools/pacman/db
|
||||
readonly _DEVTOOLS_PACMAN_CONF_DIR=${_DEVTOOLS_LIBRARY_DIR}/pacman.conf.d
|
||||
readonly _DEVTOOLS_MAKEPKG_CONF_DIR=${_DEVTOOLS_LIBRARY_DIR}/makepkg.conf.d
|
||||
|
||||
|
||||
update_pacman_repo_cache() {
|
||||
mkdir -p "${_DEVTOOLS_PACMAN_CACHE_DIR}"
|
||||
msg "Updating pacman database cache"
|
||||
lock 10 "${_DEVTOOLS_PACMAN_CACHE_DIR}.lock" "Locking pacman database cache"
|
||||
fakeroot -- pacman --config "${_DEVTOOLS_PACMAN_CONF_DIR}/multilib.conf" \
|
||||
--dbpath "${_DEVTOOLS_PACMAN_CACHE_DIR}" \
|
||||
-Sy
|
||||
lock_close 10
|
||||
}
|
||||
|
||||
get_pacman_repo_from_pkgbuild() {
|
||||
local path=${1:-PKGBUILD}
|
||||
|
||||
# shellcheck source=contrib/makepkg/PKGBUILD.proto
|
||||
mapfile -t pkgnames < <(source "${path}"; printf "%s\n" "${pkgname[@]}")
|
||||
|
||||
if (( ${#pkgnames[@]} == 0 )); then
|
||||
die 'Failed to get pkgname from %s' "${path}"
|
||||
return
|
||||
fi
|
||||
|
||||
slock 10 "${_DEVTOOLS_PACMAN_CACHE_DIR}.lock" "Locking pacman database cache"
|
||||
mapfile -t repos < <(pacman --config "${_DEVTOOLS_PACMAN_CONF_DIR}/multilib.conf" \
|
||||
--dbpath "${_DEVTOOLS_PACMAN_CACHE_DIR}" \
|
||||
-S \
|
||||
--print \
|
||||
--print-format '%n %r' \
|
||||
"${pkgnames[0]}" | grep -E "^${pkgnames[0]} " | awk '{print $2}'
|
||||
)
|
||||
lock_close 10
|
||||
|
||||
printf "%s" "${repos[0]}"
|
||||
}
|
|
@ -22,6 +22,7 @@ usage() {
|
|||
auth Authenticate with services like GitLab
|
||||
db Pacman database modification for packge update, move etc
|
||||
diff Compare package files using different modes
|
||||
release Release step to commit, tag and upload build artifacts
|
||||
repo Manage Git packaging repositories and their configuration
|
||||
|
||||
OPTIONS
|
||||
|
@ -75,6 +76,14 @@ while (( $# )); do
|
|||
diffpkg "$@"
|
||||
exit 0
|
||||
;;
|
||||
release)
|
||||
_DEVTOOLS_COMMAND+=" $1"
|
||||
shift
|
||||
# shellcheck source=src/lib/release.sh
|
||||
source "${_DEVTOOLS_LIBRARY_DIR}"/lib/release.sh
|
||||
pkgctl_release "$@"
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
die "invalid command: %s" "$1"
|
||||
;;
|
||||
|
|
Loading…
Reference in New Issue