feat(builder): support project-local distribution scripts
This commit is contained in:
@@ -6,12 +6,17 @@ usage() {
|
||||
Usage:
|
||||
COPY_DEST=/path/or/container:/dir \
|
||||
copy_artifact.sh FILE [FILE ...]
|
||||
COPY_SCRIPT=.pouch/builder/publish-apk.sh \
|
||||
copy_artifact.sh FILE [FILE ...]
|
||||
|
||||
Copy built artifacts to COPY_DEST. Dest is a local directory, or a Docker
|
||||
copy target `container:/absolute/dir` (docker cp). Does not read `.env`.
|
||||
Copy built artifacts using COPY_SCRIPT when configured; otherwise copy to
|
||||
COPY_DEST. COPY_DEST is a local directory or a Docker copy target
|
||||
`container:/absolute/dir` (docker cp). Does not read `.env`.
|
||||
|
||||
Environment (project root .env.builder; shell values win):
|
||||
COPY_DEST Required. Local dir or container:/dir
|
||||
COPY_DEST Optional fallback. Local dir or container:/dir
|
||||
COPY_SCRIPT Optional .pouch/builder/ relative path or absolute
|
||||
executable. Receives FILE paths as positional args.
|
||||
COPY_AS Optional. Extra basenames for the first file
|
||||
(comma or space separated)
|
||||
ALLOW_UNCOMMITTED=1 Publish despite a dirty working tree
|
||||
@@ -58,9 +63,13 @@ while (($#)); do
|
||||
esac
|
||||
done
|
||||
|
||||
if [[ -z "$dest" || $# -eq 0 ]]; then
|
||||
echo "Error: COPY_DEST and at least one file are required." >&2
|
||||
echo "Set them in the environment or the project root .env.builder." >&2
|
||||
if [[ -z "$dest" && -z "${COPY_SCRIPT:-}" || $# -eq 0 ]]; then
|
||||
if [[ $# -eq 0 ]]; then
|
||||
echo "Error: at least one file is required." >&2
|
||||
else
|
||||
echo "Error: set COPY_DEST or COPY_SCRIPT." >&2
|
||||
fi
|
||||
echo "Set the value in the environment or the project root .env.builder." >&2
|
||||
usage >&2
|
||||
exit 2
|
||||
fi
|
||||
@@ -73,6 +82,63 @@ if [[ -n "$project_root" ]] && git -C "$project_root" rev-parse HEAD >/dev/null
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ -n "${COPY_SCRIPT:-}" ]]; then
|
||||
copy_script=$COPY_SCRIPT
|
||||
if [[ "$copy_script" != /* ]]; then
|
||||
relative_script=${copy_script#./}
|
||||
if [[ "$relative_script" != .pouch/builder/* || -z "$project_root" ]]; then
|
||||
echo "Error: relative COPY_SCRIPT must be under .pouch/builder/." >&2
|
||||
exit 2
|
||||
fi
|
||||
copy_script="$project_root/$relative_script"
|
||||
fi
|
||||
if [[ ! -f "$copy_script" ]]; then
|
||||
echo "Error: COPY_SCRIPT is not a file: $copy_script" >&2
|
||||
exit 2
|
||||
fi
|
||||
if [[ ! -x "$copy_script" ]]; then
|
||||
echo "Error: COPY_SCRIPT is not executable: $copy_script" >&2
|
||||
exit 2
|
||||
fi
|
||||
artifact_args=()
|
||||
for src in "$@"; do
|
||||
if [[ ! -f "$src" ]]; then
|
||||
echo "Error: not a file: $src" >&2
|
||||
exit 2
|
||||
fi
|
||||
if [[ "$src" == /* ]]; then
|
||||
artifact_args+=("$src")
|
||||
else
|
||||
artifact_args+=("$PWD/$src")
|
||||
fi
|
||||
done
|
||||
if $dry_run; then
|
||||
printf 'custom copy script:'
|
||||
printf ' %q' "$copy_script" "${artifact_args[@]}"
|
||||
printf '\n'
|
||||
exit 0
|
||||
fi
|
||||
export BUILDER_PROJECT_ROOT=${project_root:-}
|
||||
if "$copy_script" "${artifact_args[@]}"; then
|
||||
if command -v sha256sum >/dev/null 2>&1; then
|
||||
for src in "${artifact_args[@]}"; do
|
||||
sha256sum -- "$src"
|
||||
done
|
||||
fi
|
||||
echo "copy_artifact: custom script completed for $# file(s)"
|
||||
exit 0
|
||||
else
|
||||
status=$?
|
||||
echo "Error: COPY_SCRIPT failed with exit code $status." >&2
|
||||
exit "$status"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ -z "$dest" ]]; then
|
||||
echo "Error: COPY_DEST is required when COPY_SCRIPT is not configured." >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
is_docker_dest() {
|
||||
local d=$1
|
||||
[[ "$d" != /* && "$d" != ./* && "$d" != ../* && "$d" != ~* ]] \
|
||||
|
||||
Reference in New Issue
Block a user