diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..8cc3e1f --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,39 @@ +name: CI + +on: [push, pull_request] + +jobs: + format: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Install Stylua + run: | + sudo apt-get update + sudo apt-get install -y stylua + + - name: Run Stylua + run: | + stylua --config-path .stylua.toml . --exclude lib/cc-tweaked + + static-analysis: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Install Lua-Language-Server + run: | + sudo apt-get update + sudo apt-get install -y lua-language-server + + - name: Run Lua-Language-Server + continue-on-error: true + run: | + lua-language-server --logpath . --check . + + - name: Parse Lua-Language-Server Output + run: | + lua parse_lua_ls_output.lua ./check.json diff --git a/.luarc.json b/.luarc.json index a32b301..e58ddbd 100644 --- a/.luarc.json +++ b/.luarc.json @@ -2,5 +2,6 @@ "workspace.library": [ "./lib/cc-tweaked/", "./lib/basalt/Basalt" - ] + ], + "diagnostics.libraryFiles": "Disable" } diff --git a/parse_lua_ls_output.lua b/parse_lua_ls_output.lua new file mode 100644 index 0000000..03aac4f --- /dev/null +++ b/parse_lua_ls_output.lua @@ -0,0 +1,41 @@ +local json = require("json") + +local function parse_lua_ls_output(file_path) + local output_file = io.open(file_path, "r") + if not output_file then + error("Failed to open " .. file_path) + end + + local output_data = output_file:read("*a") + output_file:close() + + local parsed_data = json.decode(output_data) + if not parsed_data then + error("Failed to parse JSON data") + end + + local has_issues = false + + for _, diagnostic in ipairs(parsed_data) do + print(string.format("File: %s", diagnostic.uri)) + for _, issue in ipairs(diagnostic.diagnostics) do + print(string.format(" Line: %d, Column: %d", issue.range.start.line, issue.range.start.character)) + print(string.format(" Message: %s", issue.message)) + print() + has_issues = true + end + end + + if has_issues then + os.exit(1) + else + os.exit(0) + end +end + +local file_path = arg[1] +if not file_path then + error("No file path provided") +end + +parse_lua_ls_output(file_path) diff --git a/stylua.toml b/stylua.toml new file mode 100644 index 0000000..4c70132 --- /dev/null +++ b/stylua.toml @@ -0,0 +1,13 @@ +# Stylua Configuration File + +# Indent settings +indent_type = "Spaces" +indent_width = 2 + +# Line settings +column_width = 80 + +# Exclude files and directories +exclude = { + "lib/cc-tweaked/**" +}