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