Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix using of absolute paths in prettify script #621

Merged
merged 1 commit into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 2 additions & 14 deletions .github/workflows/check-formatting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,7 @@ jobs:
git stash
for x in $(git ls-tree --full-tree --name-only -r HEAD); do
if [ "${x##*.}" == "hs" ]; then
if grep -qE '^#' "$x"; then
echo "$x contains CPP. Skipping."
else
"$(git rev-parse --show-toplevel)/scripts/devshell/prettify" "$x"
fi
fi
"$(git rev-parse --show-toplevel)/scripts/devshell/prettify" "$x"
done
git --no-pager diff
Expand All @@ -70,13 +64,7 @@ jobs:
git stash
git fetch origin ${{ github.base_ref }} --unshallow
for x in $(git diff --name-only --diff-filter=ACMR origin/${{ github.base_ref }}..HEAD); do
if [ "${x##*.}" == "hs" ]; then
if grep -qE '^#' "$x"; then
echo "$x contains CPP. Skipping."
else
"$(git rev-parse --show-toplevel)/scripts/devshell/prettify" "$x"
fi
fi
"$(git rev-parse --show-toplevel)/scripts/devshell/prettify" "$x"
done
git --no-pager diff --exit-code
Expand Down
37 changes: 25 additions & 12 deletions scripts/devshell/prettify
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,32 @@ show_help() {
echo " -h, --help Show this help message"
}

# https://no-color.org/
if [[ -z "$NO_COLOR" ]]; then
green_colour="\033[0;32m"
blue_colour="\033[0;34m"
orange_colour="\033[0;33m"
reset_colour="\033[0m"
else
green_colour=""
blue_colour=""
orange_colour=""
reset_colour=""
fi

# Function to run the formatting commands
run_format() {
top_level=$(git rev-parse --show-toplevel)
top_level=$(git rev-parse --show-toplevel)
for file in "$@"; do
if [[ $file == *.hs ]]; then
if grep -qE '^#' "$top_level/$file"; then
echo "$file contains CPP. Skipping."
relative_path=$(realpath --relative-to="$top_level" "$file")
if grep -qE '^#' "$top_level/$relative_path"; then
echo -e "${orange_colour}${relative_path} contains CPP. Skipping.${reset_colour}"
else
echo "Formatting: $file"
fourmolu -q -i "$top_level/$file"
fourmolu -q -i "$top_level/$file"
stylish-haskell -i "$top_level/$file"
echo -e "${green_colour}Formatting: ${blue_colour}${relative_path}${reset_colour}"
fourmolu -q -i "$top_level/$relative_path"
fourmolu -q -i "$top_level/$relative_path"
stylish-haskell -i "$top_level/$relative_path"
fi
fi
done
Expand Down Expand Up @@ -71,16 +85,15 @@ for file in $files; do
if [[ ! -a $file ]]; then
echo "ERROR: $file does not exist"
exit 1
if ![[ -f $file ]]; then
echo "ERROR: $file is not a regular file"
exit
fi
elif ! [[ -f $file ]]; then
echo "ERROR: $file is not a regular file"
exit
fi
done

for tool in stylish-haskell fourmolu
do
if !(which $tool > /dev/null 2>&1); then
if ! (which $tool > /dev/null 2>&1); then
echo "ERROR: $tool is not available!"
echo -e
echo "Try entering the development shell with:"
Expand Down
Loading