Skip to content

Commit 528ac92

Browse files
committed
Update formatting script to use pre-commit and GitHub Actions
1 parent f3a63a3 commit 528ac92

File tree

6 files changed

+99
-60
lines changed

6 files changed

+99
-60
lines changed

.gitattributes

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,8 @@
1+
# Normalize EOL for all files that Git considers text files.
2+
* text=auto eol=lf
3+
# Except for Windows-only / Visual Studio files
4+
*.bat eol=crlf
5+
*.sln eol=crlf
6+
*.csproj eol=crlf
7+
18
*.hdr binary

.github/workflows/file_format.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
import sys
5+
6+
if len(sys.argv) < 2:
7+
print("Invalid usage of file_format.py, it should be called with a path to one or multiple files.")
8+
sys.exit(1)
9+
10+
BOM = b"\xef\xbb\xbf"
11+
12+
changed = []
13+
invalid = []
14+
15+
for file in sys.argv[1:]:
16+
try:
17+
with open(file, "rt", encoding="utf-8") as f:
18+
original = f.read()
19+
except UnicodeDecodeError:
20+
invalid.append(file)
21+
continue
22+
23+
if original == "":
24+
continue
25+
26+
EOL = "\r\n" if file.endswith((".csproj", ".sln", ".bat")) else "\n"
27+
WANTS_BOM = file.endswith((".csproj", ".sln"))
28+
29+
revamp = EOL.join([line.rstrip("\n\r\t ") for line in original.splitlines(True)]).rstrip(EOL) + EOL
30+
31+
new_raw = revamp.encode(encoding="utf-8")
32+
if not WANTS_BOM and new_raw.startswith(BOM):
33+
new_raw = new_raw[len(BOM) :]
34+
elif WANTS_BOM and not new_raw.startswith(BOM):
35+
new_raw = BOM + new_raw
36+
37+
with open(file, "rb") as f:
38+
old_raw = f.read()
39+
40+
if old_raw != new_raw:
41+
changed.append(file)
42+
with open(file, "wb") as f:
43+
f.write(new_raw)
44+
45+
if changed:
46+
for file in changed:
47+
print(f"FIXED: {file}")
48+
49+
if invalid:
50+
for file in invalid:
51+
print(f"REQUIRES MANUAL CHANGES: {file}")
52+
sys.exit(1)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: 📊 Static Checks
2+
on: [push, pull_request]
3+
4+
concurrency:
5+
group: ci-${{ github.actor }}-${{ github.head_ref || github.run_number }}-${{ github.ref }}-static
6+
7+
jobs:
8+
static-checks:
9+
name: Code style and file formatting
10+
runs-on: ubuntu-24.04
11+
steps:
12+
- name: Checkout
13+
uses: actions/checkout@v4
14+
with:
15+
fetch-depth: 2
16+
17+
- name: Install Python dependencies and general setup
18+
run: |
19+
git config diff.wsErrorHighlight all
20+
21+
- name: Style checks via pre-commit
22+
uses: pre-commit/[email protected]
23+
with:
24+
extra_args: --all-files

.pre-commit-config.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
default_language_version:
2+
python: python3
3+
4+
exclude: |
5+
(?x)^(
6+
CODE_OF_CONDUCT.md
7+
)
8+
9+
repos:
10+
- repo: local
11+
hooks:
12+
- id: file-format
13+
name: file-format
14+
language: python
15+
entry: python .github/workflows/file_format.py
16+
types_or: [text]

appveyor.yml

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,6 @@ configuration: Release
1010
environment:
1111
APPVEYOR_YML_DISABLE_PS_LINUX: true
1212

13-
install:
14-
- sh: |
15-
if [ "$(uname)" != "Darwin" ]; then
16-
sudo apt-get update -y
17-
sudo apt-get install -y dos2unix recode
18-
fi
19-
2013
build_script:
2114
- ps: |
2215
New-Item -Path . -Name "build" -ItemType "directory"
@@ -33,12 +26,6 @@ build_script:
3326
cmake --build . --config ${CONFIGURATION}
3427
cd ../
3528
36-
test_script:
37-
- sh: |
38-
if [ "$(uname)" != "Darwin" ]; then
39-
bash ./format.sh
40-
fi
41-
4229
artifacts:
4330
# Linux
4431
- path: bin/basisu

format.sh

Lines changed: 0 additions & 47 deletions
This file was deleted.

0 commit comments

Comments
 (0)