Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

far-bisect: use GitHub releases as builds source #17

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
20 changes: 15 additions & 5 deletions Macros/scripts/far-bisect/far-bisect.cfg
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
-- highlight: lua

local base = [[C:\Shmuel_Home\BB\F\Today\Far\Archive\Versions\]]
FarArchives = {
x86 = { [[C:\Shmuel_Home\BB\F\Today\Far\Archive\Versions\1.75\x86]],
[[C:\Shmuel_Home\BB\F\Today\Far\Archive\Versions\2.0\x86]],
[[C:\Shmuel_Home\BB\F\Today\Far\Archive\Versions\3.0\x86]] };
x86 = { base..[[1.75\x86]],
base..[[2.0\x86]],
base..[[3.0\x86]] };

x64 = { [[C:\Shmuel_Home\BB\F\Today\Far\Archive\Versions\2.0\x64]],
[[C:\Shmuel_Home\BB\F\Today\Far\Archive\Versions\3.0\x64]] };
x64 = { base..[[2.0\x64]],
base..[[3.0\x64]] };
}

PlugArchives = [[S:\Progr\published\luaforge_github\LuaFAR\releases]]
Expand All @@ -18,3 +19,12 @@ InstallDir = [[%TEMP%\Fartest]]
Wget = [[C:\Shmuel_Home\Programs\EXE32\wget\wget.exe]]
FarNightlyPage = [[https://farmanager.com/nightly.php]]
FarNightlyDir = [[https://farmanager.com/nightly/]]

-- required: gh.exe from https://cli.github.com/
-- Ref:
-- * https://docs.github.com/en/rest/releases
-- * https://jqlang.github.io/jq/manual/
local gh = "gh"
ListReleasesCmd = gh ..[[ api -X GET "repos/FarGroup/FarManager/releases?per_page=100" --jq ".[] | .name, (.assets.[].browser_download_url | select(.|test(\"7z$\") and (test(\"\\.pdb\") or test(\"ARM64\")|not)))"]]
ListFileTmp = [[github.releases.tmp]]
ListFile = [[github.releases]]
88 changes: 69 additions & 19 deletions Macros/scripts/far-bisect/far-bisect.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ local Info = {
Title = Title;
}

local ThisDir = (...):match(".+\\")
local ThisDir = (_filename or ...):match(".+\\")
local Opt = {}
do
local fOpt, fOptMsg = loadfile(ThisDir.."far-bisect.cfg")
Expand Down Expand Up @@ -61,11 +61,13 @@ local START_DEFAULT_FARCONFIG = 2917 -- Default.farconfig invented
local START_LUAFARSTABLE = 3300 -- LuaFAR and Macro API become more or less stable
local START_LUAPREFIX = 3880 -- command line prefix "lua:" instead of "macro:post"
local START_BIGREFACTOR_DONE = 3924 -- completion of refactoring started in 3896
local START_GITHUB = 5342 -- first available at Github release


-- indexes into the dialog's combobox: must be consecutive and start with 1
local INDEX_FAR1, INDEX_FAR2, INDEX_FAR3,
INDEX_LUAMACRO, INDEX_LUAFARSTABLE,
INDEX_BIGREFACTOR = 1,2,3,4,5,6
INDEX_BIGREFACTOR, INDEX_GITHUB = 1,2,3,4,5,6,7

local MinBuilds = {
[INDEX_FAR1 ] = nil;
Expand All @@ -74,6 +76,7 @@ local MinBuilds = {
[INDEX_LUAMACRO ] = START_LUAMACRO;
[INDEX_LUAFARSTABLE ] = START_LUAFARSTABLE;
[INDEX_BIGREFACTOR ] = START_BIGREFACTOR_DONE;
[INDEX_GITHUB ] = START_GITHUB;
}

local PLUG_LF4ED = { ApiName="lf4ed"; Dir="lf4ed"; }
Expand Down Expand Up @@ -130,6 +133,7 @@ local function create_dialog_items()
[INDEX_LUAMACRO ] = {Text=">= 3.0.2851 (LuaMacro)"};
[INDEX_LUAFARSTABLE ] = {Text=">= 3.0.3300 (LuaFAR stable)"};
[INDEX_BIGREFACTOR ] = {Text=">= 3.0.3924 (Big Refactoring completed)"};
[INDEX_GITHUB ] = {Text=">= 3.0.5342 (First release at Github)"};
}; },
------------------------------------------------------------------------------
{tp="text"; text="&Command line arguments:"; },
Expand Down Expand Up @@ -498,11 +502,11 @@ function State:Test_build(build)
if self.macrocode and self.macrocode:find("%S") then
if build >= 1515 then -- Mantis#0001338: Префикс в параметрах ком.строки
local macrocode = (build < START_LUAPREFIX and "macro:post " or "lua:")..self.macrocode
cmdline = ('%s "%s"'):format(cmdline, macrocode)
cmdline = ('%s "%s"'):format(cmdline, macrocode:gsub('"','\\"'))
end
end
if cmdline:find("^%S") then cmdline = " "..cmdline; end
cmdline = ("cd %s && Far.exe%s"):format(install_path, cmdline)
cmdline = ("cd /D %s && Far.exe%s"):format(install_path, cmdline)
-- /compose command line for Far.exe
while true do
panel.GetUserScreen()
Expand Down Expand Up @@ -543,12 +547,49 @@ function State:Make_Local_Build_List(arch)
end)
end
if buildlist[1] == nil then
far.Message("No Far builds are found.", Title, nil, "w")
mf.exit()
--far.Message("No Far builds are found.", Title, nil, "w") --fixme
--mf.exit()
end
return buildlist
end

local function parseGithubList(fname,arch,map)
local build, overlap
local first = true
for line in io.lines(fname) do
local b = line:match"^v3%.0%.(%d+)"
if b then
b = assert(tonumber(b,10),b)
build = map[b] and "skip" or b
if first then overlap = map[b]; first = false end
elseif build~="skip" then
if line:match("."..arch..".",1,true) then
map[build] = line
build = "skip"
end
end
end
return overlap
end

function State:Make_Github_Build_List(arch)
if not Opt.ListReleasesCmd then return end

local map = {}
local fname = Opt.InstallDir.."\\"..Opt.ListFileTmp
win.system(Opt.ListReleasesCmd..">"..fname)
parseGithubList(fname,arch,map)

fname = Opt.ListFile:find":" and Opt.ListFile or ThisDir..Opt.ListFile
if win.GetFileAttr(fname) then
local overlap = parseGithubList(fname,arch,map)
if not overlap then
far.Message("'github.releases' file needs to be updated!", Title, nil, "w")
end
end
return map
end

function State:Make_Web_Build_List(arch)
local fname = Opt.InstallDir.."\\"..Opt.FarNightlyPage:match("[^/]+$")
win.DeleteFile(fname) -- prevent wget from creating files with suffixes
Expand All @@ -567,7 +608,7 @@ function State:Make_Web_Build_List(arch)
for name, build, date in page:gmatch(patt) do
build = tonumber(build)
if not dates[build] or dates[build] > date then
map[build] = name
map[build] = Opt.FarNightlyDir..name
dates[build] = date
end
end
Expand All @@ -577,10 +618,10 @@ end
function State:MakeBuildList(arch)
local buildlist = self:Make_Local_Build_List(arch)
if self.web ~= "none" then
local map = self:Make_Web_Build_List(arch) or {}
local map = State:Make_Github_Build_List(arch) or self:Make_Web_Build_List(arch) or {}
for build,name in pairs(map) do
if not self.mArchiveMap[build] then
self.mArchiveMap[build] = Opt.FarNightlyDir .. name
self.mArchiveMap[build] = name
table.insert(buildlist, build)
end
end
Expand Down Expand Up @@ -672,17 +713,26 @@ function State:Main()
end
end

Macro {
description=Title;
area="Shell"; key=MacroKey;
action=function()
local data = get_data_from_dialog()
if data then CreateState(data):Main(); end
end;
}

package.loaded["farbisect"] = {
local M = {
FAR1_OFFSET = FAR1_OFFSET;
AUTO_GOOD = AUTO_GOOD;
Main = function(data) mf.postmacro(function() CreateState(data):Main() end) end;
}

local function dlgBisect()
local data = get_data_from_dialog()
if data then CreateState(data):Main(); end
end

if Macro then
package.loaded["farbisect"] = M
Macro {
description=Title;
area="Shell"; key=MacroKey;
action=dlgBisect;
}
elseif _cmdline then
mf.postmacro(dlgBisect)
else
return M
end
20 changes: 20 additions & 0 deletions Macros/scripts/far-bisect/update.github.releases.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
@echo off
set file=github.releases
set GH=gh
set max=100
del %file%
echo Recreating %file% database...

setlocal enabledelayedexpansion
set lastsize=0
for /l %%x in (1, 1, %max%) do (
echo %%x..
%GH% api -X GET "repos/FarGroup/FarManager/releases?page=%%x&per_page=100" --jq ".[] | .name, (.assets.[].browser_download_url | select(.|test(\"7z$\") and (test(\"\\.pdb\") or test(\"ARM64\")|not)))">>%file%
call :setsize %file%
if !size!==!lastsize! goto :eof
set lastsize=!size!
)
goto :eof

:setsize
set size=%~z1