Skip to content

Commit

Permalink
Package Sync: Add status threadhold
Browse files Browse the repository at this point in the history
Add status threadhold to filter images by status (like only equal or above basic can be sync)
  • Loading branch information
wychlw committed Dec 22, 2024
1 parent e0747fb commit 6bf3355
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 39 deletions.
14 changes: 13 additions & 1 deletion .github/workflows/package-index-sync.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,22 @@ on:
# push: # Uncomment this line to enable push event, but it is not recommended as it may cause unnecessary PRs. Use workflow_dispatch instead.

jobs:
check_should_run:
name: Check Should Run
runs-on: ubuntu-latest
steps:
- name: Check Should Run
run: |
echo "Event Name: ${{ github.event_name }}"
echo "Ref: ${{ github.ref }}"
echo "Repository Owner: ${{ github.repository_owner }}"
echo "Inputs: makepr ${{ inputs.makepr }} debuginfo ${{ inputs.debuginfo }}"
echo "Should Run Auto: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/main' && github.repository_owner == 'ruyisdk' ) }}"
echo "Should Run Manual: ${{ ( github.event_name == 'workflow_dispatch' ) }}"
build:
name: Generate and Upload
runs-on: ubuntu-latest
if: ${{ ( github.event_name == 'push' && github.ref == github.ref == 'refs/heads/main' && github.repository_owner == 'ruyisdk' ) || ( github.event_name == 'workflow_dispatch' ) }}
if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/main' && github.repository_owner == 'ruyisdk' ) || ( github.event_name == 'workflow_dispatch' ) }}
environment: ruyi-sync
env:
GITHUB_TOKEN: ${{ secrets.GHO_TOKEN }}
Expand Down
8 changes: 4 additions & 4 deletions assets/generate_svgimage.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from src.svg_gen import SvgConf, SvgNode, SvgXml, gen_html, putconf, SvgRectContainer
from src.svg_gen import SvgText, SvgTextCenter, SvgMoveTo, SvgCR, SvgLF, SvgGroup
from src.svg_gen import SvgAdvancer, SvgSvg, SvgLine, SvgLink
from src.matrix_parser import Systems, status_map
from src.matrix_parser import Systems


def gen_svg_table(conf: SvgConf, systems: Systems, need_systems: dict[str],
Expand Down Expand Up @@ -61,8 +61,8 @@ def gen_svg_table(conf: SvgConf, systems: Systems, need_systems: dict[str],
continue
flag = True
if len(system.variant) == 1:
sys_t = SvgText(status_map(
system.variant[0].status), False)
sys_t = SvgText(
str(system.variant[0].status), False)
# Use python's dynamic feature to add link without modifying the class
sys_t.link = system.variant[0].link
board_group.append(sys_t)
Expand All @@ -71,7 +71,7 @@ def gen_svg_table(conf: SvgConf, systems: Systems, need_systems: dict[str],
for var in system.variant:
sys_var = var.sys_var if var.sys_var is not None else "main"
sys_t = SvgText(sys_var + ': ' +
status_map(var.status), False)
str(var.status), False)
# Same as above
sys_t.link = var.link
var_g.append(sys_t)
Expand Down
8 changes: 6 additions & 2 deletions assets/renew_ruyi_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import logging
import colorlog

from src.matrix_parser import Systems
from src.matrix_parser import Systems, ImageStatus
from src.ruyi_index_updator import RuyiDiff, RuyiGitRepo


Expand All @@ -35,6 +35,9 @@ def main():
arg.add_argument(
'--warn', help='output the warn to the file', default=None
)
arg.add_argument(
'--threadhold', help='the status threadhold can be synced', default='basic'
)
arg.add_argument(
'plugin_names', help='the plugins to run, default to all', nargs='*'
)
Expand Down Expand Up @@ -74,7 +77,8 @@ def main():
diffs = RuyiDiff(matrix, args.config)
repo = RuyiGitRepo(index_path)

for diff in diffs.gen_diff(args.plugin_names):
threadhold = ImageStatus(args.threadhold)
for diff in diffs.gen_diff(args.plugin_names, threadhold):
pr = repo.upload_image(diff)
if pr is None:
continue
Expand Down
60 changes: 30 additions & 30 deletions assets/src/matrix_parser/matrix_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,42 @@
"""
import os
from typing import Any
from functools import total_ordering
import yaml
import frontmatter

LANG = [
'zh'
]

@total_ordering
class ImageStatus:

def status_map(status: str):
"""
map status to pretty string
"""
if status == 'wip':
return 'WIP'
if status == 'cft':
return 'CFT'
if status == 'cfh':
return 'CFH'
if status == 'basic':
return 'Basic'
if status == 'good':
return 'Good'
return status
MAPPER = {
'wip': ('WIP', 1),
'cfh': ('CFH', 2),
'cft': ('CFT', 3),
'basic': ('Basic', 4),
'good': ('Good', 5),
}

def __init__(self, status: str):
self.status = status.lower()

def __str__(self):
return self.MAPPER[self.status][0]

def __len__(self):
return len(self.MAPPER[self.status][0])

def __repr__(self):
return self.MAPPER[self.status][0]

def __eq__(self, other):
return self.MAPPER[self.status][1] == self.MAPPER[other.status][1]

def __lt__(self, other):
return self.MAPPER[self.status][1] < self.MAPPER[other.status][1]

class SystemVar:
"""
Expand All @@ -44,24 +56,12 @@ class SystemVar:
sys: str
sys_ver: str | None
sys_var: str | None
status: str
status: ImageStatus
last_update: str
link: list[str] | None

raw_data: Any # Store the raw data of the readed metadata

def strip(self):
"""
dummy for strip the system
"""
return self

def __str__(self):
return status_map(self.status)

def __len__(self):
return len(status_map(self.status))

def __init_by_file(self, meta_path, link: list[str]):
self.link = link
if not os.path.exists(meta_path):
Expand All @@ -81,15 +81,15 @@ def __init_by_file(self, meta_path, link: list[str]):
self.sys = post['sys']
self.sys_ver = post['sys_ver']
self.sys_var = post['sys_var']
self.status = post['status']
self.status = ImageStatus(post['status'])
self.last_update = post['last_update']

def __init__(self, *args, **kwargs):
if len(kwargs) > 0:
self.sys = kwargs['sys']
self.sys_ver = kwargs['sys_ver']
self.sys_var = kwargs['sys_var']
self.status = kwargs['status']
self.status = ImageStatus(kwargs['status'])
self.last_update = kwargs['last_update']
self.link = kwargs['link']
else:
Expand Down
7 changes: 5 additions & 2 deletions assets/src/ruyi_index_updator/version_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

from ..ruyi_index_parser import PackageIndexProc, clone_package_index, BoardImages
from ..version_checker import gen_oldver
from ..matrix_parser import Systems
from ..matrix_parser import Systems, ImageStatus
from ..version_checker import VInfo
from .plugin_handler import find_plugin
from .upload_plugin_base import UploadPluginBase
Expand Down Expand Up @@ -125,7 +125,7 @@ def __yield_one_sys(self, vinfo: VInfo,
index_name, newest_index.version, matrix_version)
yield BoardImageWrapper(vinfo, plug, index_name, index)

def gen_diff(self, filter_plugins: list[str] = None):
def gen_diff(self, filter_plugins: list[str] = None, threadhold = ImageStatus("basic")):
"""
Yield the system that needs to be updated
"""
Expand All @@ -138,6 +138,9 @@ def gen_diff(self, filter_plugins: list[str] = None):
plugin.get_name() not in filter_plugins:
continue

if v.raw_data.status < threadhold:
continue

# Please notice:
# One system may have multiple ruyi_index, we need to handle them all
# So, we need to iterate the index
Expand Down

0 comments on commit 6bf3355

Please sign in to comment.