Skip to content

Commit

Permalink
adding parallel execution to restyle-diff (#34663)
Browse files Browse the repository at this point in the history
* adding parallel execution to restyle-diff

* using xargs to call restyle-paths

* fixing Copyright year

* restyle the restyler
  • Loading branch information
Alami-Amine authored and pull[bot] committed Sep 25, 2024
1 parent 31859b4 commit 3355258
Showing 1 changed file with 34 additions and 32 deletions.
66 changes: 34 additions & 32 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) 2020-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,57 +21,54 @@
# 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%/*}

set -e

MAX_ARGS=256
pull_image=0

CHIP_ROOT=$(cd "$here/../.." && pwd)
cd "$CHIP_ROOT"

docker_run() {
if [ -t 0 ]; then
exec docker run --tty "$@"

else
exec docker run "$@"

fi
}

restyle-paths() {

image=restyled/restyler:edge

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"
)
done
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" "$@"

}

#This was added to be able to use xargs to call the function restyle-paths
export -f restyle-paths

while [[ $# -gt 0 ]]; do
case "$1" in
-d)
export LOG_LEVEL="DEBUG"
shift
;;
-p)
pull_image=1
shift
;;
*)
ref="$1"
shift
Expand All @@ -81,8 +78,13 @@ 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

mapfile -t paths < <(git diff --ignore-submodules --name-only --merge-base "$ref")
restyle-paths "${paths[@]}"
if [[ $pull_image -eq 1 ]]; then
docker pull restyled/restyler:edge
fi

paths=$(git diff --ignore-submodules --name-only --merge-base "$ref")

echo "$paths" | xargs -n "$MAX_ARGS" bash -c 'restyle-paths "$@"'

0 comments on commit 3355258

Please sign in to comment.