feat!: MAJOR release. Update go to 1.25, and add migration path (#520)
BREAKING CHANGE: This bumps Go and external packages to later versions.
This commit is contained in:
@@ -5,8 +5,29 @@ local List = require("gitlab.utils.list")
|
||||
local state = require("gitlab.state")
|
||||
local u = require("gitlab.utils")
|
||||
local job = require("gitlab.job")
|
||||
local Job = require("plenary.job")
|
||||
local M = {}
|
||||
|
||||
-- Builds the binary if it doesn't exist, and starts the server. If the pre-existing binary has an older
|
||||
-- tag than the Lua code (exposed via the /version endpoint) then shuts down the server, rebuilds it, and
|
||||
-- restarts the server again.
|
||||
M.build_and_start = function(callback)
|
||||
M.build(false)
|
||||
M.start(function()
|
||||
M.get_version(function(version)
|
||||
if version.plugin_version ~= version.binary_version then
|
||||
M.shutdown(function()
|
||||
if M.build(true) then
|
||||
M.start(callback)
|
||||
end
|
||||
end)
|
||||
else
|
||||
callback()
|
||||
end
|
||||
end)
|
||||
end)
|
||||
end
|
||||
|
||||
-- Starts the Go server and call the callback provided
|
||||
M.start = function(callback)
|
||||
local port = tonumber(state.settings.port) or 0
|
||||
@@ -50,6 +71,7 @@ M.start = function(callback)
|
||||
-- Make sure that this actually check if port was correctly parsed based on server output
|
||||
-- because server outputs port only if it started successfully.
|
||||
if parsed_port ~= nil and not callback_called then
|
||||
state.go_server_running = true
|
||||
callback()
|
||||
callback_called = true
|
||||
end
|
||||
@@ -80,7 +102,7 @@ M.start = function(callback)
|
||||
end
|
||||
end
|
||||
|
||||
-- Builds the Go binary
|
||||
-- Builds the Go binary with the current Git tag.
|
||||
M.build = function(override)
|
||||
local file_path = u.current_file_path()
|
||||
local parent_dir = vim.fn.fnamemodify(file_path, ":h:h:h:h")
|
||||
@@ -96,8 +118,15 @@ M.build = function(override)
|
||||
end
|
||||
end
|
||||
|
||||
local version_output = vim.system({ "git", "describe", "--tags", "--always" }, { cwd = parent_dir }):wait()
|
||||
local version = version_output.code == 0 and vim.trim(version_output.stdout) or "unknown"
|
||||
|
||||
local ldflags = string.format("-X main.Version=%s", version)
|
||||
local res = vim
|
||||
.system({ "go", "build", "-o", bin_name }, { cwd = state.settings.root_path .. u.path_separator .. "cmd" })
|
||||
.system(
|
||||
{ "go", "build", "-ldflags", ldflags, "-o", bin_name },
|
||||
{ cwd = state.settings.root_path .. u.path_separator .. "cmd" }
|
||||
)
|
||||
:wait()
|
||||
|
||||
if res.code ~= 0 then
|
||||
@@ -134,7 +163,6 @@ M.restart = function(cb)
|
||||
job.run_job("/shutdown", "POST", { restart = true }, function(data)
|
||||
state.go_server_running = false
|
||||
M.start(function()
|
||||
state.go_server_running = true
|
||||
state.clear_data()
|
||||
if cb then
|
||||
cb()
|
||||
@@ -145,4 +173,44 @@ M.restart = function(cb)
|
||||
end)
|
||||
end
|
||||
|
||||
-- Returns the version (git tag) that was baked into the binary when it was last built
|
||||
M.get_version = function(callback)
|
||||
if not state.go_server_running then
|
||||
u.notify("Gitlab server not running", vim.log.levels.ERROR)
|
||||
return nil
|
||||
end
|
||||
local file_path = u.current_file_path()
|
||||
local parent_dir = vim.fn.fnamemodify(file_path, ":h:h:h:h")
|
||||
|
||||
local version_output = vim.system({ "git", "describe", "--tags", "--always" }, { cwd = parent_dir }):wait()
|
||||
local plugin_version = version_output.code == 0 and vim.trim(version_output.stdout) or "unknown"
|
||||
|
||||
local args = { "-s", "-X", "GET", string.format("localhost:%s/version", state.settings.port) }
|
||||
|
||||
-- We call the "/version" endpoint here instead of through the regular jobs pattern because earlier versions of the plugin
|
||||
-- may not have it. We handle a 404 as an "unknown" version error.
|
||||
Job:new({
|
||||
command = "curl",
|
||||
args = args,
|
||||
on_stdout = function(_, output)
|
||||
vim.defer_fn(function()
|
||||
if output == nil then
|
||||
callback({ plugin_version = plugin_version, binary_version = "unknown" })
|
||||
return
|
||||
end
|
||||
|
||||
local data_ok, data = pcall(vim.json.decode, output)
|
||||
if not data_ok or data == nil or data.version == nil then
|
||||
callback({ plugin_version = plugin_version, binary_version = "unknown" })
|
||||
return
|
||||
end
|
||||
|
||||
callback({ plugin_version = plugin_version, binary_version = data.version })
|
||||
end, 0)
|
||||
end,
|
||||
on_stderr = function() end,
|
||||
on_exit = function() end,
|
||||
}):start()
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
Reference in New Issue
Block a user