Skip to content

Commit

Permalink
修复错误,优化代码
Browse files Browse the repository at this point in the history
  • Loading branch information
chenmozhijin committed Sep 23, 2024
1 parent c061793 commit 875483d
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 34 deletions.
21 changes: 3 additions & 18 deletions .github/workflows/build-openwrt-py.yml
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ jobs:
if: success() || failure()
uses: ./../../../../../opt/OpenWrt-K/.github/action/upload

build-images:
build-images-releases:
runs-on: ubuntu-22.04
needs: [prepare,base-builds,build-ImageBuilder,build-packages]
name: build-Image-${{ matrix.name }}
Expand All @@ -183,23 +183,8 @@ jobs:
- name: 构建
id: build
working-directory: /opt/OpenWrt-K
run: python3 -m build_helper --task build_images --config ${{ matrix.config }}
run: python3 -m build_helper --task build_images_releases --config ${{ matrix.config }}

- name: 上传
if: success() || failure()
uses: ./../../../../../opt/OpenWrt-K/.github/action/upload

releases:
runs-on: ubuntu-22.04
needs: [prepare, build-images]
name: releases-${{ matrix.name }}
strategy:
matrix: ${{ fromJSON(needs.prepare.outputs.matrix) }}
steps:
- uses: actions/checkout@v4
- name: 建立环境
uses: ./.github/action/prepare

- name: 发布
working-directory: /opt/OpenWrt-K
run: python3 -m build_helper --task releases --config ${{ matrix.config }}
uses: ./../../../../../opt/OpenWrt-K/.github/action/upload
3 changes: 1 addition & 2 deletions build_helper/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,9 @@ def main() -> None:
case "build_image_builder":
from .build import build_image_builder
build_image_builder(config)
case "build_images":
case "build_images_releases":
from .build import build_images
build_images(config)
case "releases":
from .releases import releases
releases(config)

Expand Down
11 changes: 6 additions & 5 deletions build_helper/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def prepare(cfg: dict) -> None:
with tarfile.open(os.path.join(tmpdir.name, "builds.tar.gz"), "r:gz") as tar:
tar.extractall(openwrt.path) # noqa: S202

elif context.job == "build-images":
elif context.job == "build-images-releases":
ib_path = dl_artifact(f"Image_Builder-{cfg["name"]}", tmpdir.name)
with zipfile.ZipFile(ib_path, "r") as zip_ref:
zip_ref.extract("openwrt-imagebuilder.tar.xz", tmpdir.name)
Expand All @@ -95,9 +95,10 @@ def prepare(cfg: dict) -> None:
msg = f"未知的工作流 {context.job}"
raise ValueError(msg)

cache_restore_key = get_cache_restore_key(openwrt, cfg)
core.set_output("cache-key", f"{cache_restore_key}-{context.run_id}")
core.set_output("cache-restore-key", cache_restore_key)
if context.job in ("base-builds", "build-packages", "build-ImageBuilder"):
cache_restore_key = get_cache_restore_key(openwrt, cfg)
core.set_output("cache-key", f"{cache_restore_key}-{context.run_id}")
core.set_output("cache-restore-key", cache_restore_key)
core.set_output("use-cache", cfg["compile"]["use_cache"])
core.set_output("openwrt-path", openwrt.path)

Expand Down Expand Up @@ -177,7 +178,7 @@ def build_image_builder(cfg: dict) -> None:
with open(os.path.join(openwrt.path, ".config"), "w") as f:
for line in config.splitlines():
if ((match := re.match(r"CONFIG_(?P<name>[^_=]+)_IMAGES=y", line)) or
(match := re.match(r"CONFIG_TARGET_ROOTFS_(?P<name>[^_=]+)=y", line)) or
(match := re.match(r"CONFIG_TARGET_ROOTFS_(?P<name>[^_=]+)=y", line)) or
(match := re.match(r"CONFIG_TARGET_IMAGES_(?P<name>[^_=]+)=y", line))):
name = match.group("name")
if name in ("ISO", "VDI", "VMDK", "VHDX", "TARGZ", "CPIOGZ", "EXT4FS", "SQUASHFS", "GZIP"):
Expand Down
16 changes: 8 additions & 8 deletions build_helper/releases.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
import json
import os
import shutil
import tempfile
import zipfile
from datetime import datetime, timedelta, timezone

from .utils.logger import logger
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

Expand All @@ -26,14 +25,15 @@ def releases(cfg: dict) -> None:
shutil.move(kmods_archive_path, os.path.join(paths.uploads, "kmods.zip"))
kmods_archive_path = os.path.join(paths.uploads, "kmods.zip")

firmware_path = os.path.join(paths.uploads, "firmware")
os.makedirs(firmware_path)
firmware_archive_path = dl_artifact(f"firmware-{cfg['name']}", tmpdir.name)
with zipfile.ZipFile(firmware_archive_path, "r") as zip_ref:
zip_ref.extractall(firmware_path)

tmpdir.cleanup()

ib = ImageBuilder(os.path.join(paths.workdir, "ImageBuilder"))
target, subtarget = ib.get_target()
if target is None or subtarget is None:
msg = "无法获取target信息"
raise RuntimeError(msg)
firmware_path = str(shutil.copytree(os.path.join(ib.path, "bin", "targets", target, subtarget), os.path.join(paths.uploads, "firmware")))

current_manifest = None
profiles = None
for root, _, files in os.walk(firmware_path):
Expand Down
2 changes: 1 addition & 1 deletion build_helper/utils/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ class ConfigNotFoundError(ConfigError):
pass

class PrePareError(Exception):
pass
pass

0 comments on commit 875483d

Please sign in to comment.