Skip to content

Commit 960141c

Browse files
committed
adding parallel execution to restyle-diff
1 parent 8601109 commit 960141c

File tree

1 file changed

+65
-26
lines changed

1 file changed

+65
-26
lines changed

scripts/helpers/restyle-diff.sh

+65-26
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
22

33
#
4-
# Copyright (c) 2020 Project CHIP Authors
4+
# Copyright (c) 2024 Project CHIP Authors
55
#
66
# Licensed under the Apache License, Version 2.0 (the "License");
77
# you may not use this file except in compliance with the License.
@@ -21,10 +21,11 @@
2121
# you've written is kosher to CI
2222
#
2323
# Usage:
24-
# restyle-diff.sh [-d] [ref]
24+
# restyle-diff.sh [-d] [-p] [ref]
2525
#
2626
# if unspecified, ref defaults to upstream/master (or master)
2727
# -d sets container's log level to DEBUG, if unspecified the default log level will remain (info level)
28+
# -p pulls the Docker image before running the restyle paths
2829
#
2930

3031
here=${0%/*}
@@ -45,43 +46,81 @@ docker_run() {
4546
}
4647

4748
restyle-paths() {
48-
4949
image=restyled/restyler:edge
50+
batch_size=4
51+
batch=()
5052

5153
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-
)
54+
batch+=("$path")
55+
if [[ ${#batch[@]} -eq $batch_size ]]; then
56+
for p in "${batch[@]}"; do
57+
(
58+
docker_run \
59+
--env LOG_LEVEL \
60+
--env LOG_DESTINATION \
61+
--env LOG_FORMAT \
62+
--env LOG_COLOR \
63+
--env HOST_DIRECTORY="$PWD" \
64+
--env UNRESTRICTED=1 \
65+
--volume "$PWD":/code \
66+
--volume /tmp:/tmp \
67+
--volume /var/run/docker.sock:/var/run/docker.sock \
68+
--entrypoint restyle-path \
69+
"$image" "$p"
70+
) &
71+
done
72+
wait
73+
batch=()
74+
fi
6675
done
76+
77+
if [[ ${#batch[@]} -gt 0 ]]; then
78+
for p in "${batch[@]}"; do
79+
(
80+
docker_run \
81+
--env LOG_LEVEL \
82+
--env LOG_DESTINATION \
83+
--env LOG_FORMAT \
84+
--env LOG_COLOR \
85+
--env HOST_DIRECTORY="$PWD" \
86+
--env UNRESTRICTED=1 \
87+
--volume "$PWD":/code \
88+
--volume /tmp:/tmp \
89+
--volume /var/run/docker.sock:/var/run/docker.sock \
90+
--entrypoint restyle-path \
91+
"$image" "$p"
92+
) &
93+
done
94+
wait
95+
fi
6796
}
6897

98+
pull_image=0
99+
69100
while [[ $# -gt 0 ]]; do
70101
case "$1" in
71-
-d)
72-
export LOG_LEVEL="DEBUG"
73-
shift
74-
;;
75-
*)
76-
ref="$1"
77-
shift
78-
;;
102+
-d)
103+
export LOG_LEVEL="DEBUG"
104+
shift
105+
;;
106+
-p)
107+
pull_image=1
108+
shift
109+
;;
110+
*)
111+
ref="$1"
112+
shift
113+
;;
79114
esac
80115
done
81116

82117
if [[ -z "$ref" ]]; then
83118
ref="master"
84-
git remote | grep -qxF upstream && ref="upstream/master"
119+
git remote | grep -qxF upstream && ref="upstream/master" && git fetch upstream
120+
fi
121+
122+
if [[ $pull_image -eq 1 ]]; then
123+
docker pull restyled/restyler:edge
85124
fi
86125

87126
mapfile -t paths < <(git diff --ignore-submodules --name-only --merge-base "$ref")

0 commit comments

Comments
 (0)