Skip to content

Commit

Permalink
Update rockspec and lua scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
lggruspe committed Sep 16, 2023
1 parent 8cf48e1 commit f7b909b
Show file tree
Hide file tree
Showing 14 changed files with 49 additions and 76 deletions.
14 changes: 5 additions & 9 deletions .github/workflows/lua.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,11 @@ jobs:

steps:
- uses: actions/checkout@v2
- uses: leafo/gh-actions-lua@v8.0.0
- uses: leafo/gh-actions-luarocks@v4.0.0
- uses: leafo/gh-actions-lua@v10.0.0
- uses: leafo/gh-actions-luarocks@v4.3.0
- name: Set up lua
run: |
luarocks install busted
luarocks install luacheck
- name: Lint with luacheck
cd filters; luarocks init; luarocks test --prepare
- name: Run tests and linters
run: |
cd filters; luacheck src/*.lua --std max+busted
- name: Test with busted
run: |
cd filters; busted src -p '.*.test.lua'
cd filters; luarocks test
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ init-js:

.PHONY: init-lua
init-lua:
cd filters; lua scripts/init.lua
cd filters; luarocks init; luarocks test --prepare

.PHONY: init-python
init-python:
Expand All @@ -41,7 +41,7 @@ check-js:

.PHONY: check-lua
check-lua:
cd filters; lua scripts/check.lua
cd filters; luarocks test

.PHONY: check-python
check-python: lint test
Expand Down
6 changes: 3 additions & 3 deletions filters/scripts/bundle.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
-- Bundle filters into a single-file.

local utils = require "scripts.utils"
local run = utils.run
require "scripts.path"

local exec = require("scripts.utils").exec
local lfs = require "lfs"

local function bundle()
Expand All @@ -20,7 +20,7 @@ local function bundle()
local command = "%s %s -s src/zk.lua -o build/filter.lua"
local prog = "lua_modules/bin/amalg.lua"
local args = table.concat(sources, " ")
run(command:format(prog, args))
exec(command:format(prog, args))
end

lfs.mkdir "build"
Expand Down
7 changes: 0 additions & 7 deletions filters/scripts/check.lua

This file was deleted.

16 changes: 0 additions & 16 deletions filters/scripts/init.lua

This file was deleted.

8 changes: 8 additions & 0 deletions filters/scripts/path.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-- Update package path to load from lua_modules.

local version = _VERSION:match "%d+%.%d+"

package.path = "lua_modules/share/lua/" .. version .. "/?/init.lua;" .. package.path
package.path = "lua_modules/share/lua/" .. version .. "/?.lua;" .. package.path
package.cpath = "lua_modules/lib/lua/" .. version .. "/?.so;" .. package.cpath
package.cpath = "lua_modules/lib64/lua/" .. version .. "/?.so;" .. package.cpath
6 changes: 6 additions & 0 deletions filters/scripts/test.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-- Run tests and linters.

local exec = require("scripts.utils").exec

exec "lua_modules/bin/busted"
exec "lua_modules/bin/luacheck src spec scripts"
31 changes: 7 additions & 24 deletions filters/scripts/utils.lua
Original file line number Diff line number Diff line change
@@ -1,28 +1,11 @@
-- Useful functions used in other scripts.

local function run(command)
-- Execute command and exit on error.
local ok, _, code = os.execute(command)
if not ok then
os.exit(code)
end
-- Executes command.
-- Raises an error on failure.
local function exec(command)
if not os.execute(command) then
error "command failed"
end
end

local updated = false

local function update_paths()
-- Include lua_modules/ in require path.
assert(not updated)
if not updated then
package.path = "lua_modules/share/lua/5.4/?.lua;" .. package.path
package.cpath = "lua_modules/lib/lua/5.4/?.so;" .. package.cpath
package.cpath = "lua_modules/lib64/lua/5.4/?.so;" .. package.cpath
updated = true
end
end

update_paths()

return {
run = run,
}
return {exec = exec}
Original file line number Diff line number Diff line change
@@ -1,24 +1,38 @@
rockspec_format = "3.0"
package = "slipbox-filters"
version = "0.1-1"
version = "dev-1"
source = {
url = "git+ssh://[email protected]/lggruspe/slipbox.git"
}
description = {
summary = "Lua filters used by slipbox",
homepage = "https://github.com/lggruspe/slipbox",
license = "MIT"
}
dependencies = {
"lua ~> 5.3"
"lua >= 5.1, < 5.5",
"dkjson"
}
test_dependencies = {
"amalg",
"busted",
"luacheck",
"luafilesystem"
}
build = {
type = "builtin",
modules = {
csv = "src/csv.lua",
errors = "src/errors.lua",
filters = "src/filters.lua",
log = "src/log.lua",
links = "src/links.lua",
metadata = "src/metadata.lua",
slipbox = "src/slipbox.lua",
utils = "src/utils.lua",
["utils.test"] = "src/utils.test.lua",
zk = "src/zk.lua"
}
}
test = {
type = "command",
script = "scripts/test.lua",
}
3 changes: 0 additions & 3 deletions filters/src/csv.test.lua → filters/spec/csv_spec.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
require "busted.runner" ()

local csv = require "src.csv"


describe("Writer", function()
describe("write", function()
describe("with wrong number of fields", function()
Expand Down
2 changes: 0 additions & 2 deletions filters/src/errors.test.lua → filters/spec/errors_spec.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require "busted.runner" ()

local errors = require "src.errors"

describe("duplicate_note_id", function()
Expand Down
2 changes: 0 additions & 2 deletions filters/src/links.test.lua → filters/spec/links_spec.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require "busted.runner" ()

local links = require "src.links"

local function join(table, sep)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require "busted.runner" ()

local metadata = require "src.metadata"

describe("parse", function()
Expand Down
2 changes: 0 additions & 2 deletions filters/src/utils.test.lua → filters/spec/utils_spec.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require "busted.runner" ()

local utils = require "src.utils"

it("hashtag_prefix", function()
Expand Down

0 comments on commit f7b909b

Please sign in to comment.