Skip to content

Commit f6454bc

Browse files
authored
fix for restyle-diff script and merge it with restyled-paths scripts (project-chip#34625)
1 parent 87393f8 commit f6454bc

File tree

1 file changed

+44
-8
lines changed

1 file changed

+44
-8
lines changed

scripts/helpers/restyle-diff.sh

+44-8
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@
2121
# you've written is kosher to CI
2222
#
2323
# Usage:
24-
# restyle-diff.sh [ref]
24+
# restyle-diff.sh [-d] [ref]
2525
#
2626
# if unspecified, ref defaults to upstream/master (or master)
27+
# -d sets container's log level to DEBUG, if unspecified the default log level will remain (info level)
2728
#
2829

2930
here=${0%/*}
@@ -33,20 +34,55 @@ set -e
3334
CHIP_ROOT=$(cd "$here/../.." && pwd)
3435
cd "$CHIP_ROOT"
3536

36-
restyle-paths() {
37-
if hash restyle-path 2>/dev/null; then
38-
echo "$@" | xargs restyle-path
37+
docker_run() {
38+
if [ -t 0 ]; then
39+
exec docker run --tty "$@"
40+
3941
else
40-
url=https://github.com/restyled-io/restyler/raw/main/bin/restyle-path
41-
echo "$@" | xargs sh <(curl --location --proto "=https" --tlsv1.2 "$url" -sSf)
42+
exec docker run "$@"
43+
4244
fi
4345
}
4446

45-
ref="$1"
47+
restyle-paths() {
48+
49+
image=restyled/restyler:edge
50+
51+
for path in "$@"; do
52+
(
53+
docker_run --tty --interactive --rm \
54+
--env LOG_LEVEL \
55+
--env LOG_DESTINATION \
56+
--env LOG_FORMAT \
57+
--env LOG_COLOR \
58+
--env HOST_DIRECTORY="$PWD" \
59+
--env UNRESTRICTED=1 \
60+
--volume "$PWD":/code \
61+
--volume /tmp:/tmp \
62+
--volume /var/run/docker.sock:/var/run/docker.sock \
63+
--entrypoint restyle-path \
64+
"$image" "$path"
65+
)
66+
done
67+
}
68+
69+
while [[ $# -gt 0 ]]; do
70+
case "$1" in
71+
-d)
72+
export LOG_LEVEL="DEBUG"
73+
shift
74+
;;
75+
*)
76+
ref="$1"
77+
shift
78+
;;
79+
esac
80+
done
81+
4682
if [[ -z "$ref" ]]; then
4783
ref="master"
4884
git remote | grep -qxF upstream && ref="upstream/master"
4985
fi
5086

51-
declare -a paths=("$(git diff --ignore-submodules --name-only --merge-base "$ref")")
87+
mapfile -t paths < <(git diff --ignore-submodules --name-only --merge-base "$ref")
5288
restyle-paths "${paths[@]}"

0 commit comments

Comments
 (0)