mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-21 01:36:02 +08:00
[formatters] Use pushd/popd so formatters can be called from any directory
This commit is contained in:
parent
9ffe3579d7
commit
ca45046ae3
12
.github/workflows/format-check-new.yml
vendored
12
.github/workflows/format-check-new.yml
vendored
@ -42,12 +42,24 @@ jobs:
|
|||||||
distribution: 'zulu'
|
distribution: 'zulu'
|
||||||
java-version: "16"
|
java-version: "16"
|
||||||
|
|
||||||
|
- name: Install Haxe
|
||||||
|
uses: krdlab/setup-haxe@v1
|
||||||
|
with:
|
||||||
|
haxe-version: '4.3.2'
|
||||||
|
- run: haxelib install formatter
|
||||||
|
|
||||||
|
- name: Install Dart
|
||||||
|
uses: dart-lang/setup-dart@v1
|
||||||
|
with:
|
||||||
|
sdk: 'stable'
|
||||||
|
|
||||||
- name: Format
|
- name: Format
|
||||||
run: |
|
run: |
|
||||||
export CLANGFORMAT=`pwd`/clang/bin/clang-format
|
export CLANGFORMAT=`pwd`/clang/bin/clang-format
|
||||||
./formatters/format-cpp.sh
|
./formatters/format-cpp.sh
|
||||||
./formatters/format-csharp.sh
|
./formatters/format-csharp.sh
|
||||||
./formatters/format-dart.sh
|
./formatters/format-dart.sh
|
||||||
|
./formatters/format-haxe.sh
|
||||||
./formatters/format-java.sh
|
./formatters/format-java.sh
|
||||||
./formatters/format-ts.sh
|
./formatters/format-ts.sh
|
||||||
git diff
|
git diff
|
||||||
|
|||||||
@ -6,8 +6,12 @@ echo "Formatting C/C++ files..."
|
|||||||
|
|
||||||
dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
|
dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
|
||||||
|
|
||||||
if [ ! -f "$dir/.clang-format" ]; then
|
# Store original directory
|
||||||
|
pushd "$dir" > /dev/null
|
||||||
|
|
||||||
|
if [ ! -f ".clang-format" ]; then
|
||||||
echo "Error: .clang-format not found in formatters directory"
|
echo "Error: .clang-format not found in formatters directory"
|
||||||
|
popd > /dev/null
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -95,7 +99,7 @@ for file in "${files[@]}"; do
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Format the file and capture any errors
|
# Format the file and capture any errors
|
||||||
if ! clang-format -i -style=file:"$dir/.clang-format" "$file" 2>/dev/null; then
|
if ! clang-format -i -style=file:".clang-format" "$file" 2>/dev/null; then
|
||||||
printf "\nError formatting: $file\n"
|
printf "\nError formatting: $file\n"
|
||||||
errors=$((errors + 1))
|
errors=$((errors + 1))
|
||||||
fi
|
fi
|
||||||
@ -109,3 +113,6 @@ if [ $errors -gt 0 ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
echo "C/C++ formatting complete"
|
echo "C/C++ formatting complete"
|
||||||
|
|
||||||
|
# Return to original directory
|
||||||
|
popd > /dev/null
|
||||||
@ -7,34 +7,42 @@ echo "Formatting C# files..."
|
|||||||
dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
|
dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
|
||||||
|
|
||||||
if command -v dotnet &> /dev/null; then
|
if command -v dotnet &> /dev/null; then
|
||||||
|
# Store original directory
|
||||||
|
pushd "$dir" > /dev/null
|
||||||
|
|
||||||
# Copy .editorconfig to C# directories
|
# Copy .editorconfig to C# directories
|
||||||
cp .editorconfig ../spine-csharp/ 2>/dev/null || true
|
cp .editorconfig ../spine-csharp/ 2>/dev/null || true
|
||||||
cp .editorconfig ../spine-monogame/ 2>/dev/null || true
|
cp .editorconfig ../spine-monogame/ 2>/dev/null || true
|
||||||
cp .editorconfig ../spine-unity/ 2>/dev/null || true
|
cp .editorconfig ../spine-unity/ 2>/dev/null || true
|
||||||
|
|
||||||
# Format spine-csharp
|
# Format spine-csharp
|
||||||
cd ../spine-csharp && dotnet format spine-csharp.csproj || echo "Warning: Some issues with spine-csharp formatting"
|
pushd ../spine-csharp > /dev/null
|
||||||
cd ../formatters
|
dotnet format spine-csharp.csproj || echo "Warning: Some issues with spine-csharp formatting"
|
||||||
|
popd > /dev/null
|
||||||
|
|
||||||
# Format spine-monogame
|
# Format spine-monogame
|
||||||
cd ../spine-monogame && dotnet format --no-restore || echo "Warning: Some issues with spine-monogame formatting"
|
pushd ../spine-monogame > /dev/null
|
||||||
cd ../formatters
|
dotnet format --no-restore || echo "Warning: Some issues with spine-monogame formatting"
|
||||||
|
popd > /dev/null
|
||||||
|
|
||||||
# Format spine-unity - look for .cs files directly
|
# Format spine-unity - look for .cs files directly
|
||||||
if [ -d ../spine-unity ]; then
|
if [ -d ../spine-unity ]; then
|
||||||
echo "Formatting spine-unity C# files directly..."
|
echo "Formatting spine-unity C# files directly..."
|
||||||
cd ../spine-unity
|
pushd ../spine-unity > /dev/null
|
||||||
# Find all .cs files and format them using dotnet format whitespace
|
# Find all .cs files and format them using dotnet format whitespace
|
||||||
find . -name "*.cs" -type f -not -path "./Library/*" -not -path "./Temp/*" -not -path "./obj/*" -not -path "./bin/*" | while read -r file; do
|
find . -name "*.cs" -type f -not -path "./Library/*" -not -path "./Temp/*" -not -path "./obj/*" -not -path "./bin/*" | while read -r file; do
|
||||||
dotnet format whitespace --include "$file" --no-restore 2>/dev/null || true
|
dotnet format whitespace --include "$file" --no-restore 2>/dev/null || true
|
||||||
done
|
done
|
||||||
cd ../formatters
|
popd > /dev/null
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Clean up .editorconfig files
|
# Clean up .editorconfig files
|
||||||
rm -f ../spine-csharp/.editorconfig
|
rm -f ../spine-csharp/.editorconfig
|
||||||
rm -f ../spine-monogame/.editorconfig
|
rm -f ../spine-monogame/.editorconfig
|
||||||
rm -f ../spine-unity/.editorconfig
|
rm -f ../spine-unity/.editorconfig
|
||||||
|
|
||||||
|
# Return to original directory
|
||||||
|
popd > /dev/null
|
||||||
else
|
else
|
||||||
echo "Warning: dotnet not found. Skipping C# formatting."
|
echo "Warning: dotnet not found. Skipping C# formatting."
|
||||||
fi
|
fi
|
||||||
@ -4,6 +4,11 @@ set -e
|
|||||||
# Format Dart files
|
# Format Dart files
|
||||||
echo "Formatting Dart files..."
|
echo "Formatting Dart files..."
|
||||||
|
|
||||||
|
dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
|
||||||
|
|
||||||
|
# Store original directory
|
||||||
|
pushd "$dir" > /dev/null
|
||||||
|
|
||||||
if command -v dart &> /dev/null; then
|
if command -v dart &> /dev/null; then
|
||||||
find .. -name "*.dart" \
|
find .. -name "*.dart" \
|
||||||
-not -path "*/.*" \
|
-not -path "*/.*" \
|
||||||
@ -13,3 +18,6 @@ if command -v dart &> /dev/null; then
|
|||||||
else
|
else
|
||||||
echo "Warning: dart not found. Skipping Dart formatting."
|
echo "Warning: dart not found. Skipping Dart formatting."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Return to original directory
|
||||||
|
popd > /dev/null
|
||||||
@ -4,6 +4,11 @@ set -e
|
|||||||
# Format Haxe files
|
# Format Haxe files
|
||||||
echo "Formatting Haxe files..."
|
echo "Formatting Haxe files..."
|
||||||
|
|
||||||
|
dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
|
||||||
|
|
||||||
|
# Store original directory
|
||||||
|
pushd "$dir" > /dev/null
|
||||||
|
|
||||||
if command -v haxelib &> /dev/null && haxelib list formatter &> /dev/null; then
|
if command -v haxelib &> /dev/null && haxelib list formatter &> /dev/null; then
|
||||||
# Format spine-haxe directory
|
# Format spine-haxe directory
|
||||||
if [ -d ../spine-haxe ]; then
|
if [ -d ../spine-haxe ]; then
|
||||||
@ -12,3 +17,6 @@ if command -v haxelib &> /dev/null && haxelib list formatter &> /dev/null; then
|
|||||||
else
|
else
|
||||||
echo "Warning: haxe formatter not found. Install with: haxelib install formatter"
|
echo "Warning: haxe formatter not found. Install with: haxelib install formatter"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Return to original directory
|
||||||
|
popd > /dev/null
|
||||||
@ -6,4 +6,11 @@ echo "Formatting Java files..."
|
|||||||
|
|
||||||
dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
|
dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
|
||||||
|
|
||||||
./formatters/gradlew -p formatters spotlessJavaApply --quiet
|
# Store original directory
|
||||||
|
pushd "$dir" > /dev/null
|
||||||
|
|
||||||
|
# Run gradle from the formatters directory
|
||||||
|
./gradlew spotlessJavaApply --quiet
|
||||||
|
|
||||||
|
# Return to original directory
|
||||||
|
popd > /dev/null
|
||||||
@ -4,6 +4,11 @@ set -e
|
|||||||
# Format Swift files
|
# Format Swift files
|
||||||
echo "Formatting Swift files..."
|
echo "Formatting Swift files..."
|
||||||
|
|
||||||
|
dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
|
||||||
|
|
||||||
|
# Store original directory
|
||||||
|
pushd "$dir" > /dev/null
|
||||||
|
|
||||||
if command -v swift-format &> /dev/null; then
|
if command -v swift-format &> /dev/null; then
|
||||||
find .. -name "*.swift" \
|
find .. -name "*.swift" \
|
||||||
-not -path "*/.*" \
|
-not -path "*/.*" \
|
||||||
@ -13,3 +18,6 @@ if command -v swift-format &> /dev/null; then
|
|||||||
else
|
else
|
||||||
echo "Warning: swift-format not found. Install from https://github.com/apple/swift-format"
|
echo "Warning: swift-format not found. Install from https://github.com/apple/swift-format"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Return to original directory
|
||||||
|
popd > /dev/null
|
||||||
@ -6,13 +6,25 @@ echo "Formatting TypeScript files..."
|
|||||||
|
|
||||||
dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
|
dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
|
||||||
|
|
||||||
|
# Store original directory
|
||||||
|
pushd "$dir" > /dev/null
|
||||||
|
|
||||||
# Check if tsfmt.json files match
|
# Check if tsfmt.json files match
|
||||||
if ! cmp -s ../spine-ts/tsfmt.json ../tests/tsfmt.json; then
|
if ! cmp -s ../spine-ts/tsfmt.json ../tests/tsfmt.json; then
|
||||||
echo -e "\033[1;31mERROR: spine-ts/tsfmt.json and tests/tsfmt.json differ!\033[0m"
|
echo -e "\033[1;31mERROR: spine-ts/tsfmt.json and tests/tsfmt.json differ!\033[0m"
|
||||||
echo -e "\033[1;31mPlease sync them to ensure consistent formatting.\033[0m"
|
echo -e "\033[1;31mPlease sync them to ensure consistent formatting.\033[0m"
|
||||||
|
popd > /dev/null
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Format TypeScript files
|
# Format TypeScript files
|
||||||
cd ../spine-ts && npm run format && cd ../formatters
|
pushd ../spine-ts > /dev/null
|
||||||
cd ../tests && npm run format -r && cd ../formatters
|
npm run format
|
||||||
|
popd > /dev/null
|
||||||
|
|
||||||
|
pushd ../tests > /dev/null
|
||||||
|
npm run format -r
|
||||||
|
popd > /dev/null
|
||||||
|
|
||||||
|
# Return to original directory
|
||||||
|
popd > /dev/null
|
||||||
Loading…
x
Reference in New Issue
Block a user