修正:清單輸入濾掉空行,避免 docker create 把空字串當成映像檔名稱
This commit is contained in:
+3
-4
@@ -6,10 +6,9 @@ set -euo pipefail
|
||||
image="action-test:${GITHUB_SHA:-local}"
|
||||
docker build -t "$image" .
|
||||
[ -n "${RUN_ARGS:-}" ] || exit 0
|
||||
mapfile -t opts <<<"${RUN_OPTIONS:-}"
|
||||
mapfile -t args <<<"$RUN_ARGS"
|
||||
# 空字串清單 → 沒有選項
|
||||
[ -n "${opts[0]:-}" ] || opts=()
|
||||
# 清單是「每行一個」,濾掉空行(多行 YAML 值結尾的換行會產生空字串,docker 會把它當成映像檔名稱)
|
||||
mapfile -t opts < <(printf '%s\n' "${RUN_OPTIONS:-}" | sed '/^[[:space:]]*$/d')
|
||||
mapfile -t args < <(printf '%s\n' "$RUN_ARGS" | sed '/^[[:space:]]*$/d')
|
||||
id=$(docker create -w /w -e GITHUB_WORKSPACE=/w "${opts[@]}" "$image" "${args[@]}")
|
||||
trap 'docker rm -f "$id" >/dev/null 2>&1 || true' EXIT
|
||||
docker cp "$PWD/." "$id:/w"
|
||||
|
||||
Reference in New Issue
Block a user