2020-06-25 21:55:55 +02:00
|
|
|
|
|
|
|
-- the rewrite rule for the framework
|
|
|
|
-- should be something like this
|
|
|
|
-- ^\/apps\/+(.*)$ = /apps/router.lua?r=<1>&<query>
|
|
|
|
-- some global variables
|
2020-06-26 00:21:11 +02:00
|
|
|
function fail(msg)
|
|
|
|
std.json()
|
|
|
|
std.t(JSON.encode({error=msg}))
|
|
|
|
end
|
|
|
|
|
|
|
|
function result(obj)
|
|
|
|
std.json()
|
|
|
|
std.t(JSON.encode({result=obj, error=false}))
|
|
|
|
end
|
2020-06-25 21:55:55 +02:00
|
|
|
DIR_SEP = "/"
|
|
|
|
WWW_ROOT = __ROOT__.."/ci"
|
|
|
|
if HEADER.Host then
|
|
|
|
HTTP_ROOT= "https://"..HEADER.Host
|
|
|
|
else
|
|
|
|
HTTP_ROOT = "https://ci.iohub.dev"
|
|
|
|
end
|
|
|
|
-- class path: path.to.class
|
|
|
|
BASE_FRW = ""
|
|
|
|
-- class path: path.to.class
|
2020-06-26 00:21:11 +02:00
|
|
|
CONTROLLER_ROOT = BASE_FRW.."ci.controllers"
|
|
|
|
MODEL_ROOT = BASE_FRW.."ci.models"
|
2020-06-25 21:55:55 +02:00
|
|
|
-- file path: path/to/file
|
|
|
|
VIEW_ROOT = WWW_ROOT..DIR_SEP.."views"
|
|
|
|
LOG_ROOT = WWW_ROOT..DIR_SEP.."logs"
|
|
|
|
|
|
|
|
-- require needed library
|
|
|
|
require(BASE_FRW.."silk.api")
|
|
|
|
|
|
|
|
function NotfoundController:index(...)
|
|
|
|
local args = {...}
|
2020-06-26 00:21:11 +02:00
|
|
|
if #args == 0 then
|
|
|
|
fail("Unknown action")
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
local action = args[1]
|
|
|
|
if action == "BuildController" then
|
|
|
|
if REQUEST.json then
|
|
|
|
local request = JSON.decodeString(REQUEST.json)
|
|
|
|
if request.ref and request.ref == "refs/heads/ci" then
|
|
|
|
local branch = "ci"
|
|
|
|
local repository = request.repository.name
|
|
|
|
local path = WWW_ROOT..DIR_SEP.."scripts"..DIR_SEP..repository..".sh"
|
|
|
|
|
|
|
|
if ulib.exists(path) then
|
2020-06-26 01:34:09 +02:00
|
|
|
result("Build action triggered, log file will soon be available at: https://ci.iohub.dev/log/"..repository.."_"..branch..".txt")
|
|
|
|
os.execute("at now -f "..path)
|
2020-06-26 00:21:11 +02:00
|
|
|
else
|
|
|
|
fail("No build script found")
|
|
|
|
end
|
|
|
|
else
|
|
|
|
result("This action is ignored by the CI")
|
|
|
|
end
|
|
|
|
else
|
|
|
|
fail("Unknow action parameters")
|
|
|
|
end
|
|
|
|
else
|
|
|
|
fail("Action not supported: "..action)
|
|
|
|
end
|
2020-06-25 21:55:55 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
-- registry object store global variables
|
|
|
|
local REGISTRY = {}
|
|
|
|
-- set logging level
|
|
|
|
REGISTRY.logger = Logger:new{ levels = {INFO = false, ERROR = false, DEBUG = false}}
|
|
|
|
|
|
|
|
REGISTRY.layout = 'default'
|
2020-06-26 00:21:11 +02:00
|
|
|
REGISTRY.fileaccess = true
|
2020-06-25 21:55:55 +02:00
|
|
|
|
|
|
|
local router = Router:new{registry = REGISTRY}
|
|
|
|
REGISTRY.router = router
|
|
|
|
router:setPath(CONTROLLER_ROOT)
|
|
|
|
--router:route('edit', 'post/edit', "ALL" )
|
|
|
|
|
|
|
|
router:route('default', default_routes_dependencies )
|
|
|
|
router:delegate()
|
|
|
|
|