improve autoupdate

pull/3403/head
ruki 9 months ago
parent 066d49a635
commit 16d3ae4374
  1. 2
      .github/workflows/autoupdate.yml
  2. 29
      scripts/autoupdate.lua

@ -37,6 +37,6 @@ jobs:
- name: Auto-update packages
run: |
xmake l -vD scripts/autoupdate.lua 3
xmake l -vD scripts/autoupdate.lua

@ -14,12 +14,13 @@ function _load_package(packagename, packagedir, packagefile)
end
end
function _get_all_packages()
function _get_all_packages(pattern)
local packages = _g.packages
if not packages then
packages = {}
for _, packagedir in ipairs(os.dirs(path.join("packages", "*", "*"))) do
local packagename = path.filename(packagedir)
if not pattern or packagename:match(pattern) then
local packagefile = path.join(packagedir, "xmake.lua")
local instance = _load_package(packagename, packagedir, packagefile)
local basename = instance:get("base")
@ -32,6 +33,7 @@ function _get_all_packages()
table.insert(packages, instance)
end
end
end
_g.packages = packages
end
return packages
@ -82,33 +84,40 @@ function _update_version(instance, version, shasum)
instance:name(), version_current, version)
os.vexec("git add .")
os.vexec("git commit -a -m \"Update %s to %s\"", instance:name(), version)
os.vexec("git push %s %s:%s", repourl, branch, branch)
os.vexec("gh pr create --label \"auto-update\" --title \"Auto-update %s to %s\" --body \"%s\" -R xmake-io/xmake-repo -B dev -H %s",
instance:name(), version, body, branch)
--os.vexec("git push %s %s:%s", repourl, branch, branch)
--os.vexec("gh pr create --label \"auto-update\" --title \"Auto-update %s to %s\" --body \"%s\" -R xmake-io/xmake-repo -B dev -H %s",
-- instance:name(), version, body, branch)
end
os.vexec("git reset --hard HEAD")
os.vexec("git checkout %s", branch_current)
end
function main(maxcount)
function main(pattern)
local count = 0
local maxcount = tonumber(maxcount or 10)
local instances = _get_all_packages()
local maxcount = 3
local instances = _get_all_packages(pattern)
math.randomseed(os.time())
while count < maxcount do
local instance = instances[math.random(#instances)]
while count < maxcount and #instances > 0 do
local idx = math.random(#instances)
local instance = instances[idx]
local checkupdate_filepath = path.join(instance:scriptdir(), "checkupdate.lua")
if not os.isfile(checkupdate_filepath) then
checkupdate_filepath = path.join(os.scriptdir(), "checkupdate.lua")
end
local updated = false
if os.isfile(checkupdate_filepath) then
local checkupdate = import("checkupdate", {rootdir = path.directory(checkupdate_filepath), anonymous = true})
local version, shasum = checkupdate(instance)
if version and shasum and not _is_pending(instance, version) then
cprint("package(%s): new version ${bright}%s${clear} found, shasum: ${bright}%s", instance:name(), version, shasum)
_update_version(instance, version, shasum)
count = count + 1
updated = true
end
end
if updated then
count = count + 1
else
table.remove(instances, idx)
end
end
end

Loading…
Cancel
Save