1
0
mirror of https://github.com/lxsang/antd-web-apps synced 2024-11-20 02:18:20 +01:00

add auto script

This commit is contained in:
lxsang 2020-06-26 00:21:11 +02:00
parent 41b25648ac
commit 2bf45c6cc2
4 changed files with 77 additions and 7 deletions

View File

@ -1,4 +1,4 @@
copyfiles = router.lua
copyfiles = router.lua scripts log
main:
- mkdir $(BUILDDIR)

View File

@ -3,6 +3,15 @@
-- should be something like this
-- ^\/apps\/+(.*)$ = /apps/router.lua?r=<1>&<query>
-- some global variables
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
DIR_SEP = "/"
WWW_ROOT = __ROOT__.."/ci"
if HEADER.Host then
@ -13,8 +22,8 @@ end
-- class path: path.to.class
BASE_FRW = ""
-- class path: path.to.class
CONTROLLER_ROOT = BASE_FRW.."apps.controllers"
MODEL_ROOT = BASE_FRW.."apps.models"
CONTROLLER_ROOT = BASE_FRW.."ci.controllers"
MODEL_ROOT = BASE_FRW.."ci.models"
-- file path: path/to/file
VIEW_ROOT = WWW_ROOT..DIR_SEP.."views"
LOG_ROOT = WWW_ROOT..DIR_SEP.."logs"
@ -24,8 +33,44 @@ require(BASE_FRW.."silk.api")
function NotfoundController:index(...)
local args = {...}
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
local cmd = "/bin/bash "..path.." "..branch
print(cmd)
local handle = io.popen(cmd)
local f = io.open(WWW_ROOT..DIR_SEP.."log"..DIR_SEP..repository.."_"..branch..".txt", "w")
for line in handle:lines() do
f:write(line)
end
handle:close()
f:close()
result("Build done, log file: https://ci.iohub.dev/log/"..repository.."_"..branch..".txt")
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
end
-- registry object store global variables
@ -34,7 +79,7 @@ local REGISTRY = {}
REGISTRY.logger = Logger:new{ levels = {INFO = false, ERROR = false, DEBUG = false}}
REGISTRY.layout = 'default'
REGISTRY.fileaccess = false
REGISTRY.fileaccess = true
local router = Router:new{registry = REGISTRY}
REGISTRY.router = router

25
ci/scripts/antos.sh Normal file
View File

@ -0,0 +1,25 @@
#! /bin/bash
BRANCH="master"
REPO="https://github.com/lxsang/antos.git"
DEST="/opt/www/htdocs/os"
if [ ! -z $1 ]; then
BRANCH="$1"
fi
echo "Build date: $(date)"
echo "Building AntOS using branch $BRANCH..."
if [ -d "/tmp/ci" ]; then
echo "Clean up /tmp/ci"
rm -rf /tmp/ci/*
else
echo "Creating /tmp/ci"
mkdir -p "/tmp/ci"
fi
cd /tmp/ci || (echo "Unable to change directory to /tmp/ci" && exit 1)
echo "Cloning Antos (branch $BRANCH) to /tmp/ci..."
git clone -b "$BRANCH" --single-branch --depth=1 "$REPO"
npm i @types/jquery
cd antos || (echo "Unable to change directory to source code folder" && exit 1)
BUILDDIR="$DEST" make release
echo "Done!"

View File

@ -13,8 +13,8 @@ end
-- class path: path.to.class
BASE_FRW = ""
-- class path: path.to.class
CONTROLLER_ROOT = BASE_FRW.."apps.controllers"
MODEL_ROOT = BASE_FRW.."apps.models"
CONTROLLER_ROOT = BASE_FRW.."get.controllers"
MODEL_ROOT = BASE_FRW.."get.models"
-- file path: path/to/file
VIEW_ROOT = WWW_ROOT..DIR_SEP.."views"
LOG_ROOT = WWW_ROOT..DIR_SEP.."logs"