Skip to content

Commit

Permalink
fix for restyle-diff script and merge it with restyled-paths scripts (p…
Browse files Browse the repository at this point in the history
  • Loading branch information
Alami-Amine authored Jul 30, 2024
1 parent 87393f8 commit f6454bc
Showing 1 changed file with 44 additions and 8 deletions.
52 changes: 44 additions & 8 deletions scripts/helpers/restyle-diff.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@
# you've written is kosher to CI
#
# Usage:
# restyle-diff.sh [ref]
# restyle-diff.sh [-d] [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)
#

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

restyle-paths() {
if hash restyle-path 2>/dev/null; then
echo "$@" | xargs restyle-path
docker_run() {
if [ -t 0 ]; then
exec docker run --tty "$@"

else
url=https://github.com/restyled-io/restyler/raw/main/bin/restyle-path
echo "$@" | xargs sh <(curl --location --proto "=https" --tlsv1.2 "$url" -sSf)
exec docker run "$@"

fi
}

ref="$1"
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
}

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

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

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

0 comments on commit f6454bc

Please sign in to comment.