Skip to content

Commit

Permalink
ci: initial CI configuration + added tools for quality standards
Browse files Browse the repository at this point in the history
  • Loading branch information
wojciech-kulik committed Feb 27, 2024
1 parent 5b6b724 commit e16af8d
Show file tree
Hide file tree
Showing 14 changed files with 285 additions and 68 deletions.
58 changes: 58 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Linting, Style, And Error Checking

on:
push:
branches: ["main"]
pull_request:
branches: ["main"]

jobs:
lint:
name: Linting
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Prepare
run: |
brew update
brew install luacheck
- name: Lint
run: make lint

format-check:
name: Format Check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Prepare
run: |
brew update
brew install stylua
- name: Check
run: make format-check

lsp-check:
name: LSP Error Check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Prepare
run: |
brew update
brew install lua-language-server
- name: Check
run: make lsp-check

help-check:
name: Help Check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Prepare
run: cargo install lemmy-help --features=cli

- name: Check
run: make help-check
30 changes: 30 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Run Tests

on:
push:
branches: ["main"]
pull_request:
branches: ["main"]

jobs:
unit-tests:
name: Unit Tests
strategy:
fail-fast: false
matrix:
nvim-version: ["stable", "nightly"]
os: ["ubuntu-latest"]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4

- name: Install Neovim
uses: rhysd/action-setup-vim@v1
with:
neovim: true
version: ${{ matrix.nvim-version }}

- name: Run tests
run: |
nvim --version
make test
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,5 @@ tools/src/getsnapshots.xcodeproj/xcuserdata
tools/src/getsnapshots.xcodeproj/xcshareddata/xcschemes/getsnapshots.xcscheme
specs/test_data/*.vim
doc/tags
luals-out
.tests
3 changes: 3 additions & 0 deletions .luarc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"diagnostics.globals": ["vim", "require", "describe", "it", "P"]
}
89 changes: 42 additions & 47 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,48 +1,43 @@
all: lint format-check lsp-check help-check test

# Checks warnings and errors in code using linter
lint:
luacheck lua

gendocs:
lemmy-help \
--layout compact:0 \
--indent 2 \
-f -t -a -c \
./lua/xcodebuild/init.lua \
./lua/xcodebuild/docs/features.lua \
./lua/xcodebuild/docs/requirements.lua \
./lua/xcodebuild/docs/highlights.lua \
./lua/xcodebuild/docs/keybindings.lua \
./lua/xcodebuild/docs/commands.lua \
./lua/xcodebuild/docs/global_variables.lua \
./lua/xcodebuild/actions.lua \
./lua/xcodebuild/core/constants.lua \
./lua/xcodebuild/core/autocmd.lua \
./lua/xcodebuild/core/config.lua \
./lua/xcodebuild/core/quickfix.lua \
./lua/xcodebuild/core/xcode.lua \
./lua/xcodebuild/xcode_logs/parser.lua \
./lua/xcodebuild/xcode_logs/panel.lua \
./lua/xcodebuild/project/config.lua \
./lua/xcodebuild/project/appdata.lua \
./lua/xcodebuild/project/builder.lua \
./lua/xcodebuild/project/manager.lua \
./lua/xcodebuild/platform/device.lua \
./lua/xcodebuild/platform/device_proxy.lua \
./lua/xcodebuild/broadcasting/events.lua \
./lua/xcodebuild/broadcasting/notifications.lua \
./lua/xcodebuild/tests/diagnostics.lua \
./lua/xcodebuild/tests/enumeration_parser.lua \
./lua/xcodebuild/tests/explorer.lua \
./lua/xcodebuild/tests/provider.lua \
./lua/xcodebuild/tests/runner.lua \
./lua/xcodebuild/tests/search.lua \
./lua/xcodebuild/tests/snapshots.lua \
./lua/xcodebuild/code_coverage/coverage.lua \
./lua/xcodebuild/code_coverage/report.lua \
./lua/xcodebuild/integrations/dap.lua \
./lua/xcodebuild/integrations/remote_debugger.lua \
./lua/xcodebuild/integrations/lsp.lua \
./lua/xcodebuild/integrations/nvim-tree.lua \
./lua/xcodebuild/ui/pickers.lua \
./lua/xcodebuild/helpers.lua \
./lua/xcodebuild/util.lua \
> doc/xcodebuild.txt
luacheck -q lua

# Formats code
format:
stylua lua

# Checks if code is formatted
format-check:
stylua --check lua

# Checks errors in code using LSP
lsp-check:
scripts/luals-check.sh

# Check if help is up-to-date
help-check:
scripts/update-help.sh
git diff --exit-code doc/xcodebuild.txt

# Updates help file
help-update:
scripts/update-help.sh
git add doc/xcodebuild.txt

# Runs tests
test:
nvim --headless --noplugin -u scripts/minimal_init.lua -c "PlenaryBustedDirectory specs/ { minimal_init = './scripts/minimal_init.lua' }"

# Installs dependencies for plugin usage
install:
brew update --quiet
brew install --quiet xcbeautify xcode-build-server
python3 -m pip install -U pymobiledevice3 --quiet
gem install --quiet xcodeproj

# Installs dependencies for development
install-dev: install
brew install --quiet luacheck lua-language-server stylua
cargo install lemmy-help --features=cli --quiet
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ gem install xcodeproj
python3 -m pip install -U pymobiledevice3
```

To quickly install all required tools you can run:

```shell
make install
```

> [!TIP]
> Make sure to check out [Tips & Tricks](https://github.com/wojciech-kulik/xcodebuild.nvim/discussions/categories/tips-tricks)!
>
Expand Down
11 changes: 7 additions & 4 deletions doc/xcodebuild.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1487,6 +1487,9 @@ AppData *xcodebuild.project.appdata.AppData*
{snapshots_dir} (string) # The path to the snapshots directory.
{coverage_filepath} (string) # The path to the coverage file.
{coverage_report_filepath} (string) # The path to the coverage report file.
{GETSNAPSHOTS_TOOL} (string) # The name of the getsnapshots tool.
{PROJECT_HELPER_TOOL} (string) # The name of the project helper tool.
{REMOTE_DEBUGGER_TOOL} (string) # The name of the remote debugger tool.


M.tool_path({name}) *xcodebuild.project.appdata.tool_path*
Expand Down Expand Up @@ -3486,7 +3489,7 @@ M.contains({array}, {value}) *xcodebuild.util.contains*
Checks if an array contains a value.

Parameters: ~
{array} (any[])
{array} (any[]|nil)
{value} (any)


Expand All @@ -3501,12 +3504,12 @@ M.find({array}, {predicate}) *xcodebuild.util.find*
(any)


M.call({fn}) *xcodebuild.util.call*
Calls {fn} with arguments if {fn} is not nil.
M.call({callback}) *xcodebuild.util.call*
Calls {callback} with arguments if {callback} is not nil.
Returns the result of the function call.

Parameters: ~
{fn} (function|nil) @vararg any
{callback} (function|nil) @vararg any

Returns: ~
(any)
Expand Down
7 changes: 0 additions & 7 deletions lua/.luarc.json

This file was deleted.

4 changes: 2 additions & 2 deletions lua/xcodebuild/tests/explorer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ local spinnerFrames = { "⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧",
local currentFrame = 1
local last_updated_id = nil
local line_to_test = {}
local last_run_tests = {}
local collapsed_ids = {}
local ns = vim.api.nvim_create_namespace("xcodebuild-test-explorer")
local last_run_tests = {}

---Generates the report for provided tests.
---Sets the `M.report` variable.
Expand Down Expand Up @@ -524,7 +524,7 @@ function M.start_tests(selectedTests)
return
end

last_run_tests = selectedTests
last_run_tests = selectedTests or {}

for _, target in ipairs(M.report) do
for _, class in ipairs(target.classes) do
Expand Down
1 change: 1 addition & 0 deletions lua/xcodebuild/tests/runner.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ local M = {}
local CANCELLED_CODE = 143

---Validates if test plan is set in the project configuration.
---Send an error notification if not found.
---@return boolean
local function validate_testplan()
if not projectConfig.settings.testPlan then
Expand Down
18 changes: 10 additions & 8 deletions lua/xcodebuild/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,13 @@ function M.has_prefix(text, prefix)
end

---Checks if an array contains a value.
---@param array any[]
---@param array any[]|nil
---@param value any
function M.contains(array, value)
if not array then
return false
end

for _, val in ipairs(array) do
if val == value then
return true
Expand All @@ -246,16 +250,14 @@ function M.find(array, predicate)
return nil
end

---Calls {fn} with arguments if {fn} is not nil.
---Calls {callback} with arguments if {callback} is not nil.
---Returns the result of the function call.
---@param fn function|nil
---@param callback function|nil
---@vararg any
---@return any
function M.call(fn, ...)
local args = { ... }

if fn then
return fn(unpack(args))
function M.call(callback, ...)
if callback then
return callback(...)
end
end

Expand Down
38 changes: 38 additions & 0 deletions scripts/luals-check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/sh

# Performs a lua-language-server check on all files.
# luals-out/check.json will be produced on any issues, returning 1.
# Outputs only check.json to stdout, all other messages to stderr, to allow jq etc.

DIR_SRC="lua"
DIR_OUT="scripts/luals-out"

# clear output
rm -rf "${DIR_OUT}"
mkdir "${DIR_OUT}"

# execute inside lua to prevent luals itself from being checked
OUT=$(lua-language-server --check="${DIR_SRC}" --configpath="${PWD}/.luarc.json" --checklevel=Information --logpath="${DIR_OUT}" --loglevel=error)
RC=$?

echo "${OUT}" >&2

if [ $RC -ne 0 ]; then
echo "failed with RC=$RC"
exit $RC
fi

# any output is a fail
case "${OUT}" in
*Diagnosis\ complete*)
if [ -f "${DIR_OUT}/check.json" ]; then
cat "${DIR_OUT}/check.json"
exit 1
else
exit 0
fi
;;
*)
exit 1
;;
esac
40 changes: 40 additions & 0 deletions scripts/minimal_init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
local M = {}

---@param root string|nil
---@return string
function M.root(root)
local f = debug.getinfo(1, "S").source:sub(2)
return vim.fn.fnamemodify(f, ":p:h:h") .. "/" .. (root or "")
end

---@param plugin string
function M.install(plugin)
local name = plugin:match(".*/(.*)")
local package_root = M.root(".tests/site/pack/deps/start/")
if not vim.loop.fs_stat(package_root .. name) then
print("Installing " .. plugin)
vim.fn.mkdir(package_root, "p")
vim.fn.system({
"git",
"clone",
"--depth=1",
"https://github.com/" .. plugin .. ".git",
package_root .. "/" .. name,
})
end
end

function M.setup()
vim.cmd([[set runtimepath=$VIMRUNTIME]])
vim.opt.runtimepath:append(M.root())
vim.opt.packpath = { M.root(".tests/site") }
vim.env.XDG_CONFIG_HOME = M.root(".tests/config")
vim.env.XDG_DATA_HOME = M.root(".tests/data")
vim.env.XDG_STATE_HOME = M.root(".tests/state")
vim.env.XDG_CACHE_HOME = M.root(".tests/cache")

M.install("nvim-lua/plenary.nvim")
vim.cmd([[packadd plenary.nvim]])
end

M.setup()
Loading

0 comments on commit e16af8d

Please sign in to comment.