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:
Harrison Cramer
2026-01-30 21:54:00 -05:00
parent 7dba805f6a
commit 3d2828a950
61 changed files with 358 additions and 266 deletions

View File

@@ -63,8 +63,7 @@ M.sequence = function(dependencies, cb)
end
-- Otherwise, start the go server and start fetching the values
server.start(function()
state.go_server_running = true
server.build_and_start(function()
handler:fetch(dependencies, 1, argTable)
end)
end

View File

@@ -1,22 +1,9 @@
local state = require("gitlab.state")
local List = require("gitlab.utils.list")
local version = require("gitlab.version")
local u = require("gitlab.utils")
local M = {}
local function check_go_version()
local go_version = io.popen("go version"):read("*a")
if go_version then
local major, minor, _ = go_version:match("(%d+)%.(%d+)%.(%d+)")
if major and tonumber(major) >= 1 and tonumber(minor) >= 19 then
return
else
return "Go is installed, but version is older than 1.19."
end
else
return "Go is not installed."
end
end
---Checks the health of the plugin
---@param return_results boolean
M.check = function(return_results)
@@ -60,7 +47,7 @@ M.check = function(return_results)
},
}
local go_version_problem = check_go_version()
local go_version_problem = version.check_go_version()
if go_version_problem ~= nil then
table.insert(warnings, go_version_problem)
end

View File

@@ -12,6 +12,7 @@ local summary = require("gitlab.actions.summary")
local data = require("gitlab.actions.data")
local assignees_and_reviewers = require("gitlab.actions.assignees_and_reviewers")
local comment = require("gitlab.actions.comment")
local version = require("gitlab.version")
local pipeline = require("gitlab.actions.pipeline")
local create_mr = require("gitlab.actions.create_mr")
local approvals = require("gitlab.actions.approvals")
@@ -36,6 +37,13 @@ local function setup(args)
if args == nil then
args = {}
end
local version_issue = version.check_go_version()
if version_issue ~= nil then
u.notify(version_issue, vim.log.levels.ERROR)
return
end
server.build() -- Builds the Go binary if it doesn't exist
state.merge_settings(args) -- Merges user settings with default settings
state.set_global_keymaps() -- Sets keymaps that are not bound to a specific buffer

View File

@@ -4,7 +4,7 @@ local Job = require("plenary.job")
local u = require("gitlab.utils")
local M = {}
M.run_job = function(endpoint, method, body, callback, on_error_callback)
M.run_job = function(endpoint, method, body, callback)
local state = require("gitlab.state")
local args = { "-s", "-X", (method or "POST"), string.format("localhost:%s", state.settings.port) .. endpoint }
@@ -16,10 +16,8 @@ M.run_job = function(endpoint, method, body, callback, on_error_callback)
-- This handler will handle all responses from the Go server. Anything with a successful
-- status will call the callback (if it is supplied for the job). Otherwise, it will print out the
-- success message or error message and details from the Go server and run the on_error_callback
-- (if supplied for the job).
-- success message or error message and details from the Go server.
local stderr = {}
Job:new({
command = "curl",
args = args,
@@ -55,9 +53,6 @@ M.run_job = function(endpoint, method, body, callback, on_error_callback)
-- Handle error case
local message = string.format("%s: %s", data.message, data.details)
u.notify(message, vim.log.levels.ERROR)
if on_error_callback then
on_error_callback(data)
end
end
end, 0)
end,

View File

@@ -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

24
lua/gitlab/version.lua Normal file
View File

@@ -0,0 +1,24 @@
local M = {}
M.is_go_valid = function()
local go_version = io.popen("go version"):read("*a")
if go_version then
local major, minor, _ = go_version:match("(%d+)%.(%d+)%.?(%d*)")
if major and tonumber(major) >= 1 and tonumber(minor) >= 25 then
return true
else
return false
end
else
return false
end
end
M.check_go_version = function()
local has_version = M.is_go_valid()
if not has_version then
return "Go is not installed, or version is older than 1.25.1. Please reinstall up-to-date Go version: https://go.dev/dl/"
end
end
return M