mirror of
https://github.com/neovim/neovim.git
synced 2024-12-24 05:05:00 -07:00
refactor: eliminate bump-deps.sh using "nvim -l"
This commit is contained in:
parent
b741788a3a
commit
7fc5d6ea50
@ -64,7 +64,7 @@ Third-party dependencies
|
||||
------------------------
|
||||
|
||||
These "bundled" dependencies can be updated by bumping their versions in `cmake.deps/CMakeLists.txt`.
|
||||
Some can be auto-bumped by `scripts/bump-deps.sh`.
|
||||
Some can be auto-bumped by `scripts/bump_deps.lua`.
|
||||
|
||||
* [LuaJIT](https://github.com/LuaJIT/LuaJIT)
|
||||
* [Lua](https://www.lua.org/download.html)
|
||||
|
@ -1,108 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
set -u
|
||||
# Use privileged mode, which e.g. skips using CDPATH.
|
||||
set -p
|
||||
|
||||
# Ensure that the user has a bash that supports -A
|
||||
if [[ "${BASH_VERSINFO[0]}" -lt 4 ]]; then
|
||||
echo >&2 "error: script requires bash 4+ (you have ${BASH_VERSION})."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
readonly NVIM_SOURCE_DIR="${NVIM_SOURCE_DIR:-$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)}"
|
||||
readonly VIM_SOURCE_DIR_DEFAULT="${NVIM_SOURCE_DIR}/.vim-src"
|
||||
readonly VIM_SOURCE_DIR="${VIM_SOURCE_DIR:-${VIM_SOURCE_DIR_DEFAULT}}"
|
||||
BASENAME="$(basename "${0}")"
|
||||
readonly BASENAME
|
||||
|
||||
usage() {
|
||||
echo "Bump Nvim dependencies"
|
||||
echo
|
||||
echo "Usage: ${BASENAME} [ -h | --pr | --branch=<dep> | --dep=<dependency> ]"
|
||||
echo " Update a dependency:"
|
||||
echo " ./scripts/bump-deps.sh --dep Luv --version 1.43.0-0"
|
||||
echo " Create a PR:"
|
||||
echo " ./scripts/bump-deps.sh --pr"
|
||||
echo
|
||||
echo "Options:"
|
||||
echo " -h show this message and exit."
|
||||
echo " --pr submit pr for bumping deps."
|
||||
echo " --branch=<dep> create a branch bump-<dep> from current branch."
|
||||
echo " --dep=<dependency> bump to a specific release or tag."
|
||||
echo
|
||||
echo "Dependency Options:"
|
||||
echo " --version=<tag> bump to a specific release or tag."
|
||||
echo " --commit=<hash> bump to a specific commit."
|
||||
echo " --HEAD bump to a current head."
|
||||
echo
|
||||
echo " <dependency> is one of:"
|
||||
echo " \"LuaJIT\", \"libuv\", \"Luv\", \"tree-sitter\""
|
||||
}
|
||||
|
||||
# Checks if a program is in the user's PATH, and is executable.
|
||||
check_executable() {
|
||||
test -x "$(command -v "${1}")"
|
||||
}
|
||||
|
||||
require_executable() {
|
||||
if ! check_executable "${1}"; then
|
||||
echo >&2 "${BASENAME}: '${1}' not found in PATH or not executable."
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
require_executable "nvim"
|
||||
|
||||
if [ $# -eq 0 ]; then
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
|
||||
PARSED_ARGS=$(getopt -a -n "$BASENAME" -o h --long pr,branch:,dep:,version:,commit:,HEAD -- "$@")
|
||||
|
||||
DEPENDENCY=""
|
||||
eval set -- "$PARSED_ARGS"
|
||||
while :; do
|
||||
case "$1" in
|
||||
-h)
|
||||
usage
|
||||
exit 0
|
||||
;;
|
||||
--pr)
|
||||
nvim -es +"lua require('scripts.bump_deps').submit_pr()"
|
||||
exit 0
|
||||
;;
|
||||
--branch)
|
||||
DEP=$2
|
||||
nvim -es +"lua require('scripts.bump_deps').create_branch('$DEP')"
|
||||
exit 0
|
||||
;;
|
||||
--dep)
|
||||
DEPENDENCY=$2
|
||||
shift 2
|
||||
;;
|
||||
--version)
|
||||
VERSION=$2
|
||||
nvim -es +"lua require('scripts.bump_deps').version('$DEPENDENCY', '$VERSION')"
|
||||
exit 0
|
||||
;;
|
||||
--commit)
|
||||
COMMIT=$2
|
||||
nvim -es +"lua require('scripts.bump_deps').commit('$DEPENDENCY', '$COMMIT')"
|
||||
exit 0
|
||||
;;
|
||||
--HEAD)
|
||||
nvim -es +"lua require('scripts.bump_deps').head('$DEPENDENCY')"
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
break
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
usage
|
||||
exit 1
|
||||
|
||||
# vim: et sw=2
|
118
scripts/bump_deps.lua
Normal file → Executable file
118
scripts/bump_deps.lua
Normal file → Executable file
@ -1,18 +1,7 @@
|
||||
#!/usr/bin/env -S nvim -l
|
||||
|
||||
-- Usage:
|
||||
-- # bump to version
|
||||
-- nvim -es +"lua require('scripts.bump_deps').version(dependency, version_tag)"
|
||||
--
|
||||
-- # bump to commit
|
||||
-- nvim -es +"lua require('scripts.bump_deps').commit(dependency, commit_hash)"
|
||||
--
|
||||
-- # bump to HEAD
|
||||
-- nvim -es +"lua require('scripts.bump_deps').head(dependency)"
|
||||
--
|
||||
-- # submit PR
|
||||
-- nvim -es +"lua require('scripts.bump_deps').submit_pr()"
|
||||
--
|
||||
-- # create branch
|
||||
-- nvim -es +"lua require('scripts.bump_deps').create_branch()"
|
||||
-- ./scripts/bump_deps.lua -h
|
||||
|
||||
local M = {}
|
||||
|
||||
@ -128,7 +117,10 @@ local function get_archive_info(repo, ref)
|
||||
'Failed to download archive from GitHub'
|
||||
)
|
||||
|
||||
local archive_sha = run({ 'sha256sum', archive_path }):gmatch('%w+')()
|
||||
local shacmd = (vim.fn.executable('sha256sum') == 1
|
||||
and{ 'sha256sum', archive_path }
|
||||
or { 'shasum', '-a', '256', archive_path })
|
||||
local archive_sha = run(shacmd):gmatch('%w+')()
|
||||
return { url = archive_url, sha = archive_sha }
|
||||
end
|
||||
|
||||
@ -171,7 +163,7 @@ end
|
||||
local function verify_branch(new_branch_suffix)
|
||||
require_executable('git')
|
||||
|
||||
local checked_out_branch = run({ 'git', 'rev-parse', '--abbrev-ref', 'HEAD' })
|
||||
local checked_out_branch = assert(run({ 'git', 'rev-parse', '--abbrev-ref', 'HEAD' }))
|
||||
if not checked_out_branch:match('^' .. required_branch_prefix) then
|
||||
p(
|
||||
"Current branch '"
|
||||
@ -244,7 +236,7 @@ end
|
||||
local function find_git_remote(fork)
|
||||
require_executable('git')
|
||||
|
||||
local remotes = run({ 'git', 'remote', '-v' })
|
||||
local remotes = assert(run({ 'git', 'remote', '-v' }))
|
||||
local git_remote = ''
|
||||
for remote in remotes:gmatch('[^\r\n]+') do
|
||||
local words = {}
|
||||
@ -295,7 +287,7 @@ local function create_pr(pr_title, pr_body)
|
||||
end
|
||||
|
||||
function M.commit(dependency_name, commit)
|
||||
local dependency = get_dependency(dependency_name)
|
||||
local dependency = assert(get_dependency(dependency_name))
|
||||
verify_cmakelists_committed()
|
||||
local commit_sha = get_gh_commit_sha(dependency.repo, commit)
|
||||
if commit_sha ~= commit then
|
||||
@ -310,7 +302,11 @@ function M.commit(dependency_name, commit)
|
||||
end
|
||||
|
||||
function M.version(dependency_name, version)
|
||||
local dependency = get_dependency(dependency_name)
|
||||
vim.validate{
|
||||
dependency_name={dependency_name,'s'},
|
||||
version={version,'s'},
|
||||
}
|
||||
local dependency = assert(get_dependency(dependency_name))
|
||||
verify_cmakelists_committed()
|
||||
local commit_sha = get_gh_commit_sha(dependency.repo, version)
|
||||
if commit_sha == version then
|
||||
@ -325,7 +321,7 @@ function M.version(dependency_name, version)
|
||||
end
|
||||
|
||||
function M.head(dependency_name)
|
||||
local dependency = get_dependency(dependency_name)
|
||||
local dependency = assert(get_dependency(dependency_name))
|
||||
verify_cmakelists_committed()
|
||||
local commit_sha = get_gh_commit_sha(dependency.repo, 'HEAD')
|
||||
local archive = get_archive_info(dependency.repo, commit_sha)
|
||||
@ -345,7 +341,7 @@ function M.submit_pr()
|
||||
verify_branch('deps')
|
||||
|
||||
local nvim_remote = find_git_remote(nil)
|
||||
local relevant_commit = run_die({
|
||||
local relevant_commit = assert(run_die({
|
||||
'git',
|
||||
'log',
|
||||
'--grep=' .. commit_prefix,
|
||||
@ -353,7 +349,7 @@ function M.submit_pr()
|
||||
"--format='%s'",
|
||||
nvim_remote .. '/master..HEAD',
|
||||
'-1',
|
||||
}, 'Failed to fetch commits')
|
||||
}, 'Failed to fetch commits'))
|
||||
|
||||
local pr_title
|
||||
local pr_body
|
||||
@ -371,4 +367,80 @@ function M.submit_pr()
|
||||
create_pr(pr_title, pr_body)
|
||||
end
|
||||
|
||||
return M
|
||||
local function usage()
|
||||
local this_script = _G.arg[0]:match("[^/]*.lua$")
|
||||
print(([=[
|
||||
Bump Nvim dependencies
|
||||
|
||||
Usage: nvim -l %s [options]
|
||||
Bump to HEAD, tagged version, commit, or branch:
|
||||
nvim -l %s --dep Luv --head
|
||||
nvim -l %s --dep Luv --version 1.43.0-0
|
||||
nvim -l %s --dep Luv --commit abc123
|
||||
nvim -l %s --dep Luv --branch
|
||||
Create a PR:
|
||||
nvim -l %s --pr
|
||||
|
||||
Options:
|
||||
-h show this message and exit.
|
||||
--pr submit pr for bumping deps.
|
||||
--branch <dep> create a branch bump-<dep> from current branch.
|
||||
--dep <dependency> bump to a specific release or tag.
|
||||
|
||||
Dependency Options:
|
||||
--version <tag> bump to a specific release or tag.
|
||||
--commit <hash> bump to a specific commit.
|
||||
--HEAD bump to a current head.
|
||||
|
||||
<dependency> is one of:
|
||||
"LuaJIT", "libuv", "Luv", "tree-sitter"
|
||||
]=]):format(this_script, this_script, this_script, this_script, this_script, this_script))
|
||||
end
|
||||
|
||||
local function parseargs()
|
||||
local args = {}
|
||||
for i = 1, #_G.arg do
|
||||
if _G.arg[i] == '-h' then
|
||||
args.h = true
|
||||
elseif _G.arg[i] == '--pr' then
|
||||
args.pr = true
|
||||
elseif _G.arg[i] == '--branch' then
|
||||
args.branch = _G.arg[i+1]
|
||||
elseif _G.arg[i] == '--dep' then
|
||||
args.dep = _G.arg[i+1]
|
||||
elseif _G.arg[i] == '--version' then
|
||||
args.version = _G.arg[i+1]
|
||||
elseif _G.arg[i] == '--commit' then
|
||||
args.commit = _G.arg[i+1]
|
||||
elseif _G.arg[i] == '--head' then
|
||||
args.head = true
|
||||
end
|
||||
end
|
||||
return args
|
||||
end
|
||||
|
||||
local is_main = _G.arg[0]:match('bump_deps.lua')
|
||||
|
||||
if is_main then
|
||||
local args = parseargs()
|
||||
if args.h then
|
||||
usage()
|
||||
elseif args.pr then
|
||||
M.submit_pr()
|
||||
elseif args.head then
|
||||
M.head(args.dep)
|
||||
elseif args.branch then
|
||||
M.create_branch(args.dep)
|
||||
elseif args.version then
|
||||
M.version(args.dep, args.version)
|
||||
elseif args.commit then
|
||||
M.commit(args.dep, args.commit)
|
||||
elseif args.pr then
|
||||
M.submit_pr()
|
||||
else
|
||||
print('missing required arg\n')
|
||||
os.exit(1)
|
||||
end
|
||||
else
|
||||
return M
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user