9 Commits
Author SHA1 Message Date
demus 5bc2518cce Extract list of sources from spec file if available 2026-07-03 11:22:03 +02:00
demus a526626df1 Check for at least one of git or find and complain 2026-06-12 17:58:40 +02:00
demus d1d8aafca0 More option validation to simplify non-go-vendor-tools enabled scenarios
Test actual contents of sources
2026-06-12 16:33:13 +02:00
demus ba8361fb70 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
2026-06-12 15:06:08 +02:00
demus c82504be3f Add tests 2026-06-11 21:23:59 +02:00
demus aae239a031 Split repos into source and rpm build 2026-06-11 11:07:30 +02:00
demus bc57e1c0d2 Make ignoring unlicensed mods optional
Build and provide rpm of demus-packaging / Start build on COPR (f43) (release) Successful in 4m45s
Build and provide rpm of demus-packaging / Start build on COPR (rawhide) (release) Successful in 4m46s
Build and provide rpm of demus-packaging / Start build on COPR (f44) (release) Successful in 5m31s
2026-06-10 18:42:20 +02:00
demus 6a906c7a02 Ignore unlicensed mods as there is no way to avoid a failure
Build and provide rpm of demus-packaging / Start build on COPR (f43) (release) Successful in 4m3s
Build and provide rpm of demus-packaging / Start build on COPR (rawhide) (release) Successful in 5m8s
Build and provide rpm of demus-packaging / Start build on COPR (f44) (release) Successful in 5m19s
There doesn't seem to be a way to override a missing license, so the license check always fails
2026-06-08 13:28:44 +02:00
demus cf833949a3 Simplify file listing for sources generation
Build and provide rpm of demus-packaging / Start build on COPR (f43) (release) Successful in 4m28s
Build and provide rpm of demus-packaging / Start build on COPR (rawhide) (release) Successful in 5m19s
Build and provide rpm of demus-packaging / Start build on COPR (f44) (release) Successful in 5m21s
2026-06-08 13:21:25 +02:00
16 changed files with 746 additions and 198 deletions
-28
View File
@@ -1,28 +0,0 @@
name: Build and provide rpm of demus-packaging
run-name: Build demus-packaging from ${{ gitea.repository }} on COPR
on:
workflow_dispatch:
inputs:
fedoraversion:
type: choice
description: "Choose a fedora release"
required: true
options: [ f43, f44, rawhide ]
coprproject:
type: choice
description: "Which repo"
required: true
options: [ packages, packages-test ]
jobs:
coprbuild:
name: "Start build on COPR"
runs-on: ${{ inputs.fedoraversion }}-minimal-copr
steps:
- name: Check out repository code
uses: https://git.demus.dk/actions/git-clone@main
- name: Build src.rpm and send to COPR
uses: https://git.demus.dk/actions/copr-build@main
with:
copr_config: ${{ secrets.COPR_API_CONFIG }}
copr_project: ${{ inputs.coprproject }}
fedora_release: ${{ inputs.fedoraversion }}
-19
View File
@@ -1,19 +0,0 @@
name: Build and provide rpm of demus-packaging
run-name: Build demus-packaging from ${{ gitea.repository }} on COPR
on: [release]
jobs:
coprbuild:
name: "Start build on COPR"
strategy:
matrix:
fedoraversion: [ f43, f44, rawhide ]
runs-on: ${{ matrix.fedoraversion }}-minimal-copr
steps:
- name: Check out repository code
uses: https://git.demus.dk/actions/git-clone@main
- name: Build src.rpm and send to COPR
uses: https://git.demus.dk/actions/copr-build@main
with:
copr_config: ${{ secrets.COPR_API_CONFIG }}
copr_project: packages
fedora_release: ${{ matrix.fedoraversion }}
-23
View File
@@ -1,23 +0,0 @@
name: Build and provide rpm of demus-packaging-utils
run-name: Rpmbuild demus-packaging-utils at ${{ gitea.repository }}
on:
workflow_dispatch:
inputs:
fedoraversion:
type: choice
description: "Choose a fedora version"
required: true
options: [ f44, rawhide ]
jobs:
rpmbuild:
name: Build and deploy an rpm to the demus.dk repo
runs-on: ${{ inputs.fedoraversion }}-minimal-rpmbuild
steps:
- name: Check out repository code
uses: https://git.demus.dk/actions/git-clone@main
- name: Build the rpms
uses: https://git.demus.dk/actions/rpmbuild@main
- name: Deploy to packages
uses: https://git.demus.dk/actions/rpm-deploy@main
with:
pat: ${{ secrets.RPM_REPO_WRITE }}
-19
View File
@@ -1,19 +0,0 @@
name: Build and provide rpm of demus-packaging-utils
run-name: Rpmbuild demus-packaging-utils by ${{ github.actor }}
on: [ release ]
jobs:
rpmbuild:
name: Build and deploy an rpm to the demus.dk repo
strategy:
matrix:
fedoraversion: [ f44, rawhide ]
runs-on: ${{ matrix.fedoraversion }}-minimal-rpmbuild
steps:
- name: Check out repository code
uses: https://git.demus.dk/actions/git-clone@main
- name: Build the rpms
uses: https://git.demus.dk/actions/rpmbuild@main
- name: Deploy to packages
uses: https://git.demus.dk/actions/rpm-deploy@main
with:
pat: ${{ secrets.RPM_REPO_WRITE }}
+2 -3
View File
@@ -1,7 +1,6 @@
# demus-packaging-utils
# Packaging tooling
Aliases, scripts and rpm macros to assist in rpm packaging workflows
* regenerate-from-spec: Regenerate tool-generated sources referred to in a spec file
* go-vendor-update: An alias that replicates the parameters used by go2rpm to generate the vendor archive and configuration. It is used in the above regenerate script.
* spec-update-artifacts: Regenerate tool-generated sources referred to in a spec file
* verify_source_checksum rpm macro: Validate that the checksums in a sources file included in a spec matches the unpacked files.
-63
View File
@@ -1,63 +0,0 @@
%global major 1
%global minor 0
%global release 2
Name: demus-packaging
Version: %{major}.%{minor}.%{release}
Release: %autorelease
Summary: Macros and scripts to assist in rpm packaging workflows
URL: https://git.demus.dk/demus/demus-packaging
License: GPL-3.0-or-later
Source: go2rpm-vendor-update.sh
Source: regenerate-from-spec.sh
Source: macros.demus-packaging
Source: LICENSE
Source: README.md
Requires: bash go-vendor-tools+all rpmdevtools askalono-cli
Obsoletes: demus-packaging-utils < 1.0.0
Provides: demus-packaging-utils = %{version}
BuildArch: noarch
%description
* regenerate-from-spec: Regenerate tool-generated sources
referred to in a spec file
* go-vendor-update: An script that replicates the parameters
used by go2rpm to generate the vendor archive, license
expression and configuration. It is used in the above
regenerate script.
* verify_source_checksum rpm macro: Validate that the
checksums in a sources file included in a spec matches the
unpacked files.
* stripped_basename macro: Adds the extension stripping
positional parameter to %stripped_basename
* binshellname macro: Produce the stripped name of a .sh script
%prep
%if %{exists:%{S:2}}
%{load:%{S:2}}
%endif
%?verify_source_checksum
%build
%install
%{__install} -m 0755 -d %{buildroot}%{_bindir}
%{__install} -m 0755 -d %{buildroot}%{_rpmmacrodir}
%{__install} -p -m 755 %{S:0} %{buildroot}%{_bindir}/%{binshellname:%{S:0}}
%{__install} -p -m 755 %{S:1} %{buildroot}%{_bindir}/%{binshellname:%{S:1}}
%{__install} -p -m 644 %{S:2} %{buildroot}%{_rpmmacrodir}/
%{__install} -p -m 644 %{S:3} %{S:4} %{_builddir}
%files
%doc README.md
%license LICENSE
%{_bindir}//%{binshellname:%{S:0}}
%{_bindir}//%{binshellname:%{S:1}}
%{_rpmmacrodir}/*
%changelog
%autochangelog
-9
View File
@@ -1,9 +0,0 @@
#!/bin/bash
# Update go vendor archive and config emulating the way go2rpm does it
if [ $# -ne 1 ] || ! [[ "$1" =~ .*.\.spec$ ]] || [ ! -f "$1" ]; then
echo "Required spec parameter missing"
echo "Usage: go2rpm-vendor-update <specfile>.spec"
exit 1
fi
go_vendor_archive create --config go-vendor-tools.toml --write-config "$1"
go_vendor_license --config go-vendor-tools.toml --path "$1" report --write-config --prompt --autofill auto --update-spec
-29
View File
@@ -1,29 +0,0 @@
#!/bin/bash
# Update various generated artifacts in rpm packages.
# This should be run in the directory containing the spec file.
# * Go vendor archive and config
# * COPR source file
shopt -s extglob
if [ $# -ne 1 ] || ! [[ "$1" =~ .*.\.spec$ ]] || [ ! -f "$1" ]; then
echo "Please provide one .spec file"
echo "Usage: regenerate-from-spec <specfile>.spec"
exit 1
fi
# Ensure remote sources are downloaded
spectool -g "$1"
# go2rpm creates a go-vendor-tools.toml file when using the vendor profile
if grep -q go-vendor-tools.toml "$1"; then
echo Updating go vendor archive
go2rpm-vendor-update "$1"
fi
# Update the sources checksums
# We assume all files are lowercase except README and LICENSE files
# The spec file itself is excluded
echo Calculating checksums
cksum -a sha512 {[a-z],README*,LICENSE*}!(ources|*.spec) > sources
echo Done
-5
View File
@@ -1,5 +0,0 @@
SHA512 (go2rpm-vendor-update.sh) = 9ada43dfb76bf35b4bf44beb6c31b683b9e66c27348fa48f52719f92cb1ce8e2a082b3c21784d24caa3fadcd5093a242200dfcd7b39c16e514334c06fb94b5bb
SHA512 (macros.demus-packaging) = 8c1218425b20da00e6e67c15d1cf09a5913f74f5b2c14a9fda90d28db228ebc87c85bc2e73018638f94a272c71d310a025dc6893f0c69481126602db5e64ff53
SHA512 (regenerate-from-spec.sh) = bcb7b4d1e11da1ed9d9569c6abb73f1c8e5cfaf90bdc7a29dcf784956096a5bad3c5e360cc6ece7baec762ce175671840b146238d751347374bc7fd26537202e
SHA512 (README.md) = 72a6f0085fea6d2b5736c4fa98f31db8fb42462db6fe65d44de7e99405982cc2330e270f6fb042d598d4136bd2a933e226ae85fb99828e07af6ab2b74a5c89f2
SHA512 (LICENSE) = ccb0f3b838dff6254510f19c2bd6f5c48e38b8c40a5bf93d38482f4fb31015823741d3f160b6836ec99bd8f4e6c5fa9a5c9196ecdd7775b793f3ada50467aabd
+222
View File
@@ -0,0 +1,222 @@
#!/usr/bin/bash
# Update various generated artifacts in rpm packages.
# This should be run in the directory containing the spec file.
# * Go vendor archive and config
# * COPR source file
shopt -s extglob
__has_spec_file() {
test -n "$SPEC_FILE"
}
__is_vendor_enabled() {
__has_spec_file && grep -q go-vendor-tools.toml "$SPEC_FILE"
}
# shellcheck disable=SC2046,SC2086
__find_sources() {
if [ -n "$SOURCES_FILE" ] && [ -d "$(dirname $SOURCES_FILE)" ] && [ "$PWD" != "$(dirname $SOURCES_FILE)" ]; then
DO_POP=1
pushd "$(dirname $SOURCES_FILE)" > /dev/null || exit 98
fi
if __has_spec_file; then
SPECTOOL_SOURCES="$(spectool --list-files --sources "$SPEC_FILE")"
if [ $? -ne 0 ]; then
echo "The spec file $SPEC_FILE couldn't be parsed"
exit 96
fi
FILTERED_SOURCES="$(echo "$SPECTOOL_SOURCES" | sed -e '/^Source[0-9]*:[[:blank:]]*sources/d' -e 's/^Source[0-9]*:[[:blank:]]*//')"
if [ -n "$FILTERED_SOURCES" ]; then
FILENAMES=$(basename -a "$FILTERED_SOURCES")
fi
elif [ -d .git ] && which git &>/dev/null; then
FILENAMES=$(git ls-files --exclude-standard | grep -v -e '^\.' -e sources)
elif which find &>/dev/null; then
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')
else
echo "No way to search for relevant source files was found. Please install find (and git if this is a git repository directory) or add a .spec file to the directory."
exit 97
fi
if [[ "$DO_POP" -eq 1 ]]; then
popd > /dev/null || echo $FILENAMES
fi
echo $FILENAMES
}
_usage() {
echo "Usage: $(basename "$0") [OPTION]... [<SPEC_FILE>]"
echo "Update generated artifacts. If <SPEC_FILE> is specified the referenced sources and artifacts are processed"
echo " otherwise a source file is created or updated in the current directory or in the directory the source"
echo " file parameter points to."
echo
echo "Options:"
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. 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
echo "If none of the update operations are specified, all of them will"
echo "be performed unless the spec is not go-vendor-tools enabled,"
echo "in which case only the sources file will be updated."
}
_parse_args() {
while getopts ":alsuht:" flag; do
case "$flag" in
a)
UPDATE_ARCHIVE=1
;;
l)
UPDATE_LICENSES=1
;;
s)
UPDATE_SOURCES=1
;;
t)
SOURCES_FILE="$OPTARG"
;;
u)
IGNORE_UNLICENSED_ARG=" --ignore-unlicensed-mods"
;;
h)
_usage
exit
;;
\?)
echo "Option -$OPTARG is invalid"
echo
_usage
exit 9
;;
esac
done
# Validate required positional .spec file value
SPEC_FILE="${@:$OPTIND:1}"
if __has_spec_file; then
if ! [[ "$SPEC_FILE" =~ .*.\.spec$ ]]; then
echo "The spec file $SPEC_FILE doesn't have a .spec extension"
echo
_usage
exit 2
fi
if [ ! -f "$SPEC_FILE" ]; then
echo "The spec file $SPEC_FILE is not readable"
echo
_usage
exit 3
fi
fi
# Default UPDATE_ vars if no particular operation was requested
if [ -z "$UPDATE_ARCHIVE" ] && [ -z "$UPDATE_LICENSES" ] && [ -z "$UPDATE_SOURCES" ]; then
if __is_vendor_enabled; then
UPDATE_ARCHIVE=1
UPDATE_LICENSES=1
fi
UPDATE_SOURCES=1
fi
# Set implied vars
if [ -n "$IGNORE_UNLICENSED_ARG" ] && [ -z "$UPDATE_LICENSES" ]; then
if ! __is_vendor_enabled; then
echo "$SPEC_FILE is not go-vendor-tools enabled"
exit 4
fi
UPDATE_LICENSES=1
fi
if [ -n "$SOURCES_FILE" ] && [ -z "$UPDATE_SOURCES" ]; then
UPDATE_SOURCES=1
fi
}
_check_go_vendor_enabled() {
# go2rpm creates a go-vendor-tools.toml file when using the vendor profile
if [[ "$UPDATE_ARCHIVE" -eq 1 || "$UPDATE_LICENSES" -eq 1 ]] && ! __is_vendor_enabled; then
echo The spec file is not go-vendor-tools enabled
exit 14
fi
}
_download_sources() {
if __has_spec_file; then
if ! spectool -g "$SPEC_FILE"; then
echo The spec file $SPEC_FILE is not parsable
exit 96
fi
fi
}
_update_archive() {
if ! __has_spec_file; then
echo ERROR: Variable SPEC_FILE is not set
exit 97
fi
# Update the go vendors archive
if [[ "$UPDATE_ARCHIVE" -eq 1 ]]; then
echo Updating go vendor archive
if ! go_vendor_archive create --config go-vendor-tools.toml --write-config "$SPEC_FILE"; then
echo Archive update failed
exit 15
fi
fi
}
_update_licenses() {
# Update the go vendors license config if it has changed
if [[ "$UPDATE_LICENSES" -eq 1 ]]; then
echo Updating go vendor licenses
# shellcheck disable=SC2086
if ! go_vendor_license --config go-vendor-tools.toml --path "$SPEC_FILE" report --write-config --prompt --autofill auto --update-spec$IGNORE_UNLICENSED_ARG; then
echo License update failed
exit 16
fi
fi
}
_update_sources() {
# Update the sources checksums
if [[ "$UPDATE_SOURCES" -eq 1 ]]; then
if [ -n "$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=SC2046
SOURCES="$(__find_sources)"
if [ -z "$SOURCES" ]; then
echo No relevant sources found. Skipping checksumming.
return 0
fi
if ! cksum -a sha512 $SOURCES > "${SOURCES_FILE:-sources}"; then
echo Sources checksum calculation failed
exit 17
fi
if [[ "$DO_POP" -eq 1 ]]; then
popd > /dev/null || exit 98
fi
fi
}
main() {
_parse_args "$@"
_download_sources
_check_go_vendor_enabled
_update_archive
_update_licenses
_update_sources
echo Done
}
# Check if the script is being run directly, not sourced
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
main "$@"
fi
+163
View File
@@ -0,0 +1,163 @@
#!/usr/bin/env bats
load 'test_helper'
setup() {
load ../spec-update-artifacts.sh
common_setup
}
# bats file_tags=spec_file_argument
@test "No selection without a spec file selects sources update" {
_parse_args
assert_equal "$?" 0
assert_equal "$UPDATE_ARCHIVE" ""
assert_equal "$UPDATE_LICENSES" ""
assert_equal "$UPDATE_SOURCES" 1
assert_equal "$IGNORE_UNLICENSED_ARG" ""
}
@test "A not .spec file returns an error" {
run _parse_args gurli.test
assert_failure 2
assert_line --index 0 "The spec file gurli.test doesn't have a .spec extension"
}
@test "A non-existent spec file returns an error" {
run _parse_args gurli.spec
assert_failure 3
assert_line --index 0 "The spec file gurli.spec is not readable"
}
# bats file_tags=options
@test "Invalid option returns an error" {
run _parse_args -q a.spec
assert_failure 9
assert_line --index 0 "Option -q is invalid"
}
@test "No selection with a spec file selects all actions" {
echo "Source: go-vendor-tools.toml" > "$TEST_TEMP_DIR/a.spec"
_parse_args "$TEST_TEMP_DIR/a.spec"
assert_equal "$?" 0
assert_equal "$UPDATE_ARCHIVE" 1
assert_equal "$UPDATE_LICENSES" 1
assert_equal "$UPDATE_SOURCES" 1
assert_equal "$IGNORE_UNLICENSED_ARG" ""
}
@test "Only select update archive" {
touch "$TEST_TEMP_DIR/a.spec"
_parse_args -a "$TEST_TEMP_DIR/a.spec"
assert_equal "$?" 0
assert_equal "$UPDATE_ARCHIVE" 1
assert_equal "$UPDATE_LICENSES" ""
assert_equal "$UPDATE_SOURCES" ""
assert_equal "$IGNORE_UNLICENSED_ARG" ""
}
@test "Only select update license" {
touch "$TEST_TEMP_DIR/a.spec"
_parse_args -l "$TEST_TEMP_DIR/a.spec"
assert_equal "$?" 0
assert_equal "$UPDATE_ARCHIVE" ""
assert_equal "$UPDATE_LICENSES" 1
assert_equal "$UPDATE_SOURCES" ""
assert_equal "$IGNORE_UNLICENSED_ARG" ""
}
@test "Only select update sources" {
touch "$TEST_TEMP_DIR/a.spec"
_parse_args -s "$TEST_TEMP_DIR/a.spec"
assert_equal "$?" 0
assert_equal "$UPDATE_ARCHIVE" ""
assert_equal "$UPDATE_LICENSES" ""
assert_equal "$UPDATE_SOURCES" 1
assert_equal "$IGNORE_UNLICENSED_ARG" ""
}
@test "Multiple selections aggregate" {
echo "Source: go-vendor-tools.toml" > "$TEST_TEMP_DIR/a.spec"
_parse_args -s -l "$TEST_TEMP_DIR/a.spec"
assert_equal "$?" 0
assert_equal "$UPDATE_ARCHIVE" ""
assert_equal "$UPDATE_LICENSES" 1
assert_equal "$UPDATE_SOURCES" 1
assert_equal "$IGNORE_UNLICENSED_ARG" ""
}
@test "The -u option configures an --ignore-unlicensed-mods parameter for go_vendor_license" {
echo "Source: go-vendor-tools.toml" > "$TEST_TEMP_DIR/a.spec"
_parse_args -u "$TEST_TEMP_DIR/a.spec"
assert_equal "$?" 0
assert_equal "$IGNORE_UNLICENSED_ARG" " --ignore-unlicensed-mods"
assert_equal "$UPDATE_ARCHIVE" 1
assert_equal "$UPDATE_LICENSES" 1
assert_equal "$UPDATE_SOURCES" 1
}
@test "The -u option implies -l" {
echo "Source: go-vendor-tools.toml" > "$TEST_TEMP_DIR/a.spec"
_parse_args -u -s "$TEST_TEMP_DIR/a.spec"
assert_equal "$?" 0
assert_equal "$IGNORE_UNLICENSED_ARG" " --ignore-unlicensed-mods"
assert_equal "$UPDATE_ARCHIVE" ""
assert_equal "$UPDATE_LICENSES" 1
assert_equal "$UPDATE_SOURCES" 1
}
@test "The -u options returns an error in a not go-vendor-tools enabled project" {
touch "$TEST_TEMP_DIR/a.spec"
run _parse_args -u -s "$TEST_TEMP_DIR/a.spec"
assert_failure 4
assert_output "$TEST_TEMP_DIR/a.spec is not go-vendor-tools enabled"
}
@test "The help option successfully short-circuits everything else" {
touch "$TEST_TEMP_DIR/a.spec"
run _parse_args -h
assert_success
assert_line --index 0 --partial "Usage: "
}
@test "-t sets the sources file path and enables sources re-generation" {
touch "$TEST_TEMP_DIR/a.spec"
_parse_args -t "$TEST_TEMP_DIR/sources" "$TEST_TEMP_DIR/a.spec"
assert_equal "$?" 0
assert_equal "$UPDATE_ARCHIVE" ""
assert_equal "$UPDATE_LICENSES" ""
assert_equal "$SOURCES_FILE" "$TEST_TEMP_DIR/sources"
assert_equal "$UPDATE_SOURCES" 1
}
@test "-t sets the sources file path and adds sources re-generation to pre-existing requests" {
echo "Source: go-vendor-tools.toml" > "$TEST_TEMP_DIR/a.spec"
_parse_args -a -t "$TEST_TEMP_DIR/sources" "$TEST_TEMP_DIR/a.spec"
assert_equal "$?" 0
assert_equal "$UPDATE_ARCHIVE" 1
assert_equal "$UPDATE_LICENSES" ""
assert_equal "$SOURCES_FILE" "$TEST_TEMP_DIR/sources"
assert_equal "$UPDATE_SOURCES" 1
}
+301
View File
@@ -0,0 +1,301 @@
#!/usr/bin/env bats
load 'test_helper'
bats_load_library 'bats-mock'
setup() {
load ../spec-update-artifacts.sh
common_setup
export SOURCES_FILE="$TEST_TEMP_DIR/sources"
}
_make_valid_spec() {
export SPEC_FILE="$TEST_TEMP_DIR/test.spec"
cat > $SPEC_FILE <<EOL
Name: Gurli
Version: 0
Release: 0
Summary: Test
License: MIT
Source: v1.0.0.tar.gz
Source: vendor.tar.bz2
Source: go-vendor-tools.toml
Source: sources
Source: changelog
Source: README.md
Source: LICENSE
%description
Fnuggi
EOL
}
# bats file_tags=vendor_update_validation
@test "Script returns error when trying to update go vendor archive on a spec that is not go vendor enabled" {
export UPDATE_ARCHIVE=1
run _check_go_vendor_enabled
assert_failure 14
assert_output "The spec file is not go-vendor-tools enabled"
}
@test "Script returns error when trying to update go vendor licenses on a spec that is not go vendor enabled" {
export UPDATE_LICENSES=1
run _check_go_vendor_enabled
assert_failure 14
assert_output "The spec file is not go-vendor-tools enabled"
}
@test "Script succeeds when only updating sources on a spec that is not go vendor enabled" {
export UPDATE_SOURCES=1
run _check_go_vendor_enabled
assert_success
refute_output
}
@test "Script succeeds when a spec is go vendor enabled" {
export UPDATE_LICENSES=1
export UPDATE_SOURCES=1
_make_valid_spec
run _check_go_vendor_enabled
assert_success
refute_output
}
# bats file_tags=archive_update
@test "Archive is updated when spec is valid and update is requested" {
export UPDATE_ARCHIVE=1
_make_valid_spec
stub go_vendor_archive "create --config go-vendor-tools.toml --write-config $TEST_TEMP_DIR/test.spec : echo"
run _update_archive
assert_success
assert_output "Updating go vendor archive"
unstub go_vendor_archive
}
@test "Archive is only updated when an update is requested" {
export UPDATE_LICENSES=1
export UPDATE_SOURCES=1
_make_valid_spec
stub go_vendor_archive "create --config go-vendor-tools.toml --write-config $TEST_TEMP_DIR/test.spec : echo"
run _update_archive
assert_success
refute_output
assert_file_exists ${GO_VENDOR_ARCHIVE_STUB_PLAN}
# unstub fails the test because spectool wasn't invoked
"$BATS_MOCK_REAL_rm" -rf "${BATS_MOCK_TMPDIR}" || true
}
@test "Sane feedback is proffered when go_vendor_archive fails" {
export UPDATE_ARCHIVE=1
_make_valid_spec
stub go_vendor_archive "create --config go-vendor-tools.toml --write-config $TEST_TEMP_DIR/test.spec : exit 3"
run _update_archive
assert_failure 15
assert_output - <<<"Updating go vendor archive
Archive update failed"
unstub go_vendor_archive
}
# bats file_tags=license_update
@test "Licenses are updated when spec is valid and update is requested" {
export UPDATE_LICENSES=1
_make_valid_spec
stub go_vendor_license "--config go-vendor-tools.toml --path $TEST_TEMP_DIR/test.spec report --write-config --prompt --autofill auto --update-spec : echo"
run _update_licenses
assert_success
assert_output "Updating go vendor licenses"
unstub go_vendor_license
}
@test "Licenses are only updated when an update is requested" {
export UPDATE_ARCHIVE=1
export UPDATE_SOURCES=1
_make_valid_spec
stub go_vendor_license "--config go-vendor-tools.toml --path $TEST_TEMP_DIR/test.spec report --write-config --prompt --autofill auto --update-spec : echo"
run _update_licenses
assert_success
refute_output
assert_file_exists ${GO_VENDOR_LICENSE_STUB_PLAN}
# unstub fails the test because spectool wasn't invoked
"$BATS_MOCK_REAL_rm" -rf "${BATS_MOCK_TMPDIR}" || true
}
@test "Sane feedback is proffered when go_vendor_license fails" {
export UPDATE_LICENSES=1
_make_valid_spec
stub go_vendor_license "--config go-vendor-tools.toml --path $TEST_TEMP_DIR/test.spec report --write-config --prompt --autofill auto --update-spec : exit 3"
run _update_licenses
assert_failure 16
assert_output - <<<"Updating go vendor licenses
License update failed"
unstub go_vendor_license
}
@test "--ignore-unlicensed-mods to the go_vendor_license command from IGNORE_UNLICENSED_ARG" {
export UPDATE_LICENSES=1
export IGNORE_UNLICENSED_ARG=" --ignore-unlicensed-mods"
_make_valid_spec
stub go_vendor_license "--config go-vendor-tools.toml --path $TEST_TEMP_DIR/test.spec report --write-config --prompt --autofill auto --update-spec --ignore-unlicensed-mods : echo"
run _update_licenses
assert_success
assert_output "Updating go vendor licenses"
unstub go_vendor_license
}
# bats file_tags=sources_update
@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/"
_make_valid_spec
run _update_sources
assert_success
assert_output "Calculating checksums"
assert_file_contains "$SOURCES_FILE" "SHA512 (v1.0.0.tar.gz)"
assert_file_contains "$SOURCES_FILE" "SHA512 (LICENSE)"
assert_file_contains "$SOURCES_FILE" "SHA512 (README.md)"
assert_file_not_contains "$SOURCES_FILE" sources
assert_file_not_contains "$SOURCES_FILE" test.spec
assert_file_not_contains "$SOURCES_FILE" BUILD
assert_file_not_contains "$SOURCES_FILE" .git
}
@test "sources is updated in a git directory without spec and update is requested" {
export UPDATE_SOURCES=1
tar -xzf "$BATS_TEST_DIRNAME/testdata/git.example.tar.gz" -C "$TEST_TEMP_DIR/"
run _update_sources
assert_success
assert_output "Calculating checksums"
assert_file_contains "$SOURCES_FILE" "SHA512 (v1.0.0.tar.gz)"
assert_file_contains "$SOURCES_FILE" "SHA512 (LICENSE)"
assert_file_contains "$SOURCES_FILE" "SHA512 (README.md)"
assert_file_not_contains "$SOURCES_FILE" sources
assert_file_not_contains "$SOURCES_FILE" BUILD
assert_file_not_contains "$SOURCES_FILE" .git
}
@test "sources is updated in a plain directory 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/"
_make_valid_spec
run _update_sources
assert_success
assert_output "Calculating checksums"
assert_file_contains "$SOURCES_FILE" "SHA512 (v1.0.0.tar.gz)"
assert_file_contains "$SOURCES_FILE" "SHA512 (LICENSE)"
assert_file_contains "$SOURCES_FILE" "SHA512 (README.md)"
assert_file_not_contains "$SOURCES_FILE" sources
assert_file_not_contains "$SOURCES_FILE" test.spec
assert_file_not_contains "$SOURCES_FILE" BUILD
assert_file_not_contains "$SOURCES_FILE" .git
}
@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/"
_make_valid_spec
run _update_sources
assert_success
refute_output
assert_file_empty "$SOURCES_FILE"
}
@test "When there are no relevant sources, checksumming is skipped" {
export UPDATE_SOURCES=1
export SPEC_FILE="$TEST_TEMP_DIR/test.spec"
cat > $SPEC_FILE <<EOL
Name: Gurli
Version: 0
Release: 0
Summary: Test
License: MIT
Source: sources
%description
Fnuggi
EOL
run _update_sources
assert_success
assert_output - <<<"Calculating checksums
No relevant sources found. Skipping checksumming."
}
@test "Sane feedback is proffered when cksum fails" {
stub cksum "exit 1"
export UPDATE_SOURCES=1
tar -xzf "$BATS_TEST_DIRNAME/testdata/git.example.tar.gz" -C "$TEST_TEMP_DIR/"
_make_valid_spec
run _update_sources
unstub cksum
assert_failure 17
assert_output - <<<"Calculating checksums
Sources checksum calculation failed"
}
# 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"
}
# 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 "go-vendor-tools.toml vendor.tar.bz2 v1.0.0.tar.gz README.md LICENSE data/somedata.csv data/README changelog"
}
# bats test_tags=find_sources
@test "If neither git or find are installed and there is no .spec file, you get an error and explanation" {
stub which "return 1" "return 1"
tar -xzf "$BATS_TEST_DIRNAME/testdata/git.example.tar.gz" -C "$TEST_TEMP_DIR/"
run __find_sources
unstub which
assert_failure 97
assert_output "No way to search for relevant source files was found. Please install find (and git if this is a git repository directory) or add a .spec file to the directory."
}
+32
View File
@@ -0,0 +1,32 @@
#!/usr/bin/env bats
load 'test_helper'
bats_load_library 'bats-file'
bats_load_library 'bats-mock'
setup() {
load ../spec-update-artifacts.sh
common_setup
}
# bats file_tags=download_sources
@test "Missing spec variable skips action" {
stub spectool ''
_download_sources
assert_file_exists ${SPECTOOL_STUB_PLAN}
# unstub fails the test because spectool wasn't invoked
"$BATS_MOCK_REAL_rm" -rf "${BATS_MOCK_TMPDIR}" || true
}
@test "Correct parameters are passed to spectool" {
stub spectool '-g gurli.spec : echo OK'
export SPEC_FILE=gurli.spec
run _download_sources
assert_success
unstub spectool
}
+26
View File
@@ -0,0 +1,26 @@
bats_require_minimum_version 1.5.0
bats_load_library 'bats-support'
bats_load_library 'bats-assert'
bats_load_library 'bats-file'
setup_file() {
BATS_TEST_TIMEOUT=3
}
teardown() {
if [ -d "$TEST_TEMP_DIR/.git" ]; then
# Some files under .git are read-only
rm -fR "$TEST_TEMP_DIR/.git"
fi
temp_del "$TEST_TEMP_DIR"
unset TEST_TEMP_DIR
}
common_setup() {
export TEST_TEMP_DIR="$(temp_make)"
}
bats::on_failure() {
echo "Failed test run output:"
echo "$output"
}
BIN
View File
Binary file not shown.
Binary file not shown.