Skip to content

Commit

Permalink
adding parallel execution to restyle-diff
Browse files Browse the repository at this point in the history
  • Loading branch information
Alami-Amine committed Jul 31, 2024
1 parent 8601109 commit 960141c
Showing 1 changed file with 65 additions and 26 deletions.
91 changes: 65 additions & 26 deletions scripts/helpers/restyle-diff.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash

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

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

restyle-paths() {

image=restyled/restyler:edge
batch_size=4
batch=()

for path in "$@"; do
(
docker_run --tty --interactive --rm \
--env LOG_LEVEL \
--env LOG_DESTINATION \
--env LOG_FORMAT \
--env LOG_COLOR \
--env HOST_DIRECTORY="$PWD" \
--env UNRESTRICTED=1 \
--volume "$PWD":/code \
--volume /tmp:/tmp \
--volume /var/run/docker.sock:/var/run/docker.sock \
--entrypoint restyle-path \
"$image" "$path"
)
batch+=("$path")
if [[ ${#batch[@]} -eq $batch_size ]]; then
for p in "${batch[@]}"; do
(
docker_run \
--env LOG_LEVEL \
--env LOG_DESTINATION \
--env LOG_FORMAT \
--env LOG_COLOR \
--env HOST_DIRECTORY="$PWD" \
--env UNRESTRICTED=1 \
--volume "$PWD":/code \
--volume /tmp:/tmp \
--volume /var/run/docker.sock:/var/run/docker.sock \
--entrypoint restyle-path \
"$image" "$p"
) &
done
wait
batch=()
fi
done

if [[ ${#batch[@]} -gt 0 ]]; then
for p in "${batch[@]}"; do
(
docker_run \
--env LOG_LEVEL \
--env LOG_DESTINATION \
--env LOG_FORMAT \
--env LOG_COLOR \
--env HOST_DIRECTORY="$PWD" \
--env UNRESTRICTED=1 \
--volume "$PWD":/code \
--volume /tmp:/tmp \
--volume /var/run/docker.sock:/var/run/docker.sock \
--entrypoint restyle-path \
"$image" "$p"
) &
done
wait
fi
}

pull_image=0

while [[ $# -gt 0 ]]; do
case "$1" in
-d)
export LOG_LEVEL="DEBUG"
shift
;;
*)
ref="$1"
shift
;;
-d)
export LOG_LEVEL="DEBUG"
shift
;;
-p)
pull_image=1
shift
;;
*)
ref="$1"
shift
;;
esac
done

if [[ -z "$ref" ]]; then
ref="master"
git remote | grep -qxF upstream && ref="upstream/master"
git remote | grep -qxF upstream && ref="upstream/master" && git fetch upstream
fi

if [[ $pull_image -eq 1 ]]; then
docker pull restyled/restyler:edge
fi

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

0 comments on commit 960141c

Please sign in to comment.