tests
This commit is contained in:
Executable
+178
@@ -0,0 +1,178 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# bats-core git releaser
|
||||
#
|
||||
## Usage: %SCRIPT_NAME% [options]
|
||||
##
|
||||
## Options:
|
||||
## --major Major version bump
|
||||
## --minor Minor version bump
|
||||
## --patch Patch version bump
|
||||
##
|
||||
## -v, --version Print version
|
||||
## --debug Enable debug mode
|
||||
## -h, --help Display this message
|
||||
##
|
||||
|
||||
set -Eeuo pipefail
|
||||
|
||||
DIR=$(cd "$(dirname "${0}")" && pwd)
|
||||
THIS_SCRIPT="${DIR}/$(basename "${0}")"
|
||||
BATS_VERSION=$(
|
||||
# shellcheck disable=SC1090
|
||||
source <(grep '^export BATS_VERSION=' libexec/bats-core/bats)
|
||||
echo "${BATS_VERSION}"
|
||||
)
|
||||
declare -r DIR
|
||||
declare -r THIS_SCRIPT
|
||||
declare -r BATS_VERSION
|
||||
|
||||
BUMP_INTERVAL=""
|
||||
NEW_BATS_VERSION=""
|
||||
|
||||
main() {
|
||||
handle_arguments "${@}"
|
||||
|
||||
if [[ "${BUMP_INTERVAL:-}" == "" ]]; then
|
||||
echo "${BATS_VERSION}"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
local NEW_BATS_VERSION
|
||||
NEW_BATS_VERSION=$(semver bump "${BUMP_INTERVAL}" "${BATS_VERSION}")
|
||||
declare -r NEW_BATS_VERSION
|
||||
|
||||
local BATS_RELEASE_NOTES="/tmp/bats-release-${NEW_BATS_VERSION}"
|
||||
|
||||
echo "Releasing: ${BATS_VERSION} to ${NEW_BATS_VERSION}"
|
||||
echo
|
||||
|
||||
echo "Ensure docs/CHANGELOG.md is correctly updated"
|
||||
|
||||
replace_in_files
|
||||
|
||||
write_changelog
|
||||
|
||||
git diff --staged
|
||||
|
||||
cat <<EOF
|
||||
1. Version numbers have been updated. Commit the changes:
|
||||
|
||||
git commit -m "feat: release Bats v${NEW_BATS_VERSION}"
|
||||
|
||||
2. Verify this autogenerated changelog (from docs/CHANGELOG.md):
|
||||
|
||||
# changelog start
|
||||
EOF
|
||||
|
||||
local DELIM
|
||||
DELIM=$(echo -en "\001")
|
||||
sed -E -n "\\${DELIM}^## \[${NEW_BATS_VERSION}\]${DELIM},\\${DELIM}^## ${DELIM}p" docs/CHANGELOG.md |
|
||||
head -n -1 |
|
||||
sed -E \
|
||||
-e 's,^## \[([0-9\.]+)] - (.*),Bats \1\n\nReleased: \2,' \
|
||||
-e 's,^### (.*),\1:,g' |
|
||||
tee "${BATS_RELEASE_NOTES}"
|
||||
|
||||
cat <<EOF
|
||||
# changelog end
|
||||
|
||||
3. Tag the release using the autogenerated changelog:
|
||||
|
||||
git tag -a -s "v${NEW_BATS_VERSION}" --message "${BATS_RELEASE_NOTES}"
|
||||
|
||||
4. Push the changes:
|
||||
|
||||
git push --follow-tags
|
||||
|
||||
5. Use GitHub hub to make a draft release:
|
||||
|
||||
hub release create "v${NEW_BATS_VERSION}" --draft --file "${BATS_RELEASE_NOTES}"
|
||||
|
||||
6. Navigate to the provided URL, verify changes, and release Bats ${NEW_BATS_VERSION}.
|
||||
EOF
|
||||
|
||||
exit 0
|
||||
}
|
||||
|
||||
replace_in_files() {
|
||||
declare -a FILE_REPLACEMENTS=(
|
||||
"contrib/rpm/bats.spec,^Version:"
|
||||
"libexec/bats-core/bats,^export BATS_VERSION="
|
||||
"package.json,^ \"version\":"
|
||||
)
|
||||
|
||||
for FILE_REPLACEMENT in "${FILE_REPLACEMENTS[@]}"; do
|
||||
FILE="${FILE_REPLACEMENT/,*/}"
|
||||
MATCH="${FILE_REPLACEMENT/*,/}"
|
||||
sed -E -i.bak "/${MATCH}/ { s,${BATS_VERSION},${NEW_BATS_VERSION},g; }" "${FILE}"
|
||||
rm "${FILE}.bak" || true
|
||||
git add -f "${FILE}"
|
||||
done
|
||||
}
|
||||
|
||||
write_changelog() {
|
||||
local FILE="docs/CHANGELOG.md"
|
||||
sed -E -i.bak "/## \[Unreleased\]/ a \\\n## [${NEW_BATS_VERSION}] - $(date +%Y-%m-%d)" "${FILE}"
|
||||
|
||||
rm "${FILE}.bak" || true
|
||||
|
||||
cp "${FILE}" "${FILE}.new"
|
||||
sed -E -i.bak '/## \[Unreleased\]/,+1d' "${FILE}"
|
||||
git add -f "${FILE}"
|
||||
mv "${FILE}.new" "${FILE}"
|
||||
}
|
||||
|
||||
handle_arguments() {
|
||||
parse_arguments "${@:-}"
|
||||
}
|
||||
|
||||
parse_arguments() {
|
||||
local CURRENT_ARG
|
||||
|
||||
if [[ "${#}" == 1 && "${1:-}" == "" ]]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
while [[ "${#}" -gt 0 ]]; do
|
||||
CURRENT_ARG="${1}"
|
||||
|
||||
case ${CURRENT_ARG} in
|
||||
--major)
|
||||
BUMP_INTERVAL="major"
|
||||
;;
|
||||
# ---
|
||||
--minor)
|
||||
BUMP_INTERVAL="minor"
|
||||
;;
|
||||
--patch)
|
||||
BUMP_INTERVAL="patch"
|
||||
;;
|
||||
-h | --help) usage ;;
|
||||
-v | --version)
|
||||
get_version
|
||||
exit 0
|
||||
;;
|
||||
--debug)
|
||||
set -xe
|
||||
;;
|
||||
-*) usage "${CURRENT_ARG}: unknown option" ;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
}
|
||||
|
||||
semver() {
|
||||
"${DIR}/semver" "${@:-}"
|
||||
}
|
||||
|
||||
usage() {
|
||||
sed -n '/^##/,/^$/s/^## \{0,1\}//p' "${THIS_SCRIPT}" | sed "s/%SCRIPT_NAME%/$(basename "${THIS_SCRIPT}")/g"
|
||||
exit 2
|
||||
} 2>/dev/null
|
||||
|
||||
get_version() {
|
||||
echo "${THIS_SCRIPT_VERSION:-0.1}"
|
||||
}
|
||||
|
||||
main "${@}"
|
||||
@@ -0,0 +1,66 @@
|
||||
%global provider github.com
|
||||
%global project bats-core
|
||||
%global repo bats-core
|
||||
|
||||
Name: bats
|
||||
Version: 1.11.0
|
||||
Release: 1%{?dist}
|
||||
Summary: Bash Automated Testing System
|
||||
|
||||
Group: Development/Libraries
|
||||
License: MIT
|
||||
URL: https://%{provider}/%{project}/%{repo}
|
||||
Source0: https://%{provider}/%{project}/%{repo}/archive/v%{version}.tar.gz
|
||||
|
||||
BuildArch: noarch
|
||||
|
||||
Requires: bash
|
||||
|
||||
%description
|
||||
Bats is a TAP-compliant testing framework for Bash.
|
||||
It provides a simple way to verify that the UNIX programs you write behave as expected.
|
||||
Bats is most useful when testing software written in Bash, but you can use it to test any UNIX program.
|
||||
|
||||
%prep
|
||||
%setup -q -n %{repo}-%{version}
|
||||
|
||||
%install
|
||||
mkdir -p ${RPM_BUILD_ROOT}%{_prefix} ${RPM_BUILD_ROOT}%{_libexecdir} ${RPM_BUILD_ROOT}%{_mandir}
|
||||
./install.sh ${RPM_BUILD_ROOT}%{_prefix}
|
||||
|
||||
%clean
|
||||
rm -rf $RPM_BUILD_ROOT
|
||||
|
||||
%check
|
||||
|
||||
%files
|
||||
%doc README.md LICENSE.md
|
||||
%{_bindir}/%{name}
|
||||
%{_libexecdir}/%{repo}
|
||||
%{_mandir}/man1/%{name}.1.gz
|
||||
%{_mandir}/man7/%{name}.7.gz
|
||||
/usr/lib/%{repo}/common.bash
|
||||
/usr/lib/%{repo}/formatter.bash
|
||||
/usr/lib/%{repo}/preprocessing.bash
|
||||
/usr/lib/%{repo}/semaphore.bash
|
||||
/usr/lib/%{repo}/test_functions.bash
|
||||
/usr/lib/%{repo}/tracing.bash
|
||||
/usr/lib/%{repo}/validator.bash
|
||||
/usr/lib/%{repo}/warnings.bash
|
||||
|
||||
%changelog
|
||||
* Wed Sep 07 2022 Marcel Hecko <marcel@blava.net> - 1.2.0-1
|
||||
- Fix and test RPM build on Rocky Linux release 8.6
|
||||
|
||||
* Sun Jul 08 2018 mbland <mbland@acm.org> - 1.1.0-1
|
||||
- Increase version to match upstream release
|
||||
|
||||
* Mon Jun 18 2018 pixdrift <support@pixeldrift.net> - 1.0.2-1
|
||||
- Increase version to match upstream release
|
||||
- Relocate libraries to bats-core subdirectory
|
||||
|
||||
* Sat Jun 09 2018 pixdrift <support@pixeldrift.net> - 1.0.1-1
|
||||
- Increase version to match upstream release
|
||||
|
||||
* Fri Jun 08 2018 pixdrift <support@pixeldrift.net> - 1.0.0-1
|
||||
- Initial package build of forked (bats-core) github project
|
||||
Executable
+358
@@ -0,0 +1,358 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# v3.0.0
|
||||
# https://github.com/fsaintjacques/semver-tool
|
||||
|
||||
set -o errexit -o nounset -o pipefail
|
||||
|
||||
NAT='0|[1-9][0-9]*'
|
||||
ALPHANUM='[0-9]*[A-Za-z-][0-9A-Za-z-]*'
|
||||
IDENT="$NAT|$ALPHANUM"
|
||||
FIELD='[0-9A-Za-z-]+'
|
||||
|
||||
SEMVER_REGEX="\
|
||||
^[vV]?\
|
||||
($NAT)\\.($NAT)\\.($NAT)\
|
||||
(\\-(${IDENT})(\\.(${IDENT}))*)?\
|
||||
(\\+${FIELD}(\\.${FIELD})*)?$"
|
||||
|
||||
PROG=semver
|
||||
PROG_VERSION="3.0.0"
|
||||
|
||||
USAGE="\
|
||||
Usage:
|
||||
$PROG bump (major|minor|patch|release|prerel <prerel>|build <build>) <version>
|
||||
$PROG compare <version> <other_version>
|
||||
$PROG get (major|minor|patch|release|prerel|build) <version>
|
||||
$PROG --help
|
||||
$PROG --version
|
||||
|
||||
Arguments:
|
||||
<version> A version must match the following regular expression:
|
||||
\"${SEMVER_REGEX}\"
|
||||
In English:
|
||||
-- The version must match X.Y.Z[-PRERELEASE][+BUILD]
|
||||
where X, Y and Z are non-negative integers.
|
||||
-- PRERELEASE is a dot separated sequence of non-negative integers and/or
|
||||
identifiers composed of alphanumeric characters and hyphens (with
|
||||
at least one non-digit). Numeric identifiers must not have leading
|
||||
zeros. A hyphen (\"-\") introduces this optional part.
|
||||
-- BUILD is a dot separated sequence of identifiers composed of alphanumeric
|
||||
characters and hyphens. A plus (\"+\") introduces this optional part.
|
||||
|
||||
<other_version> See <version> definition.
|
||||
|
||||
<prerel> A string as defined by PRERELEASE above.
|
||||
|
||||
<build> A string as defined by BUILD above.
|
||||
|
||||
Options:
|
||||
-v, --version Print the version of this tool.
|
||||
-h, --help Print this help message.
|
||||
|
||||
Commands:
|
||||
bump Bump by one of major, minor, patch; zeroing or removing
|
||||
subsequent parts. \"bump prerel\" sets the PRERELEASE part and
|
||||
removes any BUILD part. \"bump build\" sets the BUILD part.
|
||||
\"bump release\" removes any PRERELEASE or BUILD parts.
|
||||
The bumped version is written to stdout.
|
||||
|
||||
compare Compare <version> with <other_version>, output to stdout the
|
||||
following values: -1 if <other_version> is newer, 0 if equal, 1 if
|
||||
older. The BUILD part is not used in comparisons.
|
||||
|
||||
get Extract given part of <version>, where part is one of major, minor,
|
||||
patch, prerel, build, or release.
|
||||
|
||||
See also:
|
||||
https://semver.org -- Semantic Versioning 2.0.0"
|
||||
|
||||
function error {
|
||||
echo -e "$1" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
function usage-help {
|
||||
error "$USAGE"
|
||||
}
|
||||
|
||||
function usage-version {
|
||||
echo -e "${PROG}: $PROG_VERSION"
|
||||
exit 0
|
||||
}
|
||||
|
||||
function validate-version {
|
||||
local version=$1
|
||||
if [[ "$version" =~ $SEMVER_REGEX ]]; then
|
||||
# if a second argument is passed, store the result in var named by $2
|
||||
if [ "$#" -eq "2" ]; then
|
||||
local major=${BASH_REMATCH[1]}
|
||||
local minor=${BASH_REMATCH[2]}
|
||||
local patch=${BASH_REMATCH[3]}
|
||||
local prere=${BASH_REMATCH[4]}
|
||||
local build=${BASH_REMATCH[8]}
|
||||
eval "$2=(\"$major\" \"$minor\" \"$patch\" \"$prere\" \"$build\")"
|
||||
else
|
||||
echo "$version"
|
||||
fi
|
||||
else
|
||||
error "version $version does not match the semver scheme 'X.Y.Z(-PRERELEASE)(+BUILD)'. See help for more information."
|
||||
fi
|
||||
}
|
||||
|
||||
function is-nat {
|
||||
[[ "$1" =~ ^($NAT)$ ]]
|
||||
}
|
||||
|
||||
function is-null {
|
||||
[ -z "$1" ]
|
||||
}
|
||||
|
||||
function order-nat {
|
||||
[ "$1" -lt "$2" ] && {
|
||||
echo -1
|
||||
return
|
||||
}
|
||||
[ "$1" -gt "$2" ] && {
|
||||
echo 1
|
||||
return
|
||||
}
|
||||
echo 0
|
||||
}
|
||||
|
||||
function order-string {
|
||||
[[ $1 < $2 ]] && {
|
||||
echo -1
|
||||
return
|
||||
}
|
||||
[[ $1 > $2 ]] && {
|
||||
echo 1
|
||||
return
|
||||
}
|
||||
echo 0
|
||||
}
|
||||
|
||||
# given two (named) arrays containing NAT and/or ALPHANUM fields, compare them
|
||||
# one by one according to semver 2.0.0 spec. Return -1, 0, 1 if left array ($1)
|
||||
# is less-than, equal, or greater-than the right array ($2). The longer array
|
||||
# is considered greater-than the shorter if the shorter is a prefix of the longer.
|
||||
#
|
||||
function compare-fields {
|
||||
local l="$1[@]"
|
||||
local r="$2[@]"
|
||||
local leftfield=("${!l}")
|
||||
local rightfield=("${!r}")
|
||||
local left
|
||||
local right
|
||||
|
||||
local i=$((-1))
|
||||
local order=$((0))
|
||||
|
||||
while true; do
|
||||
[ $order -ne 0 ] && {
|
||||
echo $order
|
||||
return
|
||||
}
|
||||
|
||||
: $((i++))
|
||||
left="${leftfield[$i]}"
|
||||
right="${rightfield[$i]}"
|
||||
|
||||
is-null "$left" && is-null "$right" && {
|
||||
echo 0
|
||||
return
|
||||
}
|
||||
is-null "$left" && {
|
||||
echo -1
|
||||
return
|
||||
}
|
||||
is-null "$right" && {
|
||||
echo 1
|
||||
return
|
||||
}
|
||||
|
||||
is-nat "$left" && is-nat "$right" && {
|
||||
order=$(order-nat "$left" "$right")
|
||||
continue
|
||||
}
|
||||
is-nat "$left" && {
|
||||
echo -1
|
||||
return
|
||||
}
|
||||
is-nat "$right" && {
|
||||
echo 1
|
||||
return
|
||||
}
|
||||
{
|
||||
order=$(order-string "$left" "$right")
|
||||
continue
|
||||
}
|
||||
done
|
||||
}
|
||||
|
||||
# shellcheck disable=SC2206 # checked by "validate"; ok to expand prerel id's into array
|
||||
function compare-version {
|
||||
local order
|
||||
validate-version "$1" V
|
||||
validate-version "$2" V_
|
||||
|
||||
# compare major, minor, patch
|
||||
|
||||
local left=("${V[0]}" "${V[1]}" "${V[2]}")
|
||||
local right=("${V_[0]}" "${V_[1]}" "${V_[2]}")
|
||||
|
||||
order=$(compare-fields left right)
|
||||
[ "$order" -ne 0 ] && {
|
||||
echo "$order"
|
||||
return
|
||||
}
|
||||
|
||||
# compare pre-release ids when M.m.p are equal
|
||||
|
||||
local prerel="${V[3]:1}"
|
||||
local prerel_="${V_[3]:1}"
|
||||
local left=(${prerel//./ })
|
||||
local right=(${prerel_//./ })
|
||||
|
||||
# if left and right have no pre-release part, then left equals right
|
||||
# if only one of left/right has pre-release part, that one is less than simple M.m.p
|
||||
|
||||
[ -z "$prerel" ] && [ -z "$prerel_" ] && {
|
||||
echo 0
|
||||
return
|
||||
}
|
||||
[ -z "$prerel" ] && {
|
||||
echo 1
|
||||
return
|
||||
}
|
||||
[ -z "$prerel_" ] && {
|
||||
echo -1
|
||||
return
|
||||
}
|
||||
|
||||
# otherwise, compare the pre-release id's
|
||||
|
||||
compare-fields left right
|
||||
}
|
||||
|
||||
function command-bump {
|
||||
local new
|
||||
local version
|
||||
local sub_version
|
||||
local command
|
||||
|
||||
case $# in
|
||||
2) case $1 in
|
||||
major | minor | patch | release)
|
||||
command=$1
|
||||
version=$2
|
||||
;;
|
||||
*) usage-help ;;
|
||||
esac ;;
|
||||
3) case $1 in
|
||||
prerel | build)
|
||||
command=$1
|
||||
sub_version=$2 version=$3
|
||||
;;
|
||||
*) usage-help ;;
|
||||
esac ;;
|
||||
*) usage-help ;;
|
||||
esac
|
||||
|
||||
validate-version "$version" parts
|
||||
# shellcheck disable=SC2154
|
||||
local major="${parts[0]}"
|
||||
local minor="${parts[1]}"
|
||||
local patch="${parts[2]}"
|
||||
local prere="${parts[3]}"
|
||||
local build="${parts[4]}"
|
||||
|
||||
case "$command" in
|
||||
major) new="$((major + 1)).0.0" ;;
|
||||
minor) new="${major}.$((minor + 1)).0" ;;
|
||||
patch) new="${major}.${minor}.$((patch + 1))" ;;
|
||||
release) new="${major}.${minor}.${patch}" ;;
|
||||
prerel) new=$(validate-version "${major}.${minor}.${patch}-${sub_version}") ;;
|
||||
build) new=$(validate-version "${major}.${minor}.${patch}${prere}+${sub_version}") ;;
|
||||
*) usage-help ;;
|
||||
esac
|
||||
|
||||
echo "$new"
|
||||
exit 0
|
||||
}
|
||||
|
||||
function command-compare {
|
||||
local v
|
||||
local v_
|
||||
|
||||
case $# in
|
||||
2)
|
||||
v=$(validate-version "$1")
|
||||
v_=$(validate-version "$2")
|
||||
;;
|
||||
*) usage-help ;;
|
||||
esac
|
||||
|
||||
set +u # need unset array element to evaluate to null
|
||||
compare-version "$v" "$v_"
|
||||
exit 0
|
||||
}
|
||||
|
||||
# shellcheck disable=SC2034
|
||||
function command-get {
|
||||
local part version
|
||||
|
||||
if [[ "$#" -ne "2" ]] || [[ -z "$1" ]] || [[ -z "$2" ]]; then
|
||||
usage-help
|
||||
exit 0
|
||||
fi
|
||||
|
||||
part="$1"
|
||||
version="$2"
|
||||
|
||||
validate-version "$version" parts
|
||||
local major="${parts[0]}"
|
||||
local minor="${parts[1]}"
|
||||
local patch="${parts[2]}"
|
||||
local prerel="${parts[3]:1}"
|
||||
local build="${parts[4]:1}"
|
||||
local release="${major}.${minor}.${patch}"
|
||||
|
||||
case "$part" in
|
||||
major | minor | patch | release | prerel | build) echo "${!part}" ;;
|
||||
*) usage-help ;;
|
||||
esac
|
||||
|
||||
exit 0
|
||||
}
|
||||
|
||||
case $# in
|
||||
0)
|
||||
echo "Unknown command: $*"
|
||||
usage-help
|
||||
;;
|
||||
esac
|
||||
|
||||
case $1 in
|
||||
--help | -h)
|
||||
echo -e "$USAGE"
|
||||
exit 0
|
||||
;;
|
||||
--version | -v) usage-version ;;
|
||||
bump)
|
||||
shift
|
||||
command-bump "$@"
|
||||
;;
|
||||
get)
|
||||
shift
|
||||
command-get "$@"
|
||||
;;
|
||||
compare)
|
||||
shift
|
||||
command-compare "$@"
|
||||
;;
|
||||
*)
|
||||
echo "Unknown arguments: $*"
|
||||
usage-help
|
||||
;;
|
||||
esac
|
||||
Reference in New Issue
Block a user