Skip to content

Commit b1980a7

Browse files
authored
perf(commons): migrate to commons library (#129)
1 parent cef50cc commit b1980a7

33 files changed

+2611
-730
lines changed

.github/workflows/ci.yml

Lines changed: 24 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -15,61 +15,56 @@ jobs:
1515
if: ${{ github.ref != 'refs/heads/main' }}
1616
runs-on: ubuntu-latest
1717
steps:
18-
- name: Checkout
19-
uses: actions/checkout@v4
18+
- uses: actions/checkout@v4
2019
- uses: ytanikin/[email protected]
2120
with:
2221
task_types: '["feat","fix","docs","test","ci","refactor","perf","chore","revert","break"]'
2322
luacheck:
2423
name: Lua check
2524
runs-on: ubuntu-latest
2625
steps:
27-
- name: Checkout
28-
uses: actions/checkout@v4
29-
- name: Luacheck
30-
uses: lunarmodules/luacheck@v1
26+
- uses: actions/checkout@v4
27+
- uses: lunarmodules/luacheck@v1
3128
with:
3229
args: lua --config .luacheckrc
33-
- name: Stylua
34-
uses: JohnnyMorganz/stylua-action@v3
30+
- name: Install commons.nvim
31+
shell: bash
32+
if: ${{ github.ref != 'refs/heads/main' }}
33+
run: |
34+
git clone --depth=1 https://github.com/linrongbin16/commons.nvim.git ~/.commons.nvim
35+
rm -rf ./lua/colorbox/commons
36+
mkdir -p ./lua/colorbox/commons
37+
cp -rf ~/.commons.nvim/lua/commons/*.lua ./lua/colorbox/commons
38+
cd ./lua/colorbox/commons
39+
find . -type f -name '*.lua' -exec sed -i 's/require("commons/require("colorbox.commons/g' {} \;
40+
- uses: JohnnyMorganz/stylua-action@v3
3541
with:
3642
token: ${{ secrets.GITHUB_TOKEN }}
3743
version: latest
38-
args: --config-path .stylua.toml ./lua
39-
- name: Add json.lua
44+
args: --config-path .stylua.toml ./lua ./test
45+
- uses: stefanzweifel/git-auto-commit-action@v4
4046
if: ${{ github.ref != 'refs/heads/main' }}
41-
shell: bash
42-
run: |
43-
echo "pwd"
44-
echo $PWD
45-
git clone --depth=1 https://github.com/actboy168/json.lua.git ~/.json.lua
46-
cp ~/.json.lua/json.lua ./lua/colorbox/actboy168_json.lua
47-
- name: Auto Commit
48-
if: ${{ github.ref != 'refs/heads/main' }}
49-
uses: stefanzweifel/git-auto-commit-action@v4
5047
with:
5148
commit_message: "chore(pr): auto-commit"
5249
unit_test:
5350
name: Unit Test
51+
needs:
52+
- luacheck
5453
strategy:
5554
matrix:
5655
nvim_version: [stable, nightly, v0.8.0]
5756
runs-on: ubuntu-latest
5857
steps:
59-
- name: Checkout
60-
uses: actions/checkout@v4
61-
- name: Install neovim
62-
uses: rhysd/action-setup-vim@v1
58+
- uses: actions/checkout@v4
59+
- uses: rhysd/action-setup-vim@v1
6360
id: vim
6461
with:
6562
neovim: true
6663
version: ${{ matrix.nvim_version }}
67-
- name: Install luajit
68-
uses: leafo/gh-actions-lua@v10
64+
- uses: leafo/gh-actions-lua@v10
6965
with:
7066
luaVersion: "luajit-2.1.0-beta3"
71-
- name: Install luarocks
72-
uses: leafo/gh-actions-luarocks@v4
67+
- uses: leafo/gh-actions-luarocks@v4
7368
- name: Run test cases
7469
shell: bash
7570
run: |
@@ -89,8 +84,7 @@ jobs:
8984
ls -l .
9085
echo "cat ./luacov.report.out"
9186
cat ./luacov.report.out
92-
- name: Upload coverage reports to Codecov
93-
uses: codecov/codecov-action@v3
87+
- uses: codecov/codecov-action@v3
9488
with:
9589
files: luacov.report.out
9690
env:
@@ -99,7 +93,6 @@ jobs:
9993
name: Release
10094
if: ${{ github.ref == 'refs/heads/main' }}
10195
needs:
102-
- luacheck
10396
- unit_test
10497
runs-on: ubuntu-latest
10598
steps:
@@ -116,14 +109,13 @@ jobs:
116109
message: "Current stable release: ${{ steps.release.outputs.tag_name }}"
117110
tag_exists_error: false
118111
force_push_tag: true
119-
- name: LuaRocks Upload
112+
- name: Upload LuaRocks
120113
uses: nvim-neorocks/luarocks-tag-release@v5
121114
if: ${{ steps.release.outputs.release_created }}
122115
env:
123116
LUAROCKS_API_KEY: ${{ secrets.LUAROCKS_API_KEY }}
124117
with:
125118
version: ${{ steps.release.outputs.tag_name }}
126-
summary: "Load all the ultra colorschemes into your Neovim player!"
127119
labels: |
128120
vim
129121
neovim

.luacheckrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ globals = { "vim", "describe", "before_each", "it", "assert" }
22
max_line_length = 200
33
unused = false
44
unused_args = false
5+
exclude_files = { "lua/colorbox/commons/*.lua" }

.luacov

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ modules = {
33
["colorbox.*"] = "lua",
44
}
55
exclude = {
6-
"lua/colorbox/rxi_json.lua",
6+
"lua/colorbox/commons/*.lua",
77
}
88

.luarc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"diagnostics.globals": ["vim", "describe", "before_each", "it"],
2+
"diagnostics.globals": ["vim", "describe", "before_each", "it", "jit"],
33
"workspace.checkThirdParty": "Disable"
44
}

.styluaignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
lua/colorbox/commons/*.lua

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
<!-- query a github file last update timestamp: https://stackoverflow.com/a/50204589/4438921 -->
44

55
<p align="center">
6-
<a href="https://github.com/neovim/neovim/releases/v0.8.0"><img alt="Neovim" src="https://img.shields.io/badge/Neovim-v0.8-57A143?logo=neovim&logoColor=57A143" /></a>
7-
<a href="https://luarocks.org/modules/linrongbin16/colorbox.nvim"><img alt="luarocks" src="https://custom-icon-badges.demolab.com/luarocks/v/linrongbin16/colorbox.nvim?label=LuaRocks&labelColor=063B70&logo=tag&logoColor=fff&color=008B8B" /></a>
6+
<a href="https://github.com/neovim/neovim/releases/v0.8.0"><img alt="Neovim" src="https://img.shields.io/badge/Neovim-v0.8+-57A143?logo=neovim&logoColor=57A143" /></a>
7+
<a href="https://github.com/linrongbin16/commons.nvim"><img alt="commons.nvim" src="https://custom-icon-badges.demolab.com/badge/Powered_by-commons.nvim-teal?logo=heart&logoColor=fff&labelColor=red" /></a>
8+
<a href="https://luarocks.org/modules/linrongbin16/colorbox.nvim"><img alt="luarocks" src="https://custom-icon-badges.demolab.com/luarocks/v/linrongbin16/colorbox.nvim?label=LuaRocks&labelColor=2C2D72&logo=tag&logoColor=fff&color=blue" /></a>
89
<a href="https://github.com/linrongbin16/gitlinker.nvim/actions/workflows/ci.yml"><img alt="ci.yml" src="https://img.shields.io/github/actions/workflow/status/linrongbin16/colorbox.nvim/ci.yml?label=GitHub%20CI&labelColor=181717&logo=github&logoColor=fff" /></a>
910
<a href="https://app.codecov.io/github/linrongbin16/colorbox.nvim"><img alt="codecov" src="https://img.shields.io/codecov/c/github/linrongbin16/colorbox.nvim?logo=codecov&logoColor=F01F7A&label=Codecov" /></a>
10-
<a href="https://github.com/linrongbin16/gitlinker.nvim/actions/workflows/collect.yml"><img alt="collect.yml" src="https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fapi.github.com%2Frepos%2Flinrongbin16%2Fcolorbox.nvim%2Fcommits%3Fpath%3Dcollect.py.log%26page%3D1%26per_page%3D1&query=%24%5B0%5D.commit.committer.date&logo=githubactions&logoColor=fff&label=Last%20Update&labelColor=2F4F4F" /></a>
1111
</p>
1212

1313
I'm greedy that I want all the **most popular** Neovim colorschemes than only one, I'm playful that I want to change colorscheme from time to time. Are you like me?

codecov.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ coverage:
77
default:
88
threshold: 90%
99
ignore:
10-
- "lua/colorbox/rxi_json.lua"
10+
- "lua/colorbox/commons/*.lua"

collect.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ def download_git_object(self) -> bool:
295295
f"{candidate_dir} exist: {candidate_dir.exists()}, isdir: {candidate_dir.is_dir()}"
296296
)
297297
if candidate_dir.exists() and candidate_dir.is_dir():
298-
logging.info(f"{candidate_dir} already exist, skip...")
298+
logging.debug(f"{candidate_dir} already exist, skip...")
299299
else:
300300
logging.debug(clone_cmd)
301301
os.system(clone_cmd)
@@ -399,16 +399,16 @@ def fetch(self) -> None:
399399
spec = self._parse_spec(element)
400400
logging.debug(f"vsc repo:{spec}")
401401
if len(spec.handle.split("/")) != 2:
402-
logging.info(f"skip for invalid handle - (vcs) spec:{spec}")
402+
logging.debug(f"skip for invalid handle - (vcs) spec:{spec}")
403403
continue
404404
if spec.github_stars < GITHUB_STARS:
405-
logging.info(f"skip for lower stars - (vcs) spec:{spec}")
405+
logging.debug(f"skip for lower stars - (vcs) spec:{spec}")
406406
continue
407-
logging.info(f"get (vcs) spec:{spec}")
407+
logging.debug(f"get (vcs) spec:{spec}")
408408
need_more_scan = True
409409
spec.save()
410410
if not need_more_scan:
411-
logging.info(f"no more enough github stars, exit...")
411+
logging.debug(f"no more enough github stars, exit...")
412412
break
413413

414414

@@ -436,12 +436,12 @@ def _parse_colors_list(self, driver: Chrome, tag_id: str) -> list[ColorSpec]:
436436
for e in colors_group.find_elements(By.XPATH, "./li"):
437437
spec = self._parse_spec(e)
438438
if len(spec.handle.split("/")) != 2:
439-
logging.info(f"skip for invalid handle - (asn) spec:{spec}")
439+
logging.debug(f"skip for invalid handle - (asn) spec:{spec}")
440440
continue
441441
if spec.github_stars < GITHUB_STARS:
442-
logging.info(f"skip for lower stars - (asn) spec:{spec}")
442+
logging.debug(f"skip for lower stars - (asn) spec:{spec}")
443443
continue
444-
logging.info(f"get (asn) repo:{spec}")
444+
logging.debug(f"get (asn) repo:{spec}")
445445
repos.append(spec)
446446
return repos
447447

@@ -469,11 +469,11 @@ def blacklist(sp: ColorSpec) -> bool:
469469
for spec in ColorSpec.all():
470470
logging.debug(f"process filtering on spec:{spec}")
471471
if spec.github_stars < GITHUB_STARS:
472-
logging.info(f"skip for lower stars - spec:{spec}")
472+
logging.debug(f"skip for lower stars - spec:{spec}")
473473
spec.remove()
474474
continue
475475
if blacklist(spec):
476-
logging.info(f"skip for blacklist - spec:{spec}")
476+
logging.debug(f"skip for blacklist - spec:{spec}")
477477
spec.remove()
478478
continue
479479
else:
@@ -505,13 +505,13 @@ def _download(self) -> None:
505505
spec.last_git_commit.timestamp() + LAST_GIT_COMMIT
506506
< datetime.datetime.now().timestamp()
507507
):
508-
logging.info(f"skip for too old git commit - spec:{spec}")
508+
logging.debug(f"skip for too old git commit - spec:{spec}")
509509
spec.remove()
510510
continue
511511
color_names = spec.get_vim_color_names()
512512
spec.update_color_names(color_names)
513513
if len(color_names) == 0:
514-
logging.info(f"skip for no color files (.vim,.lua) - spec:{spec}")
514+
logging.debug(f"skip for no color files (.vim,.lua) - spec:{spec}")
515515
spec.remove()
516516
continue
517517

@@ -535,12 +535,12 @@ def greater_than(a: ColorSpec, b: ColorSpec) -> bool:
535535
# detect duplicated color
536536
if color in specs_map:
537537
old_spec = specs_map[color]
538-
logging.info(
538+
logging.debug(
539539
f"detect duplicated color({color}), new:{spec}, old:{old_spec}"
540540
)
541541
# replace old repo if new repo has higher priority
542542
if greater_than(spec, old_spec):
543-
logging.info(f"replace old repo({old_spec}) with new({spec})")
543+
logging.debug(f"replace old repo({old_spec}) with new({spec})")
544544
specs_map[color] = spec
545545
specs_set.add(spec)
546546
specs_set.remove(old_spec)
@@ -558,11 +558,12 @@ def build(self) -> None:
558558

559559
for spec in ColorSpec.all():
560560
if not spec in deduped_specs:
561-
logging.info(f"remove for duplicate - repo:{spec}")
561+
logging.debug(f"remove for duplicate - repo:{spec}")
562562
spec.remove()
563563

564564
md = MdUtils(file_name="COLORSCHEMES", title="ColorSchemes List")
565565
for spec in ColorSpec.all():
566+
logging.info(f"collect spec:{spec}")
566567
color_names = spec.get_vim_color_names()
567568
color_names = sorted(color_names)
568569
md.new_line(

0 commit comments

Comments
 (0)