diff --git a/.github/workflows/format-check-new.yml b/.github/workflows/format-check-new.yml index 2536b609a..ca9cd110e 100644 --- a/.github/workflows/format-check-new.yml +++ b/.github/workflows/format-check-new.yml @@ -42,12 +42,24 @@ jobs: distribution: 'zulu' 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 run: | export CLANGFORMAT=`pwd`/clang/bin/clang-format ./formatters/format-cpp.sh ./formatters/format-csharp.sh ./formatters/format-dart.sh + ./formatters/format-haxe.sh ./formatters/format-java.sh ./formatters/format-ts.sh git diff diff --git a/formatters/format-cpp.sh b/formatters/format-cpp.sh index 23e8b3d91..46f2f20db 100755 --- a/formatters/format-cpp.sh +++ b/formatters/format-cpp.sh @@ -6,8 +6,12 @@ echo "Formatting C/C++ files..." 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" + popd > /dev/null exit 1 fi @@ -95,7 +99,7 @@ for file in "${files[@]}"; do fi # 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" errors=$((errors + 1)) fi @@ -108,4 +112,7 @@ if [ $errors -gt 0 ]; then echo "Completed with $errors errors" fi -echo "C/C++ formatting complete" \ No newline at end of file +echo "C/C++ formatting complete" + +# Return to original directory +popd > /dev/null \ No newline at end of file diff --git a/formatters/format-csharp.sh b/formatters/format-csharp.sh index 8eb429ab8..383123cd1 100755 --- a/formatters/format-csharp.sh +++ b/formatters/format-csharp.sh @@ -7,34 +7,42 @@ echo "Formatting C# files..." dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )" if command -v dotnet &> /dev/null; then + # Store original directory + pushd "$dir" > /dev/null + # Copy .editorconfig to C# directories cp .editorconfig ../spine-csharp/ 2>/dev/null || true cp .editorconfig ../spine-monogame/ 2>/dev/null || true cp .editorconfig ../spine-unity/ 2>/dev/null || true # Format spine-csharp - cd ../spine-csharp && dotnet format spine-csharp.csproj || echo "Warning: Some issues with spine-csharp formatting" - cd ../formatters + pushd ../spine-csharp > /dev/null + dotnet format spine-csharp.csproj || echo "Warning: Some issues with spine-csharp formatting" + popd > /dev/null # Format spine-monogame - cd ../spine-monogame && dotnet format --no-restore || echo "Warning: Some issues with spine-monogame formatting" - cd ../formatters + pushd ../spine-monogame > /dev/null + dotnet format --no-restore || echo "Warning: Some issues with spine-monogame formatting" + popd > /dev/null # Format spine-unity - look for .cs files directly if [ -d ../spine-unity ]; then 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 . -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 done - cd ../formatters + popd > /dev/null fi # Clean up .editorconfig files rm -f ../spine-csharp/.editorconfig rm -f ../spine-monogame/.editorconfig rm -f ../spine-unity/.editorconfig + + # Return to original directory + popd > /dev/null else echo "Warning: dotnet not found. Skipping C# formatting." fi \ No newline at end of file diff --git a/formatters/format-dart.sh b/formatters/format-dart.sh index 359fca709..558c6a95d 100755 --- a/formatters/format-dart.sh +++ b/formatters/format-dart.sh @@ -4,6 +4,11 @@ set -e # Format 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 find .. -name "*.dart" \ -not -path "*/.*" \ @@ -12,4 +17,7 @@ if command -v dart &> /dev/null; then -exec dart format --page-width 120 {} + else echo "Warning: dart not found. Skipping Dart formatting." -fi \ No newline at end of file +fi + +# Return to original directory +popd > /dev/null \ No newline at end of file diff --git a/formatters/format-haxe.sh b/formatters/format-haxe.sh index 4830e938d..4c02cb069 100755 --- a/formatters/format-haxe.sh +++ b/formatters/format-haxe.sh @@ -4,6 +4,11 @@ set -e # Format 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 # Format spine-haxe directory if [ -d ../spine-haxe ]; then @@ -11,4 +16,7 @@ if command -v haxelib &> /dev/null && haxelib list formatter &> /dev/null; then fi else echo "Warning: haxe formatter not found. Install with: haxelib install formatter" -fi \ No newline at end of file +fi + +# Return to original directory +popd > /dev/null \ No newline at end of file diff --git a/formatters/format-java.sh b/formatters/format-java.sh index 93c837bc1..7dcfb1f44 100755 --- a/formatters/format-java.sh +++ b/formatters/format-java.sh @@ -6,4 +6,11 @@ echo "Formatting Java files..." dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )" -./formatters/gradlew -p formatters spotlessJavaApply --quiet \ No newline at end of file +# Store original directory +pushd "$dir" > /dev/null + +# Run gradle from the formatters directory +./gradlew spotlessJavaApply --quiet + +# Return to original directory +popd > /dev/null \ No newline at end of file diff --git a/formatters/format-swift.sh b/formatters/format-swift.sh index d39767952..819931c55 100755 --- a/formatters/format-swift.sh +++ b/formatters/format-swift.sh @@ -4,6 +4,11 @@ set -e # Format 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 find .. -name "*.swift" \ -not -path "*/.*" \ @@ -12,4 +17,7 @@ if command -v swift-format &> /dev/null; then | xargs swift-format -i else echo "Warning: swift-format not found. Install from https://github.com/apple/swift-format" -fi \ No newline at end of file +fi + +# Return to original directory +popd > /dev/null \ No newline at end of file diff --git a/formatters/format-ts.sh b/formatters/format-ts.sh index 741209a70..f1afd60ac 100755 --- a/formatters/format-ts.sh +++ b/formatters/format-ts.sh @@ -6,13 +6,25 @@ echo "Formatting TypeScript files..." dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )" +# Store original directory +pushd "$dir" > /dev/null + # Check if tsfmt.json files match 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;31mPlease sync them to ensure consistent formatting.\033[0m" + popd > /dev/null exit 1 fi # Format TypeScript files -cd ../spine-ts && npm run format && cd ../formatters -cd ../tests && npm run format -r && cd ../formatters \ No newline at end of file +pushd ../spine-ts > /dev/null +npm run format +popd > /dev/null + +pushd ../tests > /dev/null +npm run format -r +popd > /dev/null + +# Return to original directory +popd > /dev/null \ No newline at end of file