Skip to content

Commit

Permalink
优化发布日志
Browse files Browse the repository at this point in the history
  • Loading branch information
chenmozhijin committed Sep 28, 2024
1 parent 500f404 commit 4055d26
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
10 changes: 7 additions & 3 deletions build_helper/releases.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
from .utils.network import request_get
from .utils.openwrt import ImageBuilder
from .utils.paths import paths
from .utils.repo import dl_artifact, match_releases, new_release

from .utils.repo import dl_artifact, match_releases, new_release, user_repo, get_current_commit, repo
from actions_toolkit.github import Context

def releases(cfg: dict) -> None:
"""发布到 GitHub"""
Expand Down Expand Up @@ -59,6 +59,8 @@ def releases(cfg: dict) -> None:

current_packages = {line.split(" - ")[0]: line.split(" - ")[1] for line in current_manifest.splitlines()} if current_manifest else None

context = Context()

try:
changelog = ""
if release := match_releases(cfg):
Expand All @@ -83,7 +85,9 @@ def releases(cfg: dict) -> None:
changelog = "更新日志:\n" + changelog if changelog else "无任何软件包更新"

body = f"编译完成于: {datetime.now(timezone(timedelta(hours=8))).strftime('%Y-%m-%d %H:%M:%S')}\n"
body += f"使用的配置: {cfg['name']}\n"
body += f"使用的配置: [{cfg['name']}](https://github.com/{user_repo}/tree/{get_current_commit()}/config/{cfg['name']})\n"
workflow_run = repo.get_workflow_run(context.run_id)
body += f"编译此固件的工作流运行: [{workflow_run.display_title}]({workflow_run.html_url}) ({workflow_run.event})\n"
if profiles:
if (version_number := profiles.get("version_number")) and (version_code := profiles.get('version_code')):
body += f"OpenWrt版本: {version_number} {version_code}\n"
Expand Down
12 changes: 8 additions & 4 deletions build_helper/utils/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@
if user_info := gh_api_request(f"https://api.github.com/users/{compiler}", token):
compiler = user_info.get("name", compiler)

def get_current_commit() -> str:
current_repo = pygit2.Repository(paths.openwrt_k)
head_commit = current_repo.head.target
if isinstance(head_commit, pygit2.Oid):
head_commit = head_commit.raw.hex()
return head_commit

def dl_artifact(name: str, path: str) -> str:
for artifact in repo.get_artifacts():
if artifact.workflow_run.id == context.run_id and artifact.name == name:
Expand Down Expand Up @@ -83,10 +90,7 @@ def new_release(cfg: dict, assets: list[str], body: str) -> None:
break
i += 1

current_repo = pygit2.Repository(paths.openwrt_k)
head_commit = current_repo.head.target
if isinstance(head_commit, pygit2.Oid):
head_commit = head_commit.raw.hex()
head_commit = get_current_commit()

logger.info("创建新发布: %s", release_name)
release = repo.create_git_tag_and_release(tag_name,
Expand Down

0 comments on commit 4055d26

Please sign in to comment.