Skip to content

Commit

Permalink
Merge pull request #88933 from raulsntos/dotnet/pre-commit
Browse files Browse the repository at this point in the history
Move dotnet-format script to pre-commit
  • Loading branch information
akien-mga authored Mar 2, 2024
2 parents dad6c77 + 97851f0 commit f2045ba
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 47 deletions.
8 changes: 0 additions & 8 deletions .github/workflows/static_checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,6 @@ jobs:
run: |
doc/tools/doc_status.py doc/classes modules/*/doc_classes platform/*/doc_classes
- name: Style checks via dotnet format (dotnet_format.sh)
run: |
if grep -q "modules/mono" changed.txt || [ -z "$(cat changed.txt)" ]; then
bash ./misc/scripts/dotnet_format.sh
else
echo "Skipping dotnet format as no C# files were changed."
fi
- name: Spell checks via codespell
if: github.event_name == 'pull_request' && env.CHANGED_FILES != ''
uses: codespell-project/actions-codespell@v2
Expand Down
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,9 @@ repos:
platform/android/java/lib/src/org/godotengine/godot/gl/EGLLogWrapper.*|
platform/android/java/lib/src/org/godotengine/godot/utils/ProcessPhoenix.*
)
- id: dotnet-format
name: dotnet-format
language: python
entry: python3 misc/scripts/dotnet_format.py
types_or: [c#]
30 changes: 30 additions & 0 deletions misc/scripts/dotnet_format.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import glob
import os
import sys

# Create dummy generated files.
for path in [
"modules/mono/SdkPackageVersions.props",
]:
os.makedirs(os.path.dirname(path), exist_ok=True)
with open(path, "w") as f:
f.write("<Project />")

# Avoid importing GeneratedIncludes.props.
os.environ["GodotSkipGenerated"] = "true"

# Match all the input files to their respective C# project.
input_files = [os.path.normpath(x) for x in sys.argv]
projects = {
path: [f for f in sys.argv if os.path.commonpath([f, path]) == path]
for path in [os.path.dirname(f) for f in glob.glob("**/*.csproj", recursive=True)]
}

# Run dotnet format on all projects with more than 0 modified files.
for path, files in projects.items():
if len(files) > 0:
command = f"dotnet format {path} --include {' '.join(files)}"
os.system(command)
37 changes: 0 additions & 37 deletions misc/scripts/dotnet_format.sh

This file was deleted.

2 changes: 1 addition & 1 deletion modules/mono/glue/GodotSharp/GodotSharp/GodotSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -142,5 +142,5 @@
We can't use wildcards as there may be undesired old files still hanging around.
Fortunately code completion, go to definition and such still work.
-->
<Import Project="Generated\GeneratedIncludes.props" />
<Import Condition=" '$(GodotSkipGenerated)' == '' " Project="Generated\GeneratedIncludes.props" />
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,5 @@
We can't use wildcards as there may be undesired old files still hanging around.
Fortunately code completion, go to definition and such still work.
-->
<Import Project="Generated\GeneratedIncludes.props" />
<Import Condition=" '$(GodotSkipGenerated)' == '' " Project="Generated\GeneratedIncludes.props" />
</Project>

0 comments on commit f2045ba

Please sign in to comment.