Skip to content

Commit

Permalink
improve to check pending
Browse files Browse the repository at this point in the history
  • Loading branch information
waruqi committed Jan 10, 2024
1 parent 2b837d8 commit a25cf41
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions scripts/autoupdate.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,9 @@ function _get_all_packages()
return packages
end

function _update_version(instance, version, shasum)
function _is_pending(instance, version)
local branch = "autoupdate-" .. instance:name() .. "-" .. version
local branch_current = os.iorun("git branch --show-current"):trim()
local repourl = "https://github.com/xmake-io/xmake-repo.git"
os.vexec("git reset --hard HEAD")
os.execv("git", {"branch", "-D", branch}, {try = true})
os.vexec("git checkout dev")
os.vexec("git pull %s dev", repourl)
os.vexec("git branch %s", branch)
os.vexec("git checkout %s", branch)
local is_pending = false
local remote_branches = os.iorun("git ls-remote --head %s", repourl)
if remote_branches then
Expand All @@ -58,6 +51,19 @@ function _update_version(instance, version, shasum)
end
end
end
return is_pending
end

function _update_version(instance, version, shasum)
local branch = "autoupdate-" .. instance:name() .. "-" .. version
local branch_current = os.iorun("git branch --show-current"):trim()
local repourl = "https://github.com/xmake-io/xmake-repo.git"
os.vexec("git reset --hard HEAD")
os.execv("git", {"branch", "-D", branch}, {try = true})
os.vexec("git checkout dev")
os.vexec("git pull %s dev", repourl)
os.vexec("git branch %s", branch)
os.vexec("git checkout %s", branch)
local scriptfile = path.join(instance:scriptdir(), "xmake.lua")
if os.isfile(scriptfile) and not is_pending then
local inserted = false
Expand Down Expand Up @@ -94,7 +100,7 @@ function main(maxcount)
if os.isfile(checkupdate_filepath) and count < maxcount then
local checkupdate = import("checkupdate", {rootdir = path.directory(checkupdate_filepath), anonymous = true})
local version, shasum = checkupdate(instance)
if version and shasum then
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
Expand Down

0 comments on commit a25cf41

Please sign in to comment.