minor refactor

- simplify CSV reading logic
- add more comments
- rework the packaging script
- remove debug information for git tags
This commit is contained in:
Jonatan Czarniecki 2025-06-08 15:57:24 +02:00
parent e21cbd1f63
commit cbb31f2183
No known key found for this signature in database
GPG key ID: 8B5FB251A803BDD0
6 changed files with 87 additions and 31 deletions

View file

@ -1,12 +1,64 @@
#!/bin/bash
set -euo pipefail
USAGE="\
Usage: $0 [-t target]... [-o output_dir] [-h]
-t target add a build target
-o output_dir set output directory for compressed files (default: current directory)
-h Show this help message and exit
export OUTPUT_DIR
mkdir -p "$OUTPUT_DIR"
Environment variables (override options):
OUTPUT_DIR output directory for compressed files
CARGO_BUILD_TARGETS comma-separated list of targets
"
targets=()
output_dir=
printenv CARGO_BUILD_TARGETS | awk -F, '{
for (i = 1; i <= NF; i++)
if (match($i, /^([^-]+)(-[^-]+)*-(linux|windows|darwin)(-[^-]+)*$/, matches))
printf "%s\0%s\0%s\0", $i, matches[3], matches[1]
else print "DEBUG: awk: No regex match for field index " i ": \047" $i "\047" > /dev/stderr
}' | xargs -0 -n 3 "$(dirname -- "$(readlink -f -- "$0")")/compress-artifact.sh"
while getopts "t:o:h" opt
do
case $opt in
t) targets+=("$OPTARG") ;;
o) output_dir="$OPTARG" ;;
h) echo "$USAGE"; exit 0 ;;
*) echo "Invalid option: ${opt}" >&2; echo "$USAGE"; exit 1 ;;
esac
done
output_dir="${OUTPUT_DIR:-${output_dir:-.}}"
if [ "${CARGO_BUILD_TARGETS+set}" ] # if set (might be empty)
then IFS=',' read -ra targets <<< "$CARGO_BUILD_TARGETS"
fi
compress-artifact() {
local build_dir os arch binary_file common_files output_file
build_dir="$1"
os="$2"
arch="$3"
binary_file="${build_dir}/sculptor"
# can be extended to include more files if needed
common_files=("Config.example.toml")
output_file="${output_dir}/sculptor-${os}-${arch}"
if [ "$2" = "windows" ]
then zip -j "${output_file}.zip" "${binary_file}.exe" "${common_files[@]}"
else tar --transform 's|^.*/||' -czf "${output_file}.tar.gz" "$binary_file" "${common_files[@]}"
fi
}
for target in "${targets[@]}"
do
build_dir="target/${target}/release"
# add more targets as needed, for now only linux and windows
if [[ "$target" =~ ^([^-]+)(-[^-]+)*-(linux|windows)(-[^-]+)*$ ]]
then
os="${BASH_REMATCH[3]}"
arch="${BASH_REMATCH[1]}"
declare -p BASH_REMATCH
echo compress-artifact "$build_dir" "$os" "$arch"
else
echo "ERROR: Invalid target: $target" >&2
exit 1
fi
done