Skip to content

Commit 5b10e85

Browse files
committed
Improve static checks by using pre-commit
The setup is taken from the main Godot repository.
1 parent 84eabb3 commit 5b10e85

File tree

58 files changed

+267
-354
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+267
-354
lines changed

.github/scripts/gitignore_check.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
set -uo pipefail
2+
shopt -s globstar
3+
4+
echo -e ".gitignore validation..."
5+
6+
# Get a list of files that exist in the repo but are ignored.
7+
8+
# The --verbose flag also includes files un-ignored via ! prefixes.
9+
# We filter those out with a somewhat awkward `awk` directive.
10+
# (Explanation: Split each line by : delimiters,
11+
# see if the actual gitignore line shown in the third field starts with !,
12+
# if it doesn't, print it.)
13+
14+
# ignorecase for the sake of Windows users.
15+
16+
output=$(git -c core.ignorecase=true check-ignore --verbose --no-index **/* | \
17+
awk -F ':' '{ if ($3 !~ /^!/) print $0 }')
18+
19+
# Then we take this result and return success if it's empty.
20+
if [ -z "$output" ]; then
21+
exit 0
22+
else
23+
# And print the result if it isn't.
24+
echo "$output"
25+
exit 1
26+
fi

.github/workflows/static_checks.yml

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,24 @@ jobs:
99
- name: Checkout
1010
uses: actions/checkout@v5
1111

12-
- name: Install dependencies
12+
# This needs to happen before Python and npm execution; it must happen before any extra files are written.
13+
- name: .gitignore checks (gitignore_check.sh)
1314
run: |
14-
sudo apt-get update -qq
15-
sudo apt-get install -qq dos2unix recode
15+
bash ./.github/scripts/gitignore_check.sh
1616
17-
- name: File formatting checks (file_format.sh)
17+
- name: Get changed files
18+
env:
19+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1820
run: |
19-
bash ./file_format.sh
21+
if [ "${{ github.event_name }}" == "pull_request" ]; then
22+
files=$(git diff-tree --no-commit-id --name-only -r HEAD^1..HEAD 2> /dev/null || true)
23+
elif [ "${{ github.event_name }}" == "push" -a "${{ github.event.forced }}" == "false" -a "${{ github.event.created }}" == "false" ]; then
24+
files=$(git diff-tree --no-commit-id --name-only -r ${{ github.event.before }}..${{ github.event.after }} 2> /dev/null || true)
25+
fi
26+
files=$(echo "$files" | xargs -I {} sh -c 'echo "\"./{}\""' | tr '\n' ' ')
27+
echo "CHANGED_FILES=$files" >> $GITHUB_ENV
28+
29+
- name: Style checks via pre-commit
30+
uses: pre-commit/action@v3.0.1
31+
with:
32+
extra_args: --files ${{ env.CHANGED_FILES }}

.pre-commit-config.yaml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
default_language_version:
2+
python: python3
3+
4+
repos:
5+
- repo: https://github.com/codespell-project/codespell
6+
rev: v2.4.1
7+
hooks:
8+
- id: codespell
9+
additional_dependencies: [tomli]
10+
11+
- repo: local
12+
hooks:
13+
- id: file-format
14+
name: file-format
15+
language: python
16+
entry: python file_format.py
17+
types_or: [text]
18+
exclude: |
19+
(?x)^(
20+
.*\.test\.txt|
21+
.*\.svg|
22+
)$
23+
24+
- id: dotnet-format
25+
name: dotnet-format
26+
language: python
27+
entry: python dotnet_format.py
28+
types_or: [c#]
29+
#
30+
# End of upstream Godot pre-commit hooks.
31+
#
32+
# Keep this separation to let downstream forks add their own hooks to this file,
33+
# without running into merge conflicts when rebasing on latest upstream.
34+
#
35+
# Start of downstream pre-commit hooks.
36+
#
37+
# This is still the "repo: local" scope, so new local hooks can be defined directly at this indentation:
38+
# - id: new-local-hook
39+
# To add external repo hooks, bring the indentation back to:
40+
# - repo: my-remote-hook

2d/particles/point_normal_texture_image_outline.tres

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,3 @@ data = {
1313
flags = 0
1414
image = SubResource( 1 )
1515
size = Vector2( 2048, 1 )
16-

2d/particles/point_texture_emit.tres

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,3 @@ image = SubResource( 1 )
1717
size = Vector2( 2048, 6 )
1818
storage = 0
1919
lossy_quality = 0.7
20-

2d/particles/point_texture_image_outline.tres

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,3 @@ data = {
1313
flags = 0
1414
image = SubResource( 1 )
1515
size = Vector2( 2048, 1 )
16-

2d/role_playing_game/grid_movement/grid/lines/grid_lines_tileset.tres

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,3 @@
1414
0/occluder_offset = Vector2( 32, 32 )
1515
0/navigation_offset = Vector2( 32, 32 )
1616
0/shapes = [ ]
17-

2d/role_playing_game/theme/fonts/montserrat_extra_bold_16.tres

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,3 @@ use_mipmaps = true
1010
use_filter = true
1111
font_data = ExtResource( 1 )
1212
_sections_unfolded = [ "Settings" ]
13-

2d/role_playing_game/theme/fonts/montserrat_extra_bold_24.tres

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,3 @@ use_mipmaps = true
1010
use_filter = true
1111
font_data = ExtResource( 1 )
1212
_sections_unfolded = [ "Settings" ]
13-

2d/role_playing_game/theme/fonts/montserrat_extra_bold_32.tres

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,3 @@ use_mipmaps = true
1010
use_filter = true
1111
font_data = ExtResource( 1 )
1212
_sections_unfolded = [ "Settings" ]
13-

0 commit comments

Comments
 (0)