generated from demus/basic-rpm-template
Use git ls-files to find sources when running in a git repo directory
Otherwise fall back to find Switch to the directory containing the sources file when generating Include files in sub-directories
This commit is contained in:
@@ -3,7 +3,6 @@
|
||||
# This should be run in the directory containing the spec file.
|
||||
# * Go vendor archive and config
|
||||
# * COPR source file
|
||||
# set +e
|
||||
shopt -s extglob
|
||||
|
||||
_usage() {
|
||||
@@ -14,7 +13,7 @@ _usage() {
|
||||
echo " -a Update archive"
|
||||
echo " -l Update licenses"
|
||||
echo " -s Update sources file"
|
||||
echo " -t Path to a file to write the source hashes to. Implies -s"
|
||||
echo " -t Path to a file to write the source hashes to. The checksums will be calculated for files and subdirectories in the directory containing this file. Implies -s"
|
||||
echo " -u Ignore unlicensed mods. Implies -l"
|
||||
echo " -h Print this message and exit"
|
||||
echo
|
||||
@@ -127,16 +126,42 @@ _update_licenses() {
|
||||
fi
|
||||
}
|
||||
|
||||
# shellcheck disable=SC2046,SC2086
|
||||
__find_sources() {
|
||||
if [ "$SOURCES_FILE" != "" ] && [ -d "$(dirname $SOURCES_FILE)" ] && [ "$PWD" != "$(dirname $SOURCES_FILE)" ]; then
|
||||
DO_POP=1
|
||||
pushd "$(dirname $SOURCES_FILE)" > /dev/null || exit 98
|
||||
fi
|
||||
if [ -d .git ]; then
|
||||
FILENAMES=$(git ls-files --exclude-standard | grep -v -e '^\.' -e sources)
|
||||
else
|
||||
FILENAMES=$(find . -path "./RPMS" -prune -o -path "./BUILD" -prune -o -path "./SRPMS" -prune -o -path "./.*" -prune -o \( ! \( -name '*.spec' -o -name '.*' -o -name sources \) -a -type f \) -printf ' %P')
|
||||
fi
|
||||
if [[ "$DO_POP" -eq 1 ]]; then
|
||||
popd > /dev/null || echo $FILENAMES
|
||||
fi
|
||||
echo $FILENAMES
|
||||
}
|
||||
|
||||
_update_sources() {
|
||||
# Update the sources checksums
|
||||
if [[ "$UPDATE_SOURCES" -eq 1 ]]; then
|
||||
if [ "$SOURCES_FILE" != "" ] && [ -d "$(dirname $SOURCES_FILE)" ]; then
|
||||
DO_POP=1
|
||||
pushd "$(dirname $SOURCES_FILE)" > /dev/null || exit 98
|
||||
fi
|
||||
# The spec file and rpm build directories are excluded
|
||||
echo Calculating checksums
|
||||
# shellcheck disable=SC2094
|
||||
files=$(find . -path "./RPMS" -prune -o -path "./BUILD" -prune -o -path "./SRPMS" -prune -o -path "./.*" -prune -o \( ! \( -name '*.spec' -o -name '.*' \) -a -type f \) -printf ' %P')
|
||||
if ! cksum -a sha512 $files > "${SOURCES_FILE:-sources}"; then
|
||||
echo Sources checksum update failed
|
||||
exit 7
|
||||
# shellcheck disable=SC2046
|
||||
SOURCES="$(__find_sources)"
|
||||
if [ "$SOURCES" == "" ]; then
|
||||
echo No relevant sources found. Skipping checksumming.
|
||||
return 0
|
||||
fi
|
||||
cksum -a sha512 $SOURCES > "${SOURCES_FILE:-sources}"
|
||||
|
||||
if [[ "$DO_POP" -eq 1 ]]; then
|
||||
popd > /dev/null || exit 98
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -88,8 +88,7 @@ setup() {
|
||||
run _update_archive
|
||||
|
||||
assert_failure 5
|
||||
assert_output <<<"
|
||||
Updating go vendor archive
|
||||
assert_output - <<<"Updating go vendor archive
|
||||
Archive update failed"
|
||||
unstub go_vendor_archive
|
||||
}
|
||||
@@ -131,8 +130,7 @@ Archive update failed"
|
||||
run _update_licenses
|
||||
|
||||
assert_failure 6
|
||||
assert_output <<<"
|
||||
Updating go vendor licenses
|
||||
assert_output - <<<"Updating go vendor licenses
|
||||
License update failed"
|
||||
unstub go_vendor_license
|
||||
}
|
||||
@@ -154,6 +152,7 @@ License update failed"
|
||||
|
||||
@test "sources is updated when spec is valid and update is requested" {
|
||||
export UPDATE_SOURCES=1
|
||||
tar -xzf "$BATS_TEST_DIRNAME/testdata/example.tar.gz" -C "$TEST_TEMP_DIR/"
|
||||
echo "Source: go-vendor-tools.toml" > $SPEC_FILE
|
||||
|
||||
run _update_sources
|
||||
@@ -166,6 +165,7 @@ License update failed"
|
||||
@test "sources is only updated when an update is requested" {
|
||||
export UPDATE_LICENSES=1
|
||||
export UPDATE_ARCHIVE=1
|
||||
tar -xzf "$BATS_TEST_DIRNAME/testdata/example.tar.gz" -C "$TEST_TEMP_DIR/"
|
||||
echo "Source: go-vendor-tools.toml" > $SPEC_FILE
|
||||
|
||||
run _update_sources
|
||||
@@ -175,15 +175,36 @@ License update failed"
|
||||
assert_file_empty "$SOURCES_FILE"
|
||||
}
|
||||
|
||||
@test "Some feedback is proffered when cksum fails" {
|
||||
@test "When there are no relevant sources, checksumming is skipped" {
|
||||
stub cksum "exit 1"
|
||||
export UPDATE_SOURCES=1
|
||||
echo "Source: go-vendor-tools.toml" > $SPEC_FILE
|
||||
|
||||
run _update_sources
|
||||
|
||||
assert_failure 7
|
||||
assert_output <<<"
|
||||
Calculating checksums
|
||||
Sources checksum update failed"
|
||||
assert_success
|
||||
assert_output - <<<"Calculating checksums
|
||||
No relevant sources found. Skipping checksumming."
|
||||
}
|
||||
|
||||
# bats test_tags=find_sources
|
||||
@test "The list of files to include in sources excludes the correct things in a git repo" {
|
||||
tar -xzf "$BATS_TEST_DIRNAME/testdata/git.example.tar.gz" -C "$TEST_TEMP_DIR/"
|
||||
|
||||
run __find_sources
|
||||
|
||||
assert_success
|
||||
assert_output "LICENSE README.md changelog data/README data/somedata.csv v1.0.0.tar.gz vendor.tar.bz2"
|
||||
# Some files under .git are read-only
|
||||
rm -fR "$TEST_TEMP_DIR/.git"
|
||||
}
|
||||
|
||||
# bats test_tags=find_sources
|
||||
@test "The list of files to include in sources excludes the correct things in plain directory" {
|
||||
tar -xzf "$BATS_TEST_DIRNAME/testdata/example.tar.gz" -C "$TEST_TEMP_DIR/"
|
||||
|
||||
run __find_sources
|
||||
|
||||
assert_success
|
||||
assert_output "vendor.tar.bz2 v1.0.0.tar.gz README.md LICENSE data/somedata.csv data/README changelog"
|
||||
}
|
||||
|
||||
Vendored
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
Reference in New Issue
Block a user