Skip to content

Commit 8a05218

Browse files
committed
Merge remote-tracking branch 'origin/plugin_api_v2' into add_virus_toal_scan
2 parents 1aab2b8 + 175d074 commit 8a05218

File tree

7 files changed

+2847
-2784
lines changed

7 files changed

+2847
-2784
lines changed

.github/workflows/links.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@ jobs:
1414
steps:
1515
- uses: actions/checkout@v4
1616

17+
- name: Create plugins.json For All Plugins
18+
if: ${{ github.event_name == 'schedule' }}
19+
run: |
20+
python ./ci/src/merge-manifest.py
21+
22+
- name: Create plugins.json For New Plugins Only
23+
if: ${{ github.event_name == 'pull_request' }}
24+
run: |
25+
python ./ci/src/merge-manifest.py new-only
26+
1727
- name: Link Checker
1828
id: lychee
1929
uses: lycheeverse/lychee-action@v2

ci/src/_utils.py

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
# -*-coding: utf-8 -*-
22
import json
3+
import os
4+
import re
35
from pathlib import Path
46
from typing import Dict, List, TypeVar
5-
import re
6-
import os
7+
8+
# If adding a third-party library here, check CI workflows Python files
9+
# that are dependant on this and require pip install.
710

811
# path
912
utils_path = Path(__file__).resolve()
@@ -17,7 +20,18 @@
1720
# constants
1821
id_name = "ID"
1922
language_name = "Language"
20-
language_list = ("csharp", "executable", "fsharp", "python", "javascript", "typescript", "python_v2", "executable_v2", "javascript_v2", "typescript_v2")
23+
language_list = (
24+
"csharp",
25+
"executable",
26+
"fsharp",
27+
"python",
28+
"javascript",
29+
"typescript",
30+
"python_v2",
31+
"executable_v2",
32+
"javascript_v2",
33+
"typescript_v2",
34+
)
2135
etag = "ETag"
2236
version = "Version"
2337
url_sourcecode = "UrlSourceCode"
@@ -51,12 +65,20 @@ def plugin_reader() -> P:
5165

5266
return manifests
5367

68+
69+
def save_plugins_json_file(content: list[dict[str]]) -> None:
70+
with open("plugins.json", "w", encoding="utf-8") as f:
71+
json.dump(content, f, indent=4, ensure_ascii=False)
72+
73+
5474
def get_plugin_file_paths() -> list[str]:
5575
return [os.path.join(plugin_dir, filename) for filename in get_plugin_filenames()]
5676

77+
5778
def get_plugin_filenames() -> list[str]:
5879
return os.listdir(plugin_dir)
5980

81+
6082
def etag_reader() -> ETagsType:
6183
with open(etag_file, "r", encoding="utf-8") as f:
6284
return json.load(f)
@@ -66,7 +88,8 @@ def plugin_writer(content: P):
6688
for plugin in content:
6789
with open(plugin_dir / f"{plugin[plugin_name]}-{plugin[id_name]}.json", "w", encoding="utf-8") as f:
6890
json.dump(plugin, f, indent=4)
69-
91+
92+
7093
def etags_writer(content: ETagsType):
7194
with open(etag_file, "w", encoding="utf-8") as f:
7295
json.dump(content, f, indent=4)
@@ -75,10 +98,12 @@ def etags_writer(content: ETagsType):
7598
def clean(string: str, flag="-") -> str:
7699
return string.lower().replace(flag, "").strip()
77100

101+
78102
def version_tuple(version: str) -> tuple:
79103
version = clean(version, "v")
80104
return tuple(version.split("."))
81105

106+
82107
def check_url(url: str) -> bool:
83108
regex = re.compile(
84109
r"^(?:http|ftp)s?://" # http:// or https://
@@ -100,3 +125,19 @@ def get_file_plugins_json_info(required_key: str = "") -> list[dict[str, str]]:
100125
return data
101126

102127
return [{required_key: plugin[required_key]} for plugin in data]
128+
129+
130+
def get_new_plugin_submission_ids() -> list[str]:
131+
plugins_json_ids = [item["ID"] for item in get_file_plugins_json_info("ID")]
132+
existing_plugin_file_ids = [info["ID"] for info in plugin_reader()]
133+
134+
new_ids = []
135+
136+
for id in existing_plugin_file_ids:
137+
# plugins.json would not contain new submission's ID.
138+
if id in plugins_json_ids:
139+
continue
140+
141+
new_ids.append(id)
142+
143+
return new_ids

ci/src/merge-manifest.py

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,30 @@
1-
import glob
2-
import json
1+
import sys
32

4-
if __name__ == "__main__":
5-
plugins = sorted(glob.glob("plugins/*.json"))
3+
from _utils import get_new_plugin_submission_ids, plugin_reader, save_plugins_json_file
4+
5+
6+
def get_all_plugins() -> list[dict[str]]:
7+
return plugin_reader()
8+
9+
10+
def get_new_plugins() -> list[dict[str]]:
11+
ids = get_new_plugin_submission_ids()
12+
plugins_from_plugins_dir = plugin_reader()
613

7-
manifests = []
14+
new_plugins = []
815

9-
for plugin in plugins:
10-
with open(plugin, "r", encoding="utf-8") as f:
11-
manifest = json.load(f)
12-
manifests.append(manifest)
16+
for id in ids:
17+
for plugin in plugins_from_plugins_dir:
18+
if plugin["ID"] == id:
19+
new_plugins.append(plugin)
20+
break
21+
22+
return new_plugins
23+
24+
25+
if __name__ == "__main__":
1326

14-
with open("plugins.json", "w", encoding="utf-8") as f:
15-
json.dump(manifests, f, indent=4, ensure_ascii=False)
27+
if len(sys.argv) > 1 and str(sys.argv[1]) == "new-only":
28+
save_plugins_json_file(get_new_plugins())
29+
else:
30+
save_plugins_json_file(get_all_plugins())

ci/src/validator.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# -*-coding: utf-8 -*-
22
import uuid
33

4-
from _utils import (check_url, clean, get_file_plugins_json_info, get_plugin_file_paths, get_plugin_filenames,
4+
from _utils import (check_url, clean, get_new_plugin_submission_ids, get_plugin_file_paths, get_plugin_filenames,
55
icon_path, id_name, language_list, language_name, plugin_reader)
66

77
plugin_infos = plugin_reader()
@@ -22,32 +22,29 @@ def test_language_in_list():
2222
msg = f"The '{language_name}' is not in the list of {language_list}"
2323
assert set(language_list) >= set(languages), msg
2424

25+
2526
def test_valid_icon_url():
2627
for plugin in plugin_infos:
2728
msg = f"The URL in {icon_path} is not a valid URL."
2829
assert check_url(plugin[icon_path]), msg
2930

31+
3032
def test_file_type_json():
3133
incorrect_ext_files = [file_path for file_path in get_plugin_file_paths() if not file_path.endswith(".json")]
3234

3335
assert len(incorrect_ext_files) == 0, f"Expected the following file to be of .json extension: {incorrect_ext_files}"
3436

37+
3538
def test_file_name_construct():
3639
filenames = get_plugin_filenames()
3740
for info in plugin_infos:
3841
assert (
3942
f"{info['Name']}-{info['ID']}.json" in filenames
4043
), f"Plugin {info['Name']} with ID {info['ID']} does not have the correct filename. Make sure it's name + ID, i.e. {info['Name']}-{info['ID']}.json"
4144

42-
def test_submitted_plugin_id_is_valid_uuid():
43-
plugins_json_ids = [item["ID"] for item in get_file_plugins_json_info("ID")]
44-
existing_plugin_file_ids = [info["ID"] for info in plugin_infos]
45-
46-
for id in existing_plugin_file_ids:
47-
# plugins.json would not contain new submission's ID.
48-
if id in plugins_json_ids:
49-
continue
5045

46+
def test_submitted_plugin_id_is_valid_uuid():
47+
for id in get_new_plugin_submission_ids():
5148
try:
5249
uuid.UUID(id, version=4)
5350
outcome = True

0 commit comments

Comments
 (0)