Skip to content

Commit f2045ba

Browse files
authored
Merge pull request #88933 from raulsntos/dotnet/pre-commit
Move dotnet-format script to pre-commit
2 parents dad6c77 + 97851f0 commit f2045ba

File tree

6 files changed

+38
-47
lines changed

6 files changed

+38
-47
lines changed

.github/workflows/static_checks.yml

-8
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,6 @@ jobs:
8888
run: |
8989
doc/tools/doc_status.py doc/classes modules/*/doc_classes platform/*/doc_classes
9090
91-
- name: Style checks via dotnet format (dotnet_format.sh)
92-
run: |
93-
if grep -q "modules/mono" changed.txt || [ -z "$(cat changed.txt)" ]; then
94-
bash ./misc/scripts/dotnet_format.sh
95-
else
96-
echo "Skipping dotnet format as no C# files were changed."
97-
fi
98-
9991
- name: Spell checks via codespell
10092
if: github.event_name == 'pull_request' && env.CHANGED_FILES != ''
10193
uses: codespell-project/actions-codespell@v2

.pre-commit-config.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,9 @@ repos:
4747
platform/android/java/lib/src/org/godotengine/godot/gl/EGLLogWrapper.*|
4848
platform/android/java/lib/src/org/godotengine/godot/utils/ProcessPhoenix.*
4949
)
50+
51+
- id: dotnet-format
52+
name: dotnet-format
53+
language: python
54+
entry: python3 misc/scripts/dotnet_format.py
55+
types_or: [c#]

misc/scripts/dotnet_format.py

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
import glob
5+
import os
6+
import sys
7+
8+
# Create dummy generated files.
9+
for path in [
10+
"modules/mono/SdkPackageVersions.props",
11+
]:
12+
os.makedirs(os.path.dirname(path), exist_ok=True)
13+
with open(path, "w") as f:
14+
f.write("<Project />")
15+
16+
# Avoid importing GeneratedIncludes.props.
17+
os.environ["GodotSkipGenerated"] = "true"
18+
19+
# Match all the input files to their respective C# project.
20+
input_files = [os.path.normpath(x) for x in sys.argv]
21+
projects = {
22+
path: [f for f in sys.argv if os.path.commonpath([f, path]) == path]
23+
for path in [os.path.dirname(f) for f in glob.glob("**/*.csproj", recursive=True)]
24+
}
25+
26+
# Run dotnet format on all projects with more than 0 modified files.
27+
for path, files in projects.items():
28+
if len(files) > 0:
29+
command = f"dotnet format {path} --include {' '.join(files)}"
30+
os.system(command)

misc/scripts/dotnet_format.sh

-37
This file was deleted.

modules/mono/glue/GodotSharp/GodotSharp/GodotSharp.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,5 +142,5 @@
142142
We can't use wildcards as there may be undesired old files still hanging around.
143143
Fortunately code completion, go to definition and such still work.
144144
-->
145-
<Import Project="Generated\GeneratedIncludes.props" />
145+
<Import Condition=" '$(GodotSkipGenerated)' == '' " Project="Generated\GeneratedIncludes.props" />
146146
</Project>

modules/mono/glue/GodotSharp/GodotSharpEditor/GodotSharpEditor.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,5 @@
4444
We can't use wildcards as there may be undesired old files still hanging around.
4545
Fortunately code completion, go to definition and such still work.
4646
-->
47-
<Import Project="Generated\GeneratedIncludes.props" />
47+
<Import Condition=" '$(GodotSkipGenerated)' == '' " Project="Generated\GeneratedIncludes.props" />
4848
</Project>

0 commit comments

Comments
 (0)