Skip to content

Commit

Permalink
Merge pull request #396 from vim-denops/check-support-version
Browse files Browse the repository at this point in the history
☕ Add `denops/supported-versions.json` and check if all information is updated
  • Loading branch information
lambdalisue authored Aug 3, 2024
2 parents 0608102 + de48a62 commit 06f471f
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 35 deletions.
10 changes: 7 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ jobs:
run: deno fmt --check
- name: Type check
run: deno task check
- name: Supported version inconsistency check
run: |
deno task apply:supported-versions
git diff --exit-code
test:
needs: check
Expand All @@ -50,8 +54,8 @@ jobs:
- windows-latest
- macos-latest
- ubuntu-latest
version:
- "1.45.x"
deno_version:
- "1.45.0"
- "1.x"
host_version:
- vim: "v9.1.0448"
Expand All @@ -67,7 +71,7 @@ jobs:

- uses: denoland/[email protected]
with:
deno-version: "${{ matrix.version }}"
deno-version: "${{ matrix.deno_version }}"

- uses: rhysd/action-setup-vim@v1
id: vim
Expand Down
102 changes: 102 additions & 0 deletions .scripts/apply_supported_versions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import supportedVersions from "../denops/supported_versions.json" with {
type: "json",
};

async function main(): Promise<void> {
await updateREADME();
await updatePluginDenops();
await updateGithubWorkflowsTest();
}

async function updateREADME(): Promise<void> {
const url = new URL(import.meta.resolve("../README.md"));
let text = await Deno.readTextFile(url);
// Deno
text = text.replace(
/Deno\s+\d+\.\d+\.\d+/,
`Deno ${supportedVersions.deno}`,
);
text = text.replace(
/Deno-Support%20\d+\.\d+\.\d+/,
`Deno-Support%20${supportedVersions.deno}`,
);
text = text.replace(
/https:\/\/github\.com\/denoland\/deno\/tree\/v\d+\.\d+\.\d+/,
`https://github.com/denoland/deno/tree/v${supportedVersions.deno}`,
);
// Vim
text = text.replace(
/Vim\s+\d+\.\d+\.\d+/,
`Vim ${supportedVersions.vim}`,
);
text = text.replace(
/Vim-Support%20\d+\.\d+\.\d+/,
`Vim-Support%20${supportedVersions.vim}`,
);
text = text.replace(
/https:\/\/github\.com\/vim\/vim\/tree\/v\d+\.\d+\.\d+/,
`https://github.com/vim/vim/tree/v${supportedVersions.vim}`,
);
// Neovim
text = text.replace(
/Neovim\s+\d+\.\d+\.\d+/,
`Neovim ${supportedVersions.neovim}`,
);
text = text.replace(
/Neovim-Support%20\d+\.\d+\.\d+/,
`Neovim-Support%20${supportedVersions.neovim}`,
);
text = text.replace(
/https:\/\/github\.com\/neovim\/neovim\/tree\/v\d+\.\d+\.\d+/,
`https://github.com/neovim/neovim/tree/v${supportedVersions.neovim}`,
);
await Deno.writeTextFile(url, text);
}

async function updatePluginDenops(): Promise<void> {
const url = new URL(import.meta.resolve("../plugin/denops.vim"));
let text = await Deno.readTextFile(url);
// Vim
text = text.replace(/patch-\d+\.\d+\.\d+/, `patch-${supportedVersions.vim}`);
text = text.replace(
/Vim\s+\d+\.\d+\.\d+/,
`Vim ${supportedVersions.vim}`,
);
// Neovim
text = text.replace(/nvim-\d+\.\d+\.\d+/, `nvim-${supportedVersions.neovim}`);
text = text.replace(
/Neovim\s+\d+\.\d+\.\d+/,
`Neovim ${supportedVersions.neovim}`,
);
await Deno.writeTextFile(url, text);
}

async function updateGithubWorkflowsTest(): Promise<void> {
const url = new URL(import.meta.resolve("../.github/workflows/test.yml"));
let text = await Deno.readTextFile(url);
// Deno
text = text.replace(
/deno_version:(.*?)"\d+\.\d+\.\d+"/s,
`deno_version:$1"${supportedVersions.deno}"`,
);
// Vim
text = text.replace(
/vim:(.*?)"v\d+\.\d+\.\d+"/s,
`vim:$1"v${supportedVersions.vim}"`,
);
// Neovim
text = text.replace(
/nvim:(.*?)"v\d+\.\d+\.\d+"/s,
`nvim:$1"v${supportedVersions.neovim}"`,
);
await Deno.writeTextFile(url, text);
}

if (import.meta.main) {
try {
await main();
} catch (error) {
console.error(error);
Deno.exit(1);
}
}
69 changes: 38 additions & 31 deletions autoload/health/denops.vim
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
const s:DENO_VERSION = '1.45.0'
const s:VIM_VERSION = '9.1.0448'
const s:NEOVIM_VERSION = '0.10.0'
const s:root = resolve(expand('<sfile>:p:h:h:h'))

function! s:compare_version(v1, v2) abort
let l:v1 = map(split(a:v1, '\.'), { _, v -> v + 0 })
let l:v2 = map(split(a:v2, '\.'), { _, v -> v + 0 })
const l:v1 = map(split(a:v1, '\.'), { _, v -> v + 0 })
const l:v2 = map(split(a:v2, '\.'), { _, v -> v + 0 })
for l:i in range(max([len(l:v1), len(l:v2)]))
let l:t1 = get(l:v1, l:i, 0)
let l:t2 = get(l:v2, l:i, 0)
Expand All @@ -15,8 +13,16 @@ function! s:compare_version(v1, v2) abort
return 0
endfunction

function! s:load_supported_versions() abort
const l:jsonfile = denops#_internal#path#join([s:root, 'denops', 'supported_versions.json'])
if !filereadable(l:jsonfile)
throw 'Failed to read <runtimepath>/denops/supported_versions.json'
endif
return json_decode(join(readfile(l:jsonfile), "\n"))
endfunction

function! s:get_deno_version(deno) abort
let l:output = system(printf('%s --version', a:deno))
const l:output = system(printf('%s --version', a:deno))
return matchstr(l:output, 'deno \zs[0-9.]\+')
endfunction

Expand All @@ -42,61 +48,49 @@ function! s:check_deno_executable() abort
call s:report_ok('Deno executable check: passed')
endfunction

function! s:check_deno_version() abort
let l:deno_version = s:get_deno_version(g:denops#deno)
call s:report_info(printf(
\ 'Supported Deno version: `%s`',
\ s:DENO_VERSION,
\))
function! s:check_deno_version(supported_version) abort
const l:deno_version = s:get_deno_version(g:denops#deno)
call s:report_info(printf(
\ 'Detected Deno version: `%s`',
\ l:deno_version,
\))
if empty(l:deno_version)
call s:report_error('Unable to detect version of deno, make sure your deno runtime is correct.')
return
elseif s:compare_version(l:deno_version, s:DENO_VERSION) < 0
elseif s:compare_version(l:deno_version, a:supported_version) < 0
call s:report_error(printf(
\ 'Unsupported Deno version is detected. You need to upgrade it to `%s` or later.',
\ s:DENO_VERSION,
\ a:supported_version,
\))
return
endif
call s:report_ok('Deno version check: passed')
endfunction

function! s:check_vim_version() abort
call s:report_info(printf(
\ 'Supported Vim version: `%s`',
\ s:VIM_VERSION,
\))
function! s:check_vim_version(supported_version) abort
call s:report_info(printf(
\ 'Detected Vim version: `%s`',
\ denops#_internal#meta#get().version,
\))
if !has(printf('patch-%s', s:VIM_VERSION))
if !has(printf('patch-%s', a:supported_version))
call s:report_error(printf(
\ 'Unsupported Vim version is detected. You need to upgrade it to `%s` or later.',
\ s:VIM_VERSION,
\ a:supported_version,
\))
return
endif
call s:report_ok('Vim version check: passed')
endfunction

function! s:check_neovim_version() abort
call s:report_info(printf(
\ 'Supported Neovim version: `%s`',
\ s:NEOVIM_VERSION,
\))
function! s:check_neovim_version(supported_version) abort
call s:report_info(printf(
\ 'Detected Neovim version: `%s`',
\ denops#_internal#meta#get().version,
\))
if !has(printf('nvim-%s', s:NEOVIM_VERSION))
if !has(printf('nvim-%s', a:supported_version))
call s:report_error(printf(
\ 'Unsupported Neovim version is detected. You need to upgrade it to `%s` or later.',
\ s:NEOVIM_VERSION,
\ a:supported_version,
\))
return
endif
Expand Down Expand Up @@ -157,11 +151,24 @@ else
endif

function! health#denops#check() abort
call s:check_deno_version()
const l:supported_versions = s:load_supported_versions()
call s:report_info(printf(
\ 'Supported Deno version: `%s`',
\ l:supported_versions.deno,
\))
call s:report_info(printf(
\ 'Supported Vim version: `%s`',
\ l:supported_versions.vim,
\))
call s:report_info(printf(
\ 'Supported Neovim version: `%s`',
\ l:supported_versions.neovim,
\))
call s:check_deno_version(l:supported_versions.deno)
if !has('nvim')
call s:check_vim_version()
call s:check_vim_version(l:supported_versions.vim)
else
call s:check_neovim_version()
call s:check_neovim_version(l:supported_versions.neovim)
endif
call s:check_denops()
call s:check_denops_status()
Expand Down
3 changes: 2 additions & 1 deletion deno.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"coverage": "deno coverage --exclude=\"test[.]ts(#.*)?$\" .coverage",
"update": "deno run --allow-env --allow-read --allow-write --allow-run=git,deno --allow-net=jsr.io,registry.npmjs.org jsr:@molt/cli **/*.ts",
"update:write": "deno task -q update --write",
"update:commit": "deno task -q update --commit --prefix :package: --pre-commit=fmt,lint"
"update:commit": "deno task -q update --commit --prefix :package: --pre-commit=fmt,lint",
"apply:supported-versions": "deno run --allow-read --allow-write .scripts/apply_supported_versions.ts"
},
"exclude": [
".coverage/"
Expand Down
5 changes: 5 additions & 0 deletions denops/supported_versions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"deno": "1.45.0",
"vim": "9.1.0448",
"neovim": "0.10.0"
}

0 comments on commit 06f471f

Please sign in to comment.