mirror of
https://github.com/shiroyashik/sculptor.git
synced 2025-12-06 13:01:12 +03:00
minor refactor
- simplify CSV reading logic - add more comments - rework the packaging script - remove debug information for git tags
This commit is contained in:
parent
e21cbd1f63
commit
cbb31f2183
6 changed files with 87 additions and 31 deletions
8
.github/scripts/compress-artifact.sh
vendored
8
.github/scripts/compress-artifact.sh
vendored
|
|
@ -1,8 +0,0 @@
|
|||
#!/bin/bash
|
||||
BINARY_FILE="target/$1/release/sculptor"
|
||||
COMMON_FILES=("Config.example.toml")
|
||||
ARTIFACT_OUTPUT="${OUTPUT_DIR}/sculptor-$2-$3"
|
||||
if [ "$2" = "windows" ]
|
||||
then zip -j "${ARTIFACT_OUTPUT}.zip" "${BINARY_FILE}.exe" "${COMMON_FILES[@]}"
|
||||
else tar --transform 's|^.*/||' -czf "${ARTIFACT_OUTPUT}.tar.gz" "$BINARY_FILE" "${COMMON_FILES[@]}"
|
||||
fi
|
||||
68
.github/scripts/package-artifacts.sh
vendored
68
.github/scripts/package-artifacts.sh
vendored
|
|
@ -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
|
||||
Loading…
Add table
Add a link
Reference in a new issue