diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..6b39fd1 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,22 @@ +# This is a basic workflow that is manually triggered + +name: Format Check + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +jobs: + format_check: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - name: Set up Python 3.10 + uses: actions/setup-python@v3 + with: + python-version: "3.10" + - name: Check Format + run: python3 "format_check.py" diff --git a/.gitignore b/.gitignore index 7d09eeb..4b4cd6a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ zig-out zig-cache +.zig-cache .vscode -zig-out.tar.gz \ No newline at end of file +zig-out.tar.gz diff --git a/format_check.py b/format_check.py new file mode 100644 index 0000000..d14c713 --- /dev/null +++ b/format_check.py @@ -0,0 +1,44 @@ +import os + +import sys + +directory = os.fsencode(".") + +fails = 0 + +for subdir, dirs, files in os.walk("."): + for file in files: + #print os.path.join(subdir, file) + filepath = subdir + os.sep + file + if filepath.startswith("./compiler"): continue + if filepath.startswith("./saves"): continue + if filepath.startswith("./serverAssets"): continue + if filepath.startswith("./zig-cache"): continue + if filepath.startswith("./.zig-cache"): continue + + if filepath.endswith(".json") or filepath.endswith(".zig") or filepath.endswith(".py") or filepath.endswith(".zon") or filepath.endswith(".vs") or filepath.endswith(".fs") or filepath.endswith(".glsl"): + with open(filepath, "r", newline = '') as f: + string = f.read() + line = 1 + lineStart = True + for i, c in enumerate(string): + if(c == '\r'): + print("Incorrect line ending \\r in file ", filepath, " in line ", line, ". Please configure your editor to use LF instead of CRLF.") + fails += 1 + elif(c == '\n'): + line += 1 + lineStart = True + elif(c == ' '): + if(lineStart): + print("Incorrect indentation in file ", filepath, " in line ", line, ". Please use tabs instead of spaces.") + fails += 1 + lineStart = False # avoid repeating this error multiple times + elif(c == '\t'): + continue + elif(lineStart): + lineStart = False + else: + continue +if(fails != 0): + sys.exit(1) +sys.exit(0)